Comments (6)
It's really a problem.The state of LineChart is changing when mouse is moving in the chart, because we keep the location of mouse in state.
from recharts.
The most condition is the reference of array or object. I use lodash isEqual function to re-write pureRender. It works faster.
Line yes: 1023 no: 0
Layer yes: 1955 no: 2197
Curve yes: 1245 no: 253
LineChart yes: 556 no: 81
Surface yes: 556 no: 0
CartesianGrid yes: 0 no: 354
CartesianAxis yes: 1215 no: 0
Legend yes: 0 no: 47
Tooltip yes: 481 no: 7
DefaultTooltip yes: 481 no: 0
Dot yes: 493 no: 497
from recharts.
Thanks, @arcthur.
Yeah, it work faster now.
Actually isEqual
from lodash
is yet another way to perform deep comparison. In terms of performance, this approach is pretty expensive.
The problem is not only for tooltip, but in managing state in common sense.
Every time LineChart is rerendering, it creates a bunch of new objects for children
:
const items = findAllByType(children, Line);
let xAxisMap = this.getAxisMap('xAxis', items);
let yAxisMap = this.getAxisMap('yAxis', items);
const offset = this.getOffset(xAxisMap, yAxisMap);
xAxisMap = this.getFormatAxisMap(xAxisMap, offset, 'xAxis');
yAxisMap = this.getFormatAxisMap(yAxisMap, offset, 'yAxis');
I think it would be better to store such auxiliary objects (like axisMaps and offset) to state, and perform shallow comparison for own LineChart props (nextProps) and children props (nextProps.children[].props) in componentWillReceiveProps. If that comparison will be false, we could recalculate these objects, otherwise just reuse previous state.
This approach will allow us to use shallowEqual check for other pure components.
Deep comparison seems like a brute force to achieve some performance boost, but it hides problem rather than solves it.
What do you think?
from recharts.
Thanks @Cloudo to support the project, and welcome to provide the better codes to improve the recharts. 😄
Actually, isEqual
isn't a better method that I may not spend much time to think about the problem. but the original pureRender
is too simple that didn't satisfied most conditions, such as complex object. I will custom the better pureRender
function to divisive the difference for next few days.
from recharts.
Thanks @Cloudo for your enthusiasm.
I plan to refactor the chart components in the next period of time.
I think the components can be optimized in the following two points:
- Store some auxiliary objects (axisMaps, offset and so on)
- Don't store the position of cursor in state
The job involves so much components, may take longer.
P.S. I'm sorry I didn't reply to you at the first time. We are on vacation for Chinese New Year, and we will start work next week.
from recharts.
We optimized the pureRender function above official pureRender, that may be solved more problems. Always thanks!
from recharts.
Related Issues (20)
- Tooltip deprecation HOT 1
- Negative interval number HOT 5
- Getting lowest and highest possible x and y in a line chart? HOT 22
- Tooltip first render HOT 7
- YAxis is missing if value = null || undefined HOT 2
- different name on tooltip from xaxis on barchart HOT 4
- Better API documentation HOT 3
- Issues with typing Legend props HOT 7
- Stacking Xaxis dataKey text HOT 3
- AreaChart and LineChart do not show the values correctly HOT 1
- Question on exporting `useChartWidth` and similar api HOT 2
- BarChart : Without BarSize bug, with BarSize another Bug HOT 2
- Adjust the colour of the dot at the cursor of the tooltip (AreaChart) HOT 3
- Lines directly on the lower or upper bound of a Y-axis with custom domain and allowDataOverflow gets partially clipped out of view HOT 4
- Active bar and tooltip persist despite mouse cursor leaving chart area HOT 4
- Is there any way to position=insideMiddle? HOT 5
- Brush component is missing property `data` HOT 3
- Stacked chart round some bars HOT 2
- Points property not generating for Area Chart in v2.12.6 HOT 5
- recharts responsive pie chart with legend HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from recharts.