Skip to content

Commit

Permalink
Dev | Fix: Removing duplicate from stacked bar example
Browse files Browse the repository at this point in the history
#0
  • Loading branch information
reb-dev committed Apr 11, 2024
1 parent aabc094 commit 22fcd96
Showing 1 changed file with 8 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useRef } from 'react'
import { XYContainer, StackedBar, Axis } from '@unovis/ts'
import { VisXYContainer, VisStackedBar, VisAxis, VisTooltip, VisCrosshair } from '@unovis/react'

import { XYDataRecord, generateXYDataRecords } from '@src/utils/data'
Expand All @@ -13,29 +12,15 @@ export const component = (): JSX.Element => {
(d: XYDataRecord) => d.y1,
(d: XYDataRecord) => d.y2,
]
const data = generateXYDataRecords(15),

const tsChart = useRef<HTMLDivElement>(null)
React.useEffect(() => {
console.log(tsChart)
if (tsChart.current && tsChart.current.childElementCount === 0) {
const c = new XYContainer(tsChart.current, {
margin: { top: 5, left: 5 },
components: [new StackedBar({ x: d => d.x, y: accessors })],
xAxis: new Axis({ type: 'x', numTicks: 3, tickFormat: (x: number) => `${x}ms` }),
yAxis: new Axis({ type: 'y', tickFormat: (y: number) => `${y}bps` }),
}, data)
}
})
const data = generateXYDataRecords(15)

return (
<><div ref={tsChart}></div>
<VisXYContainer<XYDataRecord> data={data} margin={{ top: 5, left: 5 }}>
<VisStackedBar x={d => d.x} y={accessors} />
<VisAxis type='x' numTicks={3} tickFormat={(x: number) => `${x}ms`} />
<VisAxis type='y' tickFormat={(y: number) => `${y}bps`} />
<VisCrosshair template={(d: XYDataRecord) => `${d.x}`} />
<VisTooltip ref={tooltipRef} />
</VisXYContainer></>
<VisXYContainer<XYDataRecord> data={data} margin={{ top: 5, left: 5 }}>
<VisStackedBar x={d => d.x} y={accessors} />
<VisAxis type='x' numTicks={3} tickFormat={(x: number) => `${x}ms`} />
<VisAxis type='y' tickFormat={(y: number) => `${y}bps`} />
<VisCrosshair template={(d: XYDataRecord) => `${d.x}`} />
<VisTooltip ref={tooltipRef} />
</VisXYContainer>
)
}

0 comments on commit 22fcd96

Please sign in to comment.