mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 10:55:42 +03:00
Sort and index multi-series data correctly in line chart
- Sorting must be done on copies to preserve orders. - Indices should be reversed since rendering is also reversed (the back layer (the tallest) is rendered first to create the stacking effect).
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<div data-test-chart-tooltip class="chart-tooltip {{if @active "active" "inactive"}}" style={{@style}} ...attributes>
|
||||
<ol>
|
||||
{{#each @data as |props|}}
|
||||
{{yield props.series props.datum (inc props.index)}}
|
||||
{{yield props.series props.datum (inc props.index)}}
|
||||
{{/each}}
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
@@ -297,14 +297,14 @@ export default class LineChart extends Component {
|
||||
formattedY: this.yFormat()(datum[yProp]),
|
||||
datum,
|
||||
},
|
||||
index: seriesIndex,
|
||||
index: data.length - seriesIndex - 1,
|
||||
};
|
||||
});
|
||||
|
||||
// Of the selected data, determine which is closest
|
||||
const closestDatum = activeData.sort(
|
||||
(a, b) => Math.abs(a.datum.datum[xProp] - x) - Math.abs(b.datum.datum[xProp] - x)
|
||||
)[0];
|
||||
const closestDatum = activeData
|
||||
.slice()
|
||||
.sort((a, b) => Math.abs(a.datum.datum[xProp] - x) - Math.abs(b.datum.datum[xProp] - x))[0];
|
||||
|
||||
// If any other selected data are beyond a distance threshold, drop them from the list
|
||||
// xScale is used here to measure distance in screen-space rather than data-space.
|
||||
|
||||
Reference in New Issue
Block a user