1- import { computed } from "mobx" ;
2- import { CSSProperties , Ref , RefCallback , useEffect } from "react" ;
1+ import { Ref , RefCallback , useEffect } from "react" ;
32import { CustomChartControllerHost } from "src/controllers/CustomChartControllerHost" ;
43import { mergeRefs } from "src/utils/mergeRefs" ;
54import { PlaygroundData } from "@mendix/shared-charts/main" ;
@@ -9,30 +8,7 @@ import { useSetup } from "@mendix/widget-plugin-mobx-kit/react/useSetup";
98import { CustomChartContainerProps } from "../../typings/CustomChartProps" ;
109import { ControllerProps } from "../controllers/typings" ;
1110
12- // TODO: replace with get-dimensions from widget-plugin-platform
13- function getContainerStyle (
14- width : number ,
15- widthUnit : CustomChartContainerProps [ "widthUnit" ] ,
16- height : number ,
17- heightUnit : CustomChartContainerProps [ "heightUnit" ]
18- ) : CSSProperties {
19- const style : CSSProperties = {
20- width : widthUnit === "percentage" ? `${ width } %` : `${ width } px`
21- } ;
22-
23- if ( heightUnit === "percentageOfWidth" ) {
24- style . paddingBottom = widthUnit === "percentage" ? `${ height } %` : `${ width / 2 } px` ;
25- } else if ( heightUnit === "pixels" ) {
26- style . height = `${ height } px` ;
27- } else if ( heightUnit === "percentageOfParent" ) {
28- style . height = `${ height } %` ;
29- }
30-
31- return style ;
32- }
33-
3411interface UseCustomChartReturn {
35- containerStyle : CSSProperties ;
3612 playgroundData : PlaygroundData ;
3713 ref : Ref < HTMLDivElement > | RefCallback < HTMLDivElement > | undefined ;
3814}
@@ -42,6 +18,7 @@ export function useCustomChart(props: CustomChartContainerProps): UseCustomChart
4218
4319 const {
4420 store,
21+ adapter,
4522 chartViewModel,
4623 resizeCtrl : resizeController
4724 } = useSetup ( ( ) => new CustomChartControllerHost ( gateProvider . gate ) ) ;
@@ -50,19 +27,15 @@ export function useCustomChart(props: CustomChartContainerProps): UseCustomChart
5027 gateProvider . setProps ( props ) ;
5128 } ) ;
5229
53- const containerStyle = getContainerStyle ( props . width , props . widthUnit , props . height , props . heightUnit ) ;
54- const playgroundData = computed (
55- ( ) : PlaygroundData => ( {
56- type : "editor.data.v2" ,
57- store,
58- plotData : store . data ,
59- layoutOptions : { } ,
60- configOptions : { }
61- } )
62- ) . get ( ) ;
30+ const playgroundData : PlaygroundData = {
31+ type : "editor.data.v2" ,
32+ store,
33+ plotData : store . data ,
34+ layoutOptions : adapter . layout ,
35+ configOptions : adapter . config
36+ } ;
6337
6438 return {
65- containerStyle,
6639 playgroundData,
6740 ref : mergeRefs < HTMLDivElement > ( resizeController . setTarget , chartViewModel . setChart )
6841 } ;
0 commit comments