-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
574 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import makeChartUI from "@/sdk/makeChartUI" | ||
import { unregister } from "@/helpers/makeListeners" | ||
import makeResizeObserver from "@/helpers/makeResizeObserver" | ||
|
||
export default (sdk, chart) => { | ||
const chartUI = makeChartUI(sdk, chart) | ||
let listeners | ||
let resizeObserver | ||
let prevMin | ||
let prevMax | ||
|
||
const mount = element => { | ||
chartUI.mount(element) | ||
|
||
resizeObserver = makeResizeObserver( | ||
element, | ||
() => chartUI.trigger("resize"), | ||
() => chartUI.trigger("resize") | ||
) | ||
|
||
const { loaded } = chart.getAttributes() | ||
|
||
listeners = unregister( | ||
chart.onAttributeChange("hoverX", render), | ||
!loaded && chart.onceAttributeChange("loaded", render) | ||
) | ||
|
||
render() | ||
} | ||
|
||
const render = () => { | ||
chartUI.render() | ||
|
||
const { hoverX, loaded } = chart.getAttributes() | ||
|
||
if (!loaded) return | ||
|
||
const { data } = chart.getPayload() | ||
|
||
const row = hoverX ? chart.getClosestRow(hoverX[0]) : data.length - 1 | ||
|
||
const rowData = data[row] | ||
if (!Array.isArray(rowData)) return | ||
|
||
chartUI.render() | ||
const min = chart.getAttribute("min") | ||
const max = chart.getAttribute("max") | ||
|
||
if (min !== prevMin || max !== prevMax) { | ||
chartUI.sdk.trigger("yAxisChange", chart, min, max) | ||
} | ||
|
||
prevMin = min | ||
prevMax = max | ||
|
||
chartUI.trigger("rendered") | ||
} | ||
|
||
const unmount = () => { | ||
if (listeners) listeners() | ||
|
||
if (resizeObserver) resizeObserver() | ||
|
||
chartUI.unmount() | ||
prevMin = null | ||
prevMax = null | ||
} | ||
|
||
const instance = { | ||
...chartUI, | ||
mount, | ||
unmount, | ||
render, | ||
} | ||
|
||
return instance | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.