Skip to content

Commit

Permalink
feat(bump): skip serie labels for missing data
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Dec 13, 2019
1 parent 7275fa8 commit 04a13a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/bump/src/bump/LinesLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ LinesLabels.propTypes = {
data: PropTypes.arrayOf(
PropTypes.shape({
x: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
y: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
y: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
})
).isRequired,
})
Expand Down
14 changes: 11 additions & 3 deletions packages/bump/src/bump/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,29 @@ export const useSeriesLabels = ({ series, position, padding, color }) => {
signedPadding = padding
}

return series.map(serie => {
const labels = []
series.forEach(serie => {
const point =
position === 'start'
? serie.linePoints[0]
: serie.linePoints[serie.linePoints.length - 1]

return {
// exclude labels for series having missing data at the beginning/end
if (point[0] === null || point[1] === null) {
return
}

labels.push({
id: serie.id,
x: point[0] + signedPadding,
y: point[1],
color: getColor(serie),
opacity: serie.style.opacity,
serie,
textAnchor,
}
})
})

return labels
}, [series, position, padding, getColor])
}

0 comments on commit 04a13a7

Please sign in to comment.