Skip to content

Commit a76cac2

Browse files
committed
feat(custom-chart-web): move utils to shared/charts
1 parent d202042 commit a76cac2

File tree

4 files changed

+34
-35
lines changed

4 files changed

+34
-35
lines changed

packages/pluggableWidgets/custom-chart-web/src/CustomChart.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { getPlaygroundContext } from "@mendix/shared-charts/main";
1+
import { constructWrapperStyle, getPlaygroundContext } from "@mendix/shared-charts/main";
22
import { createElement, Fragment, ReactElement } from "react";
33
import { CustomChartContainerProps } from "../typings/CustomChartProps";
44
import { useCustomChart } from "./hooks/useCustomChart";
55
import "./ui/CustomChart.scss";
6-
import { constructWrapperStyle } from "./utils/utils";
76

87
const PlaygroundContext = getPlaygroundContext();
98

packages/pluggableWidgets/custom-chart-web/src/utils/utils.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import { Config, Data, Layout } from "plotly.js-dist-min";
2-
import { CSSProperties } from "react";
3-
import { CustomChartContainerProps } from "typings/CustomChartProps";
4-
52
export function parseData(staticData?: string, attributeData?: string, sampleData?: string): Data[] {
63
let finalData: Data[] = [];
74

@@ -53,33 +50,3 @@ export function parseConfig(configOptions?: string): Partial<Config> {
5350
return {};
5451
}
5552
}
56-
57-
function getHeightScale(height: number, heightUnit: "pixels" | "percentageOfParent" | "percentageOfView"): string {
58-
return `${height}${heightUnit === "pixels" ? "px" : heightUnit === "percentageOfView" ? "vh" : "%"}`;
59-
}
60-
61-
export function constructWrapperStyle(props: CustomChartContainerProps): CSSProperties {
62-
const { widthUnit, heightUnit, minHeightUnit, maxHeightUnit, width, height, minHeight, maxHeight, OverflowY } =
63-
props;
64-
65-
const wrapperStyle: Pick<CSSProperties, "width" | "height" | "minHeight" | "maxHeight" | "maxWidth" | "overflowY"> =
66-
{};
67-
68-
wrapperStyle.width = `${width}${widthUnit === "pixels" ? "px" : "%"}`;
69-
if (heightUnit === "percentageOfWidth") {
70-
wrapperStyle.height = "auto";
71-
72-
if (minHeightUnit !== "none") {
73-
wrapperStyle.minHeight = getHeightScale(minHeight, minHeightUnit);
74-
}
75-
76-
if (maxHeightUnit !== "none") {
77-
wrapperStyle.maxHeight = getHeightScale(maxHeight, maxHeightUnit);
78-
wrapperStyle.overflowY = OverflowY;
79-
}
80-
} else {
81-
wrapperStyle.height = getHeightScale(height, heightUnit);
82-
}
83-
84-
return wrapperStyle;
85-
}

packages/shared/charts/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type * from "./helpers/useEditorStore";
55
export * from "./hooks/usePlotChartDataSeries";
66
export * from "./utils/compareAttrValuesAsc";
77
export * from "./utils/configs";
8+
export * from "./utils/chartStyles";
89
export * from "./utils/equality";
910
export { fallback, pprint } from "./utils/json";
1011
export { getPlaygroundContext, usePlaygroundContext };
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { CSSProperties } from "react";
2+
import { CustomChartContainerProps } from "../../../../pluggableWidgets/custom-chart-web/typings/CustomChartProps";
3+
4+
function getHeightScale(height: number, heightUnit: "pixels" | "percentageOfParent" | "percentageOfView"): string {
5+
return `${height}${heightUnit === "pixels" ? "px" : heightUnit === "percentageOfView" ? "vh" : "%"}`;
6+
}
7+
8+
export function constructWrapperStyle(props: CustomChartContainerProps): CSSProperties {
9+
const { widthUnit, heightUnit, minHeightUnit, maxHeightUnit, width, height, minHeight, maxHeight, OverflowY } =
10+
props;
11+
12+
const wrapperStyle: Pick<CSSProperties, "width" | "height" | "minHeight" | "maxHeight" | "maxWidth" | "overflowY"> =
13+
{};
14+
15+
wrapperStyle.width = `${width}${widthUnit === "pixels" ? "px" : "%"}`;
16+
if (heightUnit === "percentageOfWidth") {
17+
wrapperStyle.height = "auto";
18+
19+
if (minHeightUnit !== "none") {
20+
wrapperStyle.minHeight = getHeightScale(minHeight, minHeightUnit);
21+
}
22+
23+
if (maxHeightUnit !== "none") {
24+
wrapperStyle.maxHeight = getHeightScale(maxHeight, maxHeightUnit);
25+
wrapperStyle.overflowY = OverflowY;
26+
}
27+
} else {
28+
wrapperStyle.height = getHeightScale(height, heightUnit);
29+
}
30+
31+
return wrapperStyle;
32+
}

0 commit comments

Comments
 (0)