Skip to content

Commit

Permalink
feat(line): part of a line with missing data was hidden (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahtohbi4 authored and Raphaël Benitte committed Nov 1, 2017
1 parent 0dfafff commit 60e4774
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/components/charts/line/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ const enhance = compose(
withMotion(),
withPropsOnChange(['curve'], ({ curve }) => ({
lineGenerator: line()
.defined(d => d.value !== null)
.x(d => d.x)
.y(d => d.y)
.curve(curveFromProp(curve)),
Expand Down
2 changes: 1 addition & 1 deletion src/components/charts/line/LineDots.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const LineDots = ({

return [
...acc,
...points.map(point => {
...points.filter(point => point.value !== null).map(point => {
const pointData = {
serie: { id },
x: point.key,
Expand Down
2 changes: 1 addition & 1 deletion src/components/charts/line/LineSlices.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ LineSlices.propTypes = {
points: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
color: PropTypes.string.isRequired,
})
).isRequired,
Expand Down
17 changes: 10 additions & 7 deletions src/components/charts/line/LineSlicesItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,21 @@ const enhance = compose(
withPropsOnChange(['slice', 'theme', 'tooltipFormat'], ({ slice, theme, tooltipFormat }) => {
const format =
!tooltipFormat || isFunction(tooltipFormat) ? tooltipFormat : d3Format(tooltipFormat)
const hasValues = slice.points.some(p => p.value !== null)

return {
tooltip: (
tooltip: hasValues ? (
<TableTooltip
theme={theme}
rows={slice.points.map(p => [
<Chip color={p.color} />,
p.id,
format ? format(p.value) : p.value,
])}
rows={slice.points
.filter(p => p.value !== null)
.map(p => [
<Chip color={p.color} />,
p.id,
format ? format(p.value) : p.value,
])}
/>
),
) : null,
}
}),
withHandlers({
Expand Down
2 changes: 1 addition & 1 deletion src/components/charts/line/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const LinePropTypes = {
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
20 changes: 20 additions & 0 deletions stories/charts/line.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ stories.add('with markers', () => (
/>
))

stories.add('with missing data', () => (
<Line
{...commonProperties}
curve="monotoneX"
data={[
{
id: 'fake corp. A',
data: [4, 8, 5, null, 2, 1, 4, null, 8, 9, 5].map((y, i) => ({ x: `#${i}`, y })),
},
{
id: 'fake corp. B',
data: [5, 9, 8, 6, 3, 1, 2, null, 5, 8, 4].map((y, i) => ({ x: `#${i}`, y })),
},
]}
dotSize={8}
dotBorderColor="#fff"
dotBorderWidth={2}
/>
))

stories.add('with custom min/max Y', () => (
<Line
{...commonProperties}
Expand Down

0 comments on commit 60e4774

Please sign in to comment.