|
|
|
@ -1,14 +1,18 @@
|
|
|
|
|
import { LineTimeSerie, LineOptions, LinePod } from '@chartwerk/line-pod'; |
|
|
|
|
|
|
|
|
|
import { AxisRange } from '@chartwerk/core/dist/types'; |
|
|
|
|
import { MarkerSerie } from '@chartwerk/line-pod/dist/models/marker'; |
|
|
|
|
import { SegmentSerie } from '@chartwerk/line-pod/dist/models/segment'; |
|
|
|
|
|
|
|
|
|
import { useEffect, useRef, useState } from 'react'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type ChartwerkLinePodProps = { |
|
|
|
|
id: string; |
|
|
|
|
id?: string; |
|
|
|
|
series: LineTimeSerie[]; |
|
|
|
|
options: LineOptions; |
|
|
|
|
options?: LineOptions; |
|
|
|
|
markers?: MarkerSerie[], |
|
|
|
|
segments?: SegmentSerie[], |
|
|
|
|
className?: string; |
|
|
|
|
// TODO: callback types should be exported from chartwerk
|
|
|
|
|
onZoomIn?: (ranges: AxisRange[]) => void; |
|
|
|
@ -24,7 +28,7 @@ export type ChartwerkLinePodProps = {
|
|
|
|
|
onRenderEnd?: () => void, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function ChartwerkLinePod(props: ChartwerkLinePodProps) { |
|
|
|
|
export function ChartwerkLinePod(props: ChartwerkLinePodProps) { |
|
|
|
|
|
|
|
|
|
const [pod, setPod] = useState<LinePod | null>(null); |
|
|
|
|
const [hack, setHack] = useState<number | null>(null); |
|
|
|
@ -50,27 +54,25 @@ function ChartwerkLinePod(props: ChartwerkLinePodProps) {
|
|
|
|
|
|
|
|
|
|
if(pod === null) { |
|
|
|
|
console.log('create chart'); |
|
|
|
|
console.log("markers"); |
|
|
|
|
console.log(props.markers); |
|
|
|
|
|
|
|
|
|
const newPod = new LinePod( |
|
|
|
|
// @ts-ignore
|
|
|
|
|
chart, |
|
|
|
|
props.series, |
|
|
|
|
{ |
|
|
|
|
...props.options, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
setPod( |
|
|
|
|
newPod |
|
|
|
|
props.options, |
|
|
|
|
props.markers, |
|
|
|
|
props.segments |
|
|
|
|
); |
|
|
|
|
console.log('initial chart render'); |
|
|
|
|
setPod(newPod); |
|
|
|
|
newPod.render(); |
|
|
|
|
} else { |
|
|
|
|
console.log('update chart'); |
|
|
|
|
pod.updateData(props.series, { |
|
|
|
|
...props.options, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, [chart, pod, props.id, props.options]); |
|
|
|
|
}, [chart, pod, props.id, props.options, props.markers, props.segments]); |
|
|
|
|
|
|
|
|
|
// TODO: it's a hack to render the LinePod right after the div appears in DOM
|
|
|
|
|
setTimeout(() => { |
|
|
|
@ -86,5 +88,3 @@ function ChartwerkLinePod(props: ChartwerkLinePodProps) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default ChartwerkLinePod; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|