Skip to content

Commit

Permalink
(feat)Line: add support for hiding line charts by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ccatalan6 committed Mar 13, 2024
1 parent 154056b commit b9ae884
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/line/src/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const Line = props => {
enableTouchCrosshair = false,

role = 'img',
initialHiddenIds = [],
} = props

const { margin, innerWidth, innerHeight, outerWidth, outerHeight } = useDimensions(
Expand Down Expand Up @@ -148,6 +149,7 @@ const Line = props => {
pointColor,
pointBorderColor,
enableSlices,
initialHiddenIds,
})

const theme = useTheme()
Expand Down
3 changes: 2 additions & 1 deletion packages/line/src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export const useLine = ({
pointColor = LineDefaultProps.pointColor,
pointBorderColor = LineDefaultProps.pointBorderColor,
enableSlices = LineDefaultProps.enableSlicesTooltip,
initialHiddenIds = LineDefaultProps.initialHiddenIds,
}) => {
const componentId = useId()
const formatX = useValueFormatter(xFormat)
Expand All @@ -161,7 +162,7 @@ export const useLine = ({
const theme = useTheme()
const getPointColor = useInheritedColor(pointColor, theme)
const getPointBorderColor = useInheritedColor(pointBorderColor, theme)
const [hiddenIds, setHiddenIds] = useState([])
const [hiddenIds, setHiddenIds] = useState(initialHiddenIds ?? [])

const {
xScale,
Expand Down
1 change: 1 addition & 0 deletions packages/line/src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export const LineDefaultProps = {
defs: [],
fill: [],
role: 'img',
initialHiddenIds: [],
}

export const LineCanvasDefaultProps = {
Expand Down
11 changes: 11 additions & 0 deletions storybook/stories/line/Line.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const commonProperties = {
animate: true,
enableTouchCrosshair: true,
enableSlices: 'x',
initialHiddenIds: ['cognac'],
}

const CustomSymbol = ({ size, color, borderWidth, borderColor }) => (
Expand Down Expand Up @@ -64,6 +65,16 @@ export const StackedLines: Story = {
stacked: true,
}}
curve={args.curve}
legends={[
{
anchor: 'bottom',
direction: 'row',
itemHeight: 20,
itemWidth: 80,
toggleSerie: true,
translateY: 50,
},
]}
/>
),
}
Expand Down

0 comments on commit b9ae884

Please sign in to comment.