Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixed components #724

Merged
merged 3 commits into from Aug 21, 2017
Merged

Mixed components #724

merged 3 commits into from Aug 21, 2017

Conversation

txgruppi
Copy link
Contributor

@txgruppi txgruppi commented Jun 6, 2017

Updates on how data is selected and axis points are calculated.

Changed the order in which getDisplayedData looks for the data.

The data used to calculated the Axis points are returned in this order:

  1. Data from the graphical items;
  2. Data from the item properties;
  3. data from the chart props.

This allows us to use a general data set for a complement like Line while using a specific data set for another component like Scatter.

The example below has the chart's data property defined as the general data used for the Line components while the Scatter has its own data property.

Without this code changes the Scatter would never render since it would use the data from the chart.

The linesData and scatterData are completely different and they don't use the same points on any axis. They are just displayed together.

// linesData = [ { label: string, a: number, b: number }, ... ];
// scatterData = [ { x: number, y: number }, ... ];

<ComposedChart width={600} height={400} data={linesData}>
  <CartesianGrid />

  <XAxis xAxisId="a1" dataKey="x" type="number" />
  <YAxis yAxisId="a2" dataKey="y" type="number" />

  <XAxis xAxisId="a3" dataKey="label" type="category" orientation="top" />
  <YAxis yAxisId="a4" type="number" orientation="right" />

  <Scatter xAxisId="a1" yAxisId="a2" data={scatterData} fill="#ff0000" line />

  <Line xAxisId="a3" yAxisId="a4" dataKey="a" type="monotone" stroke="#00ff00" />
  <Line xAxisId="a3" yAxisId="a4" dataKey="b" type="monotone" stroke="#ff00ff" />
</ComposedChart>

Changed how an axis points are calculated.

Updated the getAxisMapByAxes send to getDisplayedData graphicalItems which are connected with the given axis.

This prevents the axis from considering data it is not supposed to display.

The example code is the same used in the previous item.

Without this change:

screen shot 2017-06-06 at 16 13 14

With this change:

screen shot 2017-06-06 at 16 13 25

Changed the way `getDisplayedData` finds the data to be used. It will
try to return the item's data before using the chart's data.

I did this change because I believe the chart's data is less important
the a item's data, when it is present, and this allows me to use a
composed chart with the Line component getting its data from the chart
and the Scatter component getting its data from its own properties.
Updated `getAxisMapByAxes` to only use the data sets connected to the
given axis, avoiding some _empty_ points from being added to the chart's
axis.

In my case I had some Line and Scatter components together but they have
different data sets and with different intervals. With this update I can
have the Line's axis displaying only the numbers and categories related
to it and the same happens to the Scatter's axis.
@morinted
Copy link

This is behavior that I thought the library would have by default.

I tried this PR and can confirm it solves my use case. I've reviewed the code it looks fine to me.

@xile611 xile611 merged commit 4d81802 into recharts:master Aug 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants