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