-
Notifications
You must be signed in to change notification settings - Fork 121
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
fix(rendering): area, line and point rendered on the same layer for each series #290
Changes from 1 commit
17458ea
f612276
5d712a5
c4fffd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,27 +38,10 @@ export class LineGeometries extends React.PureComponent<LineGeometriesDataProps, | |
return ( | ||
<Group ref={this.barSeriesRef} key={'bar_series'}> | ||
{this.renderLineGeoms()} | ||
{this.renderLinePoints()} | ||
</Group> | ||
); | ||
} | ||
|
||
private renderLinePoints = (): JSX.Element[] => { | ||
const { lines } = this.props; | ||
return lines.reduce( | ||
(acc, glyph, i) => { | ||
const { points, seriesPointStyle, color } = glyph; | ||
|
||
if (!seriesPointStyle.visible) { | ||
return acc; | ||
} | ||
const pointStyleProps = buildPointStyleProps(color, seriesPointStyle); | ||
return [...acc, ...this.renderPoints(points, i, pointStyleProps)]; | ||
}, | ||
[] as JSX.Element[], | ||
); | ||
}; | ||
|
||
private renderPoints = ( | ||
linePoints: PointGeometry[], | ||
lineIndex: number, | ||
|
@@ -90,35 +73,47 @@ export class LineGeometries extends React.PureComponent<LineGeometriesDataProps, | |
private renderLineGeoms = (): JSX.Element[] => { | ||
const { lines, sharedStyle } = this.props; | ||
|
||
const lineElements: JSX.Element[] = []; | ||
|
||
lines.forEach((glyph, index) => { | ||
const { line, color, transform, geometryId, seriesLineStyle } = glyph; | ||
return lines.reduce<JSX.Element[]>((acc, glyph, index) => { | ||
const { seriesLineStyle, seriesPointStyle } = glyph; | ||
|
||
if (!seriesLineStyle.visible) { | ||
return; | ||
if (seriesLineStyle.visible) { | ||
acc.push(this.getLineToRender(glyph, sharedStyle, index)); | ||
} | ||
const key = `line-${index}`; | ||
const customOpacity = seriesLineStyle ? seriesLineStyle.opacity : undefined; | ||
const geometryStyle = getGeometryStyle(geometryId, this.props.highlightedLegendItem, sharedStyle, customOpacity); | ||
|
||
if (this.props.animated) { | ||
lineElements.push( | ||
<Group key={index} x={transform.x}> | ||
<Spring native reset from={{ opacity: 0 }} to={{ opacity: 1 }}> | ||
{() => { | ||
const lineProps = buildLineRenderProps(0, line, color, seriesLineStyle, geometryStyle); | ||
return <animated.Path {...lineProps} key={key} />; | ||
}} | ||
</Spring> | ||
</Group>, | ||
); | ||
} else { | ||
const lineProps = buildLineRenderProps(transform.x, line, color, seriesLineStyle, geometryStyle); | ||
lineElements.push(<Path {...lineProps} key={key} />); | ||
if (seriesPointStyle.visible) { | ||
acc.push(...this.getPointToRender(glyph, index)); | ||
} | ||
}); | ||
|
||
return lineElements; | ||
return acc; | ||
}, []); | ||
}; | ||
|
||
getLineToRender(glyph: LineGeometry, sharedStyle: SharedGeometryStyle, index: number) { | ||
const { line, color, transform, geometryId, seriesLineStyle } = glyph; | ||
const key = `line-${index}`; | ||
const customOpacity = seriesLineStyle ? seriesLineStyle.opacity : undefined; | ||
const geometryStyle = getGeometryStyle(geometryId, this.props.highlightedLegendItem, sharedStyle, customOpacity); | ||
|
||
if (this.props.animated) { | ||
return ( | ||
<Group key={index} x={transform.x}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here? re: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed on 5d712a5 |
||
<Spring native reset from={{ opacity: 0 }} to={{ opacity: 1 }}> | ||
{() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we extract this function so it doesn't create a new function on each rerender? I don't think it will be that different on performance but best to keep up with best practices. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed the animation in 5d712a5 |
||
const lineProps = buildLineRenderProps(0, line, color, seriesLineStyle, geometryStyle); | ||
return <animated.Path {...lineProps} key={key} />; | ||
}} | ||
</Spring> | ||
</Group> | ||
); | ||
} else { | ||
const lineProps = buildLineRenderProps(transform.x, line, color, seriesLineStyle, geometryStyle); | ||
return <Path {...lineProps} key={key} />; | ||
} | ||
} | ||
|
||
getPointToRender(glyph: LineGeometry, index: number) { | ||
const { points, color, seriesPointStyle } = glyph; | ||
|
||
const pointStyleProps = buildPointStyleProps(color, seriesPointStyle); | ||
return this.renderPoints(points, index, pointStyleProps); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use something other than the index for the key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed on 5d712a5