@plasmicpkgs/react-chartjs-2 1.0.158 → 1.0.160
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common.d.ts +87 -87
- package/dist/index.d.ts +3 -3
- package/dist/react-chartjs-2.cjs.development.js +35 -19
- package/dist/react-chartjs-2.cjs.development.js.map +1 -1
- package/dist/react-chartjs-2.cjs.production.min.js +1 -1
- package/dist/react-chartjs-2.cjs.production.min.js.map +1 -1
- package/dist/react-chartjs-2.esm.js +35 -19
- package/dist/react-chartjs-2.esm.js.map +1 -1
- package/dist/simple-bar/SimpleBar.d.ts +38 -38
- package/dist/simple-chart/SimpleChart.d.ts +8 -8
- package/dist/simple-chart/index.d.ts +5 -5
- package/dist/simple-line/SimpleLine.d.ts +7 -7
- package/dist/simple-scatter/SimpleScatter.d.ts +4 -4
- package/dist/utils.d.ts +24 -24
- package/package.json +4 -4
package/dist/common.d.ts
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import { Plugin } from "chart.js/dist/types";
|
|
2
|
-
export declare const baseOptions: {
|
|
3
|
-
responsive: boolean;
|
|
4
|
-
chartArea: {};
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* These are hand-picked from the Tailwind palette.
|
|
8
|
-
*/
|
|
9
|
-
export declare const defaultColors: string[];
|
|
10
|
-
export declare function useIsClient(): boolean;
|
|
11
|
-
export interface BaseChartProps {
|
|
12
|
-
className?: string;
|
|
13
|
-
data?: Record<string, any>[];
|
|
14
|
-
labelField?: string;
|
|
15
|
-
interactive?: boolean;
|
|
16
|
-
title?: string;
|
|
17
|
-
chosenFields?: string[];
|
|
18
|
-
scatterSeries?: {
|
|
19
|
-
name: string;
|
|
20
|
-
fields: [string, string];
|
|
21
|
-
}[];
|
|
22
|
-
}
|
|
23
|
-
export interface PrepDataOpts {
|
|
24
|
-
isScatter?: boolean;
|
|
25
|
-
preferNonNumericAsLabel?: boolean;
|
|
26
|
-
extras?: (field: string) => {};
|
|
27
|
-
opacity?: number;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Returns a color from the default color palette.
|
|
31
|
-
*
|
|
32
|
-
* Tries to pick "different" colors that are somewhat spread out on the palette. With a higher 'total' colors requested, the colors will be packed more closely together.
|
|
33
|
-
*
|
|
34
|
-
* We prefer starting from blue when possible. This only starts getting pushed down toward yellow if too many colors requested.
|
|
35
|
-
*
|
|
36
|
-
* If too many colors are requested, it will recycle.
|
|
37
|
-
*/
|
|
38
|
-
export declare function getDefaultColor(index: number, total: number, opacity?: number): string;
|
|
39
|
-
export declare function prepData({ data, labelField, chosenFields, scatterSeries }: BaseChartProps, { isScatter, preferNonNumericAsLabel, extras, opacity }?: PrepDataOpts): {
|
|
40
|
-
datasets: {
|
|
41
|
-
label: string;
|
|
42
|
-
data: {
|
|
43
|
-
x: any;
|
|
44
|
-
y: any;
|
|
45
|
-
}[];
|
|
46
|
-
backgroundColor: string;
|
|
47
|
-
}[];
|
|
48
|
-
labels?: undefined;
|
|
49
|
-
} | {
|
|
50
|
-
labels: any[] | undefined;
|
|
51
|
-
datasets: {
|
|
52
|
-
label: string;
|
|
53
|
-
data: any[];
|
|
54
|
-
backgroundColor: string;
|
|
55
|
-
borderWidth: number;
|
|
56
|
-
borderColor: string;
|
|
57
|
-
}[];
|
|
58
|
-
};
|
|
59
|
-
export declare function prepOptions({ interactive, title }: BaseChartProps): ({
|
|
60
|
-
responsive: boolean;
|
|
61
|
-
chartArea: {};
|
|
62
|
-
} | {
|
|
63
|
-
interaction: {
|
|
64
|
-
mode: "index";
|
|
65
|
-
intersect: boolean;
|
|
66
|
-
};
|
|
67
|
-
events: undefined;
|
|
68
|
-
plugins?: undefined;
|
|
69
|
-
} | {
|
|
70
|
-
events: never[];
|
|
71
|
-
interaction?: undefined;
|
|
72
|
-
plugins?: undefined;
|
|
73
|
-
} | {
|
|
74
|
-
plugins: {
|
|
75
|
-
title: {
|
|
76
|
-
display: boolean;
|
|
77
|
-
text: string;
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
interaction?: undefined;
|
|
81
|
-
events?: undefined;
|
|
82
|
-
} | {
|
|
83
|
-
interaction?: undefined;
|
|
84
|
-
events?: undefined;
|
|
85
|
-
plugins?: undefined;
|
|
86
|
-
})[];
|
|
87
|
-
export declare const ChartAreaPlugin: Plugin;
|
|
1
|
+
import { Plugin } from "chart.js/dist/types";
|
|
2
|
+
export declare const baseOptions: {
|
|
3
|
+
responsive: boolean;
|
|
4
|
+
chartArea: {};
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* These are hand-picked from the Tailwind palette.
|
|
8
|
+
*/
|
|
9
|
+
export declare const defaultColors: string[];
|
|
10
|
+
export declare function useIsClient(): boolean;
|
|
11
|
+
export interface BaseChartProps {
|
|
12
|
+
className?: string;
|
|
13
|
+
data?: Record<string, any>[];
|
|
14
|
+
labelField?: string;
|
|
15
|
+
interactive?: boolean;
|
|
16
|
+
title?: string;
|
|
17
|
+
chosenFields?: string[];
|
|
18
|
+
scatterSeries?: {
|
|
19
|
+
name: string;
|
|
20
|
+
fields: [string, string];
|
|
21
|
+
}[];
|
|
22
|
+
}
|
|
23
|
+
export interface PrepDataOpts {
|
|
24
|
+
isScatter?: boolean;
|
|
25
|
+
preferNonNumericAsLabel?: boolean;
|
|
26
|
+
extras?: (field: string) => {};
|
|
27
|
+
opacity?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns a color from the default color palette.
|
|
31
|
+
*
|
|
32
|
+
* Tries to pick "different" colors that are somewhat spread out on the palette. With a higher 'total' colors requested, the colors will be packed more closely together.
|
|
33
|
+
*
|
|
34
|
+
* We prefer starting from blue when possible. This only starts getting pushed down toward yellow if too many colors requested.
|
|
35
|
+
*
|
|
36
|
+
* If too many colors are requested, it will recycle.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getDefaultColor(index: number, total: number, opacity?: number): string;
|
|
39
|
+
export declare function prepData({ data, labelField, chosenFields, scatterSeries }: BaseChartProps, { isScatter, preferNonNumericAsLabel, extras, opacity }?: PrepDataOpts): {
|
|
40
|
+
datasets: {
|
|
41
|
+
label: string;
|
|
42
|
+
data: {
|
|
43
|
+
x: any;
|
|
44
|
+
y: any;
|
|
45
|
+
}[];
|
|
46
|
+
backgroundColor: string;
|
|
47
|
+
}[];
|
|
48
|
+
labels?: undefined;
|
|
49
|
+
} | {
|
|
50
|
+
labels: any[] | undefined;
|
|
51
|
+
datasets: {
|
|
52
|
+
label: string;
|
|
53
|
+
data: any[];
|
|
54
|
+
backgroundColor: string;
|
|
55
|
+
borderWidth: number;
|
|
56
|
+
borderColor: string;
|
|
57
|
+
}[];
|
|
58
|
+
};
|
|
59
|
+
export declare function prepOptions({ interactive, title }: BaseChartProps): ({
|
|
60
|
+
responsive: boolean;
|
|
61
|
+
chartArea: {};
|
|
62
|
+
} | {
|
|
63
|
+
interaction: {
|
|
64
|
+
mode: "index";
|
|
65
|
+
intersect: boolean;
|
|
66
|
+
};
|
|
67
|
+
events: undefined;
|
|
68
|
+
plugins?: undefined;
|
|
69
|
+
} | {
|
|
70
|
+
events: never[];
|
|
71
|
+
interaction?: undefined;
|
|
72
|
+
plugins?: undefined;
|
|
73
|
+
} | {
|
|
74
|
+
plugins: {
|
|
75
|
+
title: {
|
|
76
|
+
display: boolean;
|
|
77
|
+
text: string;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
interaction?: undefined;
|
|
81
|
+
events?: undefined;
|
|
82
|
+
} | {
|
|
83
|
+
interaction?: undefined;
|
|
84
|
+
events?: undefined;
|
|
85
|
+
plugins?: undefined;
|
|
86
|
+
})[];
|
|
87
|
+
export declare const ChartAreaPlugin: Plugin;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Registerable } from "./utils";
|
|
2
|
-
export { SimpleChart } from "./simple-chart";
|
|
3
|
-
export declare function registerAll(loader?: Registerable): void;
|
|
1
|
+
import { Registerable } from "./utils";
|
|
2
|
+
export { SimpleChart } from "./simple-chart";
|
|
3
|
+
export declare function registerAll(loader?: Registerable): void;
|
|
@@ -36,8 +36,8 @@ var baseOptions = {
|
|
|
36
36
|
// backgroundColor: "#f8fafc",
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
/**
|
|
40
|
-
* These are hand-picked from the Tailwind palette.
|
|
39
|
+
/**
|
|
40
|
+
* These are hand-picked from the Tailwind palette.
|
|
41
41
|
*/
|
|
42
42
|
var defaultColors = ["hsla(25,95%,53%,1.0)", "hsla(38,92%,50%,1.0)", "hsla(45,93%,47%,1.0)", "hsla(84,81%,44%,1.0)", "hsla(142,71%,45%,1.0)", "hsla(160,84%,39%,1.0)", "hsla(173,80%,40%,1.0)", "hsla(199,89%,48%,1.0)", "hsla(217,91%,60%,1.0)", "hsla(239,84%,67%,1.0)", "hsla(258,90%,66%,1.0)", "hsla(271,91%,65%,1.0)", "hsla(292,84%,61%,1.0)", "hsla(293,69%,49%,1.0)", "hsla(295,72%,40%,1.0)", "hsla(295,70%,33%,1.0)"];
|
|
43
43
|
function useIsClient() {
|
|
@@ -52,14 +52,14 @@ function useIsClient() {
|
|
|
52
52
|
function range(total) {
|
|
53
53
|
return Array.from(Array(total).keys());
|
|
54
54
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Returns a color from the default color palette.
|
|
57
|
-
*
|
|
58
|
-
* Tries to pick "different" colors that are somewhat spread out on the palette. With a higher 'total' colors requested, the colors will be packed more closely together.
|
|
59
|
-
*
|
|
60
|
-
* We prefer starting from blue when possible. This only starts getting pushed down toward yellow if too many colors requested.
|
|
61
|
-
*
|
|
62
|
-
* If too many colors are requested, it will recycle.
|
|
55
|
+
/**
|
|
56
|
+
* Returns a color from the default color palette.
|
|
57
|
+
*
|
|
58
|
+
* Tries to pick "different" colors that are somewhat spread out on the palette. With a higher 'total' colors requested, the colors will be packed more closely together.
|
|
59
|
+
*
|
|
60
|
+
* We prefer starting from blue when possible. This only starts getting pushed down toward yellow if too many colors requested.
|
|
61
|
+
*
|
|
62
|
+
* If too many colors are requested, it will recycle.
|
|
63
63
|
*/
|
|
64
64
|
function getDefaultColor(index, total, opacity) {
|
|
65
65
|
var preferredStart = 9;
|
|
@@ -143,12 +143,12 @@ function prepData(_ref, _temp) {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
// additional styling
|
|
146
|
-
/*
|
|
147
|
-
elements: {
|
|
148
|
-
bar: {
|
|
149
|
-
borderWidth: 2,
|
|
150
|
-
},
|
|
151
|
-
},
|
|
146
|
+
/*
|
|
147
|
+
elements: {
|
|
148
|
+
bar: {
|
|
149
|
+
borderWidth: 2,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
152
|
|
|
153
153
|
*/
|
|
154
154
|
function prepOptions(_ref3) {
|
|
@@ -343,11 +343,11 @@ function SimpleChart(props) {
|
|
|
343
343
|
var _props$type;
|
|
344
344
|
switch ((_props$type = props.type) != null ? _props$type : "bar") {
|
|
345
345
|
case "bar":
|
|
346
|
-
return React__default.createElement(SimpleBar,
|
|
346
|
+
return React__default.createElement(SimpleBar, _extends({}, props));
|
|
347
347
|
case "line":
|
|
348
|
-
return React__default.createElement(SimpleLine,
|
|
348
|
+
return React__default.createElement(SimpleLine, _extends({}, props));
|
|
349
349
|
case "scatter":
|
|
350
|
-
return React__default.createElement(SimpleScatter,
|
|
350
|
+
return React__default.createElement(SimpleScatter, _extends({}, props));
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
|
|
@@ -443,6 +443,22 @@ var simpleChartMeta = {
|
|
|
443
443
|
return props.type !== "line";
|
|
444
444
|
}
|
|
445
445
|
})
|
|
446
|
+
// TODO
|
|
447
|
+
// datasets: {
|
|
448
|
+
// type: "array",
|
|
449
|
+
// unstable__keyFunc: (x) => x.key,
|
|
450
|
+
// unstable__minimalValue: (_props, ctx) => null,
|
|
451
|
+
// itemType: {
|
|
452
|
+
// type: "object",
|
|
453
|
+
// fields: {
|
|
454
|
+
// label: "string",
|
|
455
|
+
// fieldId: "string",
|
|
456
|
+
// hidden: {
|
|
457
|
+
// type: "boolean",
|
|
458
|
+
// },
|
|
459
|
+
// },
|
|
460
|
+
// },
|
|
461
|
+
// },
|
|
446
462
|
},
|
|
447
463
|
defaultStyles: {
|
|
448
464
|
width: "stretch"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-chartjs-2.cjs.development.js","sources":["../src/utils.ts","../src/common.ts","../src/simple-bar/SimpleBar.tsx","../src/simple-line/SimpleLine.tsx","../src/simple-scatter/SimpleScatter.tsx","../src/simple-chart/SimpleChart.tsx","../src/simple-chart/index.tsx","../src/index.tsx"],"sourcesContent":["import {\n CodeComponentMeta,\n default as registerComponent,\n} from \"@plasmicapp/host/registerComponent\";\nimport {\n GlobalContextMeta,\n default as registerGlobalContext,\n} from \"@plasmicapp/host/registerGlobalContext\";\nimport { default as registerToken } from \"@plasmicapp/host/registerToken\";\nimport React from \"react\";\n\nexport type Registerable = {\n registerComponent: typeof registerComponent;\n registerGlobalContext: typeof registerGlobalContext;\n registerToken: typeof registerToken;\n};\n\nexport function makeRegisterComponent<T extends React.ComponentType<any>>(\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n return function (loader?: Registerable) {\n registerComponentHelper(loader, component, meta);\n };\n}\n\nexport function makeRegisterGlobalContext<T extends React.ComponentType<any>>(\n component: T,\n meta: GlobalContextMeta<React.ComponentProps<T>>\n) {\n return function (loader?: Registerable) {\n if (loader) {\n loader.registerGlobalContext(component, meta);\n } else {\n registerGlobalContext(component, meta);\n }\n };\n}\n\nexport function registerComponentHelper<T extends React.ComponentType<any>>(\n loader: Registerable | undefined,\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n if (loader) {\n loader.registerComponent(component, meta);\n } else {\n registerComponent(component, meta);\n }\n}\n\ntype ReactElt = {\n children: ReactElt | ReactElt[];\n props: {\n children: ReactElt | ReactElt[];\n [prop: string]: any;\n } | null;\n type: React.ComponentType<any> | null;\n key: string | null;\n} | null;\n\nexport function traverseReactEltTree(\n children: React.ReactNode,\n callback: (elt: ReactElt) => void\n) {\n const rec = (elts: ReactElt | ReactElt[] | null) => {\n (Array.isArray(elts) ? elts : [elts]).forEach((elt) => {\n if (elt) {\n callback(elt);\n if (elt.children) {\n rec(elt.children);\n }\n if (elt.props?.children && elt.props.children !== elt.children) {\n rec(elt.props.children);\n }\n }\n });\n };\n rec(children as any);\n}\n\nexport function asArray<T>(x: T[] | T | undefined | null) {\n if (Array.isArray(x)) {\n return x;\n } else if (x == null) {\n return [];\n } else {\n return [x];\n }\n}\n","import { Plugin } from \"chart.js/dist/types\";\nimport { useEffect, useState } from \"react\";\n\nexport const baseOptions = {\n responsive: true,\n chartArea: {\n // backgroundColor: \"#f8fafc\",\n },\n};\n\n/**\n * These are hand-picked from the Tailwind palette.\n */\nexport const defaultColors = [\n \"hsla(25,95%,53%,1.0)\",\n \"hsla(38,92%,50%,1.0)\",\n \"hsla(45,93%,47%,1.0)\",\n \"hsla(84,81%,44%,1.0)\",\n \"hsla(142,71%,45%,1.0)\",\n \"hsla(160,84%,39%,1.0)\",\n \"hsla(173,80%,40%,1.0)\",\n \"hsla(199,89%,48%,1.0)\",\n \"hsla(217,91%,60%,1.0)\",\n \"hsla(239,84%,67%,1.0)\",\n \"hsla(258,90%,66%,1.0)\",\n \"hsla(271,91%,65%,1.0)\",\n \"hsla(292,84%,61%,1.0)\",\n \"hsla(293,69%,49%,1.0)\",\n \"hsla(295,72%,40%,1.0)\",\n \"hsla(295,70%,33%,1.0)\",\n];\n\nexport function useIsClient() {\n const [loaded, setLoaded] = useState(false);\n useEffect(() => {\n setLoaded(true);\n });\n return loaded;\n}\n\nexport interface BaseChartProps {\n className?: string;\n data?: Record<string, any>[];\n labelField?: string;\n interactive?: boolean;\n title?: string;\n chosenFields?: string[];\n scatterSeries?: { name: string; fields: [string, string] }[];\n}\n\nexport interface PrepDataOpts {\n isScatter?: boolean;\n preferNonNumericAsLabel?: boolean;\n extras?: (field: string) => {};\n opacity?: number;\n}\n\nfunction range(total: number) {\n return Array.from(Array(total).keys());\n}\n\n/**\n * Returns a color from the default color palette.\n *\n * Tries to pick \"different\" colors that are somewhat spread out on the palette. With a higher 'total' colors requested, the colors will be packed more closely together.\n *\n * We prefer starting from blue when possible. This only starts getting pushed down toward yellow if too many colors requested.\n *\n * If too many colors are requested, it will recycle.\n */\nexport function getDefaultColor(\n index: number,\n total: number,\n opacity?: number\n) {\n const preferredStart = 9;\n const end = defaultColors.length - 1;\n const start = Math.max(0, Math.min(preferredStart, end - total));\n const stops =\n total > defaultColors.length\n ? range(defaultColors.length)\n : range(total).map((_, i) =>\n Math.round(\n start + (total > 1 ? ((1.0 * i) / (total - 1)) * (end - start) : 0)\n )\n );\n const selected = defaultColors[stops[index % stops.length]];\n if (opacity === undefined) {\n return selected;\n }\n return selected.replace(\"1.0\", \"\" + opacity);\n}\n\nexport function prepData(\n { data = [], labelField, chosenFields, scatterSeries }: BaseChartProps,\n { isScatter, preferNonNumericAsLabel, extras, opacity }: PrepDataOpts = {}\n) {\n const fields = Object.keys(data[0] ?? {});\n const isFieldAllNumericOrNil = new Map(\n fields.map((key) => [key, data.every((item) => !isNaN(item[key] ?? 0))])\n );\n const realLabelField =\n labelField ??\n (preferNonNumericAsLabel\n ? fields.find((field) => !isFieldAllNumericOrNil.get(field))\n : fields[0]);\n const numericFields = fields.filter((field) =>\n isFieldAllNumericOrNil.get(field)\n );\n if (isScatter) {\n scatterSeries = isScatter\n ? scatterSeries ?? [\n {\n name: `${numericFields[0]}-${numericFields[1]}`,\n fields: [numericFields[0], numericFields[1]] as [string, string],\n },\n ]\n : undefined;\n return {\n datasets: (scatterSeries ?? []).map((series, index) => ({\n ...extras?.(series.name),\n label: series.name,\n data: data.map((item) => ({\n x: item[series.fields[0]] ?? 0,\n y: item[series.fields[1]] ?? 0,\n })),\n backgroundColor: getDefaultColor(\n index,\n (scatterSeries ?? []).length,\n opacity\n ),\n })),\n };\n } else {\n const autoChosenFields = numericFields.filter(\n (field) => field !== realLabelField\n );\n return {\n labels: realLabelField\n ? data.map((item) => item[realLabelField])\n : undefined,\n datasets: (chosenFields ?? autoChosenFields).map((key, index) => {\n return {\n ...extras?.(key),\n label: key,\n data: data.map((item) => item[key] ?? 0),\n backgroundColor: getDefaultColor(\n index,\n (chosenFields ?? autoChosenFields).length,\n 1\n ),\n borderWidth: 2,\n borderColor: getDefaultColor(\n index,\n (chosenFields ?? autoChosenFields).length,\n 1\n ),\n };\n }),\n };\n }\n}\n\n// additional styling\n\n/*\n elements: {\n bar: {\n borderWidth: 2,\n },\n },\n\n */\n\nexport function prepOptions({ interactive = true, title }: BaseChartProps) {\n return [\n baseOptions,\n interactive\n ? {\n interaction: {\n mode: \"index\" as const,\n intersect: false,\n },\n events: undefined,\n }\n : {\n events: [],\n },\n title\n ? {\n plugins: {\n title: { display: true, text: title },\n },\n }\n : {},\n ];\n}\n\nexport const ChartAreaPlugin: Plugin = {\n id: \"chartAreaPlugin\",\n // eslint-disable-next-line object-shorthand\n beforeDraw: (chart) => {\n const chartAreaOptions = (chart.config.options as any).chartArea;\n if (chartAreaOptions && chartAreaOptions.backgroundColor) {\n const ctx = chart.canvas.getContext(\"2d\");\n const { chartArea } = chart;\n if (ctx) {\n ctx.save();\n ctx.fillStyle = chartAreaOptions.backgroundColor;\n // eslint-disable-next-line max-len\n ctx.fillRect(\n chartArea.left,\n chartArea.top,\n chartArea.right - chartArea.left,\n chartArea.bottom - chartArea.top\n );\n ctx.restore();\n }\n }\n },\n};\n","import {\n BarElement,\n CategoryScale,\n Chart as ChartJS,\n Legend,\n LinearScale,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Bar } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport const stackedOptions = {\n scales: {\n x: {\n stacked: true,\n ticks: {\n major: {\n enabled: false,\n },\n },\n },\n y: {\n stacked: true,\n },\n },\n};\n\nexport const vertOptions = {\n indexAxis: \"x\" as const,\n plugins: {\n legend: {\n position: \"top\" as const,\n },\n },\n};\nexport const horizOptions = {\n indexAxis: \"y\" as const,\n plugins: {\n legend: {\n position: \"right\" as const,\n },\n },\n};\n\nexport interface SimpleBarProps extends BaseChartProps {\n direction?: \"vertical\" | \"horizontal\";\n stacked?: boolean;\n}\n\nexport function SimpleBar(props: SimpleBarProps) {\n const { direction = \"vertical\", stacked, className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n CategoryScale,\n LinearScale,\n BarElement,\n Title,\n Tooltip,\n Legend\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, {\n preferNonNumericAsLabel: true,\n opacity: 1,\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Bar\n key={`${props.direction}${props.stacked}`}\n options={deepmerge.all([\n ...options,\n direction === \"vertical\" ? vertOptions : horizOptions,\n stacked ? stackedOptions : {},\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import {\n CategoryScale,\n Chart as ChartJS,\n Filler,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect, useState } from \"react\";\nimport { Line } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport interface SimpleLineProps extends BaseChartProps {\n fill?: boolean;\n secondAxisField?: string;\n}\n\n// Force a re-mount when the secondAxisField is unset / re-set\n// https://app.shortcut.com/plasmic/story/38358/chart-component-issues-with-second-axis-field\nconst useKey = (secondAxisField?: string) => {\n const [key, setKey] = useState(0);\n\n // change key once when the secondAxisField is unset.\n if (!secondAxisField && key) {\n setKey(0);\n }\n\n // change key once when the secondAxisField value changes from undefined -> something\n if (secondAxisField && !key) {\n setKey(Math.random());\n }\n\n return key;\n};\n\nexport function SimpleLine(props: SimpleLineProps) {\n const { secondAxisField, fill, className } = props;\n const isClient = useIsClient();\n const key = useKey(props.secondAxisField);\n\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n CategoryScale,\n LinearScale,\n PointElement,\n LineElement,\n Title,\n Tooltip,\n Filler,\n Legend\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, {\n extras: (field) => ({\n fill,\n pointRadius: 0,\n yAxisID: field === secondAxisField ? \"y1\" : \"y\",\n }),\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Line\n key={key}\n options={deepmerge.all([\n ...options,\n secondAxisField\n ? {\n scales: {\n y: {\n type: \"linear\" as const,\n display: true,\n position: \"left\" as const,\n },\n y1: {\n type: \"linear\" as const,\n display: true,\n position: \"right\" as const,\n grid: {\n drawOnChartArea: false,\n },\n },\n },\n }\n : {},\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import {\n Chart as ChartJS,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Scatter } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport type SimpleScatterProps = BaseChartProps;\n\nexport function SimpleScatter(props: SimpleScatterProps) {\n const { className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n LinearScale,\n PointElement,\n LineElement,\n Tooltip,\n Legend,\n Title\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, { isScatter: true, opacity: 1 });\n const options = prepOptions(props);\n\n return (\n <div className={className}>\n <Scatter\n options={deepmerge.all([\n ...options,\n {\n scales: {\n y: {\n beginAtZero: true,\n },\n },\n },\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import React, { ReactElement } from \"react\";\nimport { SimpleBar, SimpleBarProps } from \"../simple-bar/SimpleBar\";\nimport { SimpleLine, SimpleLineProps } from \"../simple-line/SimpleLine\";\nimport {\n SimpleScatter,\n SimpleScatterProps,\n} from \"../simple-scatter/SimpleScatter\";\n\nexport type SimpleChartProps = {\n type?: \"bar\" | \"line\" | \"scatter\";\n} & (SimpleBarProps | SimpleLineProps | SimpleScatterProps);\n\nexport function SimpleChart(props: SimpleChartProps): ReactElement {\n switch (props.type ?? \"bar\") {\n case \"bar\":\n return <SimpleBar {...(props as any)} />;\n case \"line\":\n return <SimpleLine {...(props as any)} />;\n case \"scatter\":\n return <SimpleScatter {...(props as any)} />;\n }\n}\n","import {\n CodeComponentMeta,\n PropType,\n} from \"@plasmicapp/host/registerComponent\";\nimport { Registerable, registerComponentHelper } from \"../utils\";\nimport { SimpleChart, SimpleChartProps } from \"./SimpleChart\";\n\nexport * from \"./SimpleChart\";\nexport default SimpleChart;\n\nconst fieldChoice: PropType<SimpleChartProps> = {\n type: \"choice\",\n options: (props: SimpleChartProps) =>\n props.data?.[0] ? Object.keys(props.data[0]) : [],\n} as const;\nconst simpleChartMeta: CodeComponentMeta<SimpleChartProps> = {\n name: \"hostless-react-chartjs-2-simple-chart\",\n displayName: \"Chart\",\n props: {\n type: {\n type: \"choice\",\n options: [\n {\n value: \"bar\",\n label: \"Bar\",\n },\n {\n value: \"line\",\n label: \"Line\",\n },\n {\n value: \"scatter\",\n label: \"Scatter\",\n },\n ],\n defaultValueHint: \"bar\",\n },\n data: {\n type: \"exprEditor\",\n description: \"The data as an array of objects\",\n defaultExpr: JSON.stringify([\n {\n region: \"APAC\",\n revenue: 3294,\n spend: 2675,\n },\n {\n region: \"EMEA\",\n revenue: 3245,\n spend: 3895,\n },\n {\n region: \"LATAM\",\n revenue: 2165,\n spend: 3498,\n },\n {\n region: \"AMER\",\n revenue: 3215,\n spend: 1656,\n },\n ]),\n },\n labelField: {\n ...fieldChoice,\n hidden: (props) => props.type === \"scatter\",\n },\n title: \"string\",\n interactive: {\n type: \"boolean\",\n defaultValueHint: true,\n },\n // Bar chart\n direction: {\n type: \"choice\",\n options: [\"horizontal\", \"vertical\"].map((dir) => ({\n value: dir,\n label: dir[0].toUpperCase() + dir.slice(1),\n })),\n defaultValueHint: \"Vertical\",\n hidden: ({ type = \"bar\" }) => type !== \"bar\",\n },\n stacked: {\n type: \"boolean\",\n hidden: ({ type = \"bar\" }) => type !== \"bar\",\n },\n // Line chart\n fill: {\n type: \"boolean\",\n hidden: (props) => props.type !== \"line\",\n },\n secondAxisField: {\n ...fieldChoice,\n hidden: (props) => props.type !== \"line\",\n },\n\n // TODO\n // datasets: {\n // type: \"array\",\n // unstable__keyFunc: (x) => x.key,\n // unstable__minimalValue: (_props, ctx) => null,\n // itemType: {\n // type: \"object\",\n // fields: {\n // label: \"string\",\n // fieldId: \"string\",\n // hidden: {\n // type: \"boolean\",\n // },\n // },\n // },\n // },\n },\n\n defaultStyles: {\n width: \"stretch\",\n },\n\n importName: \"SimpleChart\",\n importPath: \"@plasmicpkgs/react-chartjs-2\",\n};\n\nexport function registerSimpleChart(loader?: Registerable) {\n registerComponentHelper(loader, SimpleChart, simpleChartMeta);\n}\n","import { registerSimpleChart } from \"./simple-chart\";\nimport { Registerable } from \"./utils\";\n\nexport { SimpleChart } from \"./simple-chart\";\n\nexport function registerAll(loader?: Registerable) {\n registerSimpleChart(loader);\n}\n"],"names":["registerComponentHelper","loader","component","meta","registerComponent","baseOptions","responsive","chartArea","defaultColors","useIsClient","_useState","useState","loaded","setLoaded","useEffect","range","total","Array","from","keys","getDefaultColor","index","opacity","preferredStart","end","length","start","Math","max","min","stops","map","_","i","round","selected","undefined","replace","prepData","_ref","_temp","data","_ref$data","labelField","chosenFields","scatterSeries","_ref2","isScatter","preferNonNumericAsLabel","extras","fields","Object","_data$","isFieldAllNumericOrNil","Map","key","every","item","_item$key","isNaN","realLabelField","find","field","get","numericFields","filter","name","datasets","series","_extends","label","_item$series$fields$","_item$series$fields$2","x","y","backgroundColor","autoChosenFields","labels","_item$key2","borderWidth","borderColor","prepOptions","_ref3","interactive","_ref3$interactive","title","interaction","mode","intersect","events","plugins","display","text","ChartAreaPlugin","id","beforeDraw","chart","chartAreaOptions","config","options","ctx","canvas","getContext","save","fillStyle","fillRect","left","top","right","bottom","restore","stackedOptions","scales","stacked","ticks","major","enabled","vertOptions","indexAxis","legend","position","horizOptions","SimpleBar","props","_props$direction","direction","className","isClient","ChartJS","register","CategoryScale","LinearScale","BarElement","Title","Tooltip","Legend","normalized","React","Bar","deepmerge","all","concat","useKey","secondAxisField","setKey","random","SimpleLine","fill","PointElement","LineElement","Filler","pointRadius","yAxisID","Line","type","y1","grid","drawOnChartArea","SimpleScatter","Scatter","beginAtZero","SimpleChart","_props$type","fieldChoice","_props$data","simpleChartMeta","displayName","value","defaultValueHint","description","defaultExpr","JSON","stringify","region","revenue","spend","hidden","dir","toUpperCase","slice","_ref$type","_ref2$type","defaultStyles","width","importName","importPath","registerSimpleChart","registerAll"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;SAuCgBA,uBAAuBA,CACrCC,MAAgC,EAChCC,SAAY,EACZC,IAAgD;EAEhD,IAAIF,MAAM,EAAE;IACVA,MAAM,CAACG,iBAAiB,CAACF,SAAS,EAAEC,IAAI,CAAC;GAC1C,MAAM;IACLC,iBAAiB,CAACF,SAAS,EAAEC,IAAI,CAAC;;AAEtC;;AC9CO,IAAME,WAAW,GAAG;EACzBC,UAAU,EAAE,IAAI;EAChBC,SAAS,EAAE;;;CAGZ;AAED;;;AAGA,AAAO,IAAMC,aAAa,GAAG,CAC3B,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB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WAAWA,CAAC1L,MAAqB;EAC/CyL,mBAAmB,CAACzL,MAAM,CAAC;AAC7B;;;;;"}
|
|
1
|
+
{"version":3,"file":"react-chartjs-2.cjs.development.js","sources":["../src/utils.ts","../src/common.ts","../src/simple-bar/SimpleBar.tsx","../src/simple-line/SimpleLine.tsx","../src/simple-scatter/SimpleScatter.tsx","../src/simple-chart/SimpleChart.tsx","../src/simple-chart/index.tsx","../src/index.tsx"],"sourcesContent":["import {\n CodeComponentMeta,\n default as registerComponent,\n} from \"@plasmicapp/host/registerComponent\";\nimport {\n GlobalContextMeta,\n default as registerGlobalContext,\n} from \"@plasmicapp/host/registerGlobalContext\";\nimport { default as registerToken } from \"@plasmicapp/host/registerToken\";\nimport React from \"react\";\n\nexport type Registerable = {\n registerComponent: typeof registerComponent;\n registerGlobalContext: typeof registerGlobalContext;\n registerToken: typeof registerToken;\n};\n\nexport function makeRegisterComponent<T extends React.ComponentType<any>>(\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n return function (loader?: Registerable) {\n registerComponentHelper(loader, component, meta);\n };\n}\n\nexport function makeRegisterGlobalContext<T extends React.ComponentType<any>>(\n component: T,\n meta: GlobalContextMeta<React.ComponentProps<T>>\n) {\n return function (loader?: Registerable) {\n if (loader) {\n loader.registerGlobalContext(component, meta);\n } else {\n registerGlobalContext(component, meta);\n }\n };\n}\n\nexport function registerComponentHelper<T extends React.ComponentType<any>>(\n loader: Registerable | undefined,\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n if (loader) {\n loader.registerComponent(component, meta);\n } else {\n registerComponent(component, meta);\n }\n}\n\ntype ReactElt = {\n children: ReactElt | ReactElt[];\n props: {\n children: ReactElt | ReactElt[];\n [prop: string]: any;\n } | null;\n type: React.ComponentType<any> | null;\n key: string | null;\n} | null;\n\nexport function traverseReactEltTree(\n children: React.ReactNode,\n callback: (elt: ReactElt) => void\n) {\n const rec = (elts: ReactElt | ReactElt[] | null) => {\n (Array.isArray(elts) ? elts : [elts]).forEach((elt) => {\n if (elt) {\n callback(elt);\n if (elt.children) {\n rec(elt.children);\n }\n if (elt.props?.children && elt.props.children !== elt.children) {\n rec(elt.props.children);\n }\n }\n });\n };\n rec(children as any);\n}\n\nexport function asArray<T>(x: T[] | T | undefined | null) {\n if (Array.isArray(x)) {\n return x;\n } else if (x == null) {\n return [];\n } else {\n return [x];\n }\n}\n","import { Plugin } from \"chart.js/dist/types\";\nimport { useEffect, useState } from \"react\";\n\nexport const baseOptions = {\n responsive: true,\n chartArea: {\n // backgroundColor: \"#f8fafc\",\n },\n};\n\n/**\n * These are hand-picked from the Tailwind palette.\n */\nexport const defaultColors = [\n \"hsla(25,95%,53%,1.0)\",\n \"hsla(38,92%,50%,1.0)\",\n \"hsla(45,93%,47%,1.0)\",\n \"hsla(84,81%,44%,1.0)\",\n \"hsla(142,71%,45%,1.0)\",\n \"hsla(160,84%,39%,1.0)\",\n \"hsla(173,80%,40%,1.0)\",\n \"hsla(199,89%,48%,1.0)\",\n \"hsla(217,91%,60%,1.0)\",\n \"hsla(239,84%,67%,1.0)\",\n \"hsla(258,90%,66%,1.0)\",\n \"hsla(271,91%,65%,1.0)\",\n \"hsla(292,84%,61%,1.0)\",\n \"hsla(293,69%,49%,1.0)\",\n \"hsla(295,72%,40%,1.0)\",\n \"hsla(295,70%,33%,1.0)\",\n];\n\nexport function useIsClient() {\n const [loaded, setLoaded] = useState(false);\n useEffect(() => {\n setLoaded(true);\n });\n return loaded;\n}\n\nexport interface BaseChartProps {\n className?: string;\n data?: Record<string, any>[];\n labelField?: string;\n interactive?: boolean;\n title?: string;\n chosenFields?: string[];\n scatterSeries?: { name: string; fields: [string, string] }[];\n}\n\nexport interface PrepDataOpts {\n isScatter?: boolean;\n preferNonNumericAsLabel?: boolean;\n extras?: (field: string) => {};\n opacity?: number;\n}\n\nfunction range(total: number) {\n return Array.from(Array(total).keys());\n}\n\n/**\n * Returns a color from the default color palette.\n *\n * Tries to pick \"different\" colors that are somewhat spread out on the palette. With a higher 'total' colors requested, the colors will be packed more closely together.\n *\n * We prefer starting from blue when possible. This only starts getting pushed down toward yellow if too many colors requested.\n *\n * If too many colors are requested, it will recycle.\n */\nexport function getDefaultColor(\n index: number,\n total: number,\n opacity?: number\n) {\n const preferredStart = 9;\n const end = defaultColors.length - 1;\n const start = Math.max(0, Math.min(preferredStart, end - total));\n const stops =\n total > defaultColors.length\n ? range(defaultColors.length)\n : range(total).map((_, i) =>\n Math.round(\n start + (total > 1 ? ((1.0 * i) / (total - 1)) * (end - start) : 0)\n )\n );\n const selected = defaultColors[stops[index % stops.length]];\n if (opacity === undefined) {\n return selected;\n }\n return selected.replace(\"1.0\", \"\" + opacity);\n}\n\nexport function prepData(\n { data = [], labelField, chosenFields, scatterSeries }: BaseChartProps,\n { isScatter, preferNonNumericAsLabel, extras, opacity }: PrepDataOpts = {}\n) {\n const fields = Object.keys(data[0] ?? {});\n const isFieldAllNumericOrNil = new Map(\n fields.map((key) => [key, data.every((item) => !isNaN(item[key] ?? 0))])\n );\n const realLabelField =\n labelField ??\n (preferNonNumericAsLabel\n ? fields.find((field) => !isFieldAllNumericOrNil.get(field))\n : fields[0]);\n const numericFields = fields.filter((field) =>\n isFieldAllNumericOrNil.get(field)\n );\n if (isScatter) {\n scatterSeries = isScatter\n ? scatterSeries ?? [\n {\n name: `${numericFields[0]}-${numericFields[1]}`,\n fields: [numericFields[0], numericFields[1]] as [string, string],\n },\n ]\n : undefined;\n return {\n datasets: (scatterSeries ?? []).map((series, index) => ({\n ...extras?.(series.name),\n label: series.name,\n data: data.map((item) => ({\n x: item[series.fields[0]] ?? 0,\n y: item[series.fields[1]] ?? 0,\n })),\n backgroundColor: getDefaultColor(\n index,\n (scatterSeries ?? []).length,\n opacity\n ),\n })),\n };\n } else {\n const autoChosenFields = numericFields.filter(\n (field) => field !== realLabelField\n );\n return {\n labels: realLabelField\n ? data.map((item) => item[realLabelField])\n : undefined,\n datasets: (chosenFields ?? autoChosenFields).map((key, index) => {\n return {\n ...extras?.(key),\n label: key,\n data: data.map((item) => item[key] ?? 0),\n backgroundColor: getDefaultColor(\n index,\n (chosenFields ?? autoChosenFields).length,\n 1\n ),\n borderWidth: 2,\n borderColor: getDefaultColor(\n index,\n (chosenFields ?? autoChosenFields).length,\n 1\n ),\n };\n }),\n };\n }\n}\n\n// additional styling\n\n/*\n elements: {\n bar: {\n borderWidth: 2,\n },\n },\n\n */\n\nexport function prepOptions({ interactive = true, title }: BaseChartProps) {\n return [\n baseOptions,\n interactive\n ? {\n interaction: {\n mode: \"index\" as const,\n intersect: false,\n },\n events: undefined,\n }\n : {\n events: [],\n },\n title\n ? {\n plugins: {\n title: { display: true, text: title },\n },\n }\n : {},\n ];\n}\n\nexport const ChartAreaPlugin: Plugin = {\n id: \"chartAreaPlugin\",\n // eslint-disable-next-line object-shorthand\n beforeDraw: (chart) => {\n const chartAreaOptions = (chart.config.options as any).chartArea;\n if (chartAreaOptions && chartAreaOptions.backgroundColor) {\n const ctx = chart.canvas.getContext(\"2d\");\n const { chartArea } = chart;\n if (ctx) {\n ctx.save();\n ctx.fillStyle = chartAreaOptions.backgroundColor;\n // eslint-disable-next-line max-len\n ctx.fillRect(\n chartArea.left,\n chartArea.top,\n chartArea.right - chartArea.left,\n chartArea.bottom - chartArea.top\n );\n ctx.restore();\n }\n }\n },\n};\n","import {\n BarElement,\n CategoryScale,\n Chart as ChartJS,\n Legend,\n LinearScale,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Bar } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport const stackedOptions = {\n scales: {\n x: {\n stacked: true,\n ticks: {\n major: {\n enabled: false,\n },\n },\n },\n y: {\n stacked: true,\n },\n },\n};\n\nexport const vertOptions = {\n indexAxis: \"x\" as const,\n plugins: {\n legend: {\n position: \"top\" as const,\n },\n },\n};\nexport const horizOptions = {\n indexAxis: \"y\" as const,\n plugins: {\n legend: {\n position: \"right\" as const,\n },\n },\n};\n\nexport interface SimpleBarProps extends BaseChartProps {\n direction?: \"vertical\" | \"horizontal\";\n stacked?: boolean;\n}\n\nexport function SimpleBar(props: SimpleBarProps) {\n const { direction = \"vertical\", stacked, className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n CategoryScale,\n LinearScale,\n BarElement,\n Title,\n Tooltip,\n Legend\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, {\n preferNonNumericAsLabel: true,\n opacity: 1,\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Bar\n key={`${props.direction}${props.stacked}`}\n options={deepmerge.all([\n ...options,\n direction === \"vertical\" ? vertOptions : horizOptions,\n stacked ? stackedOptions : {},\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import {\n CategoryScale,\n Chart as ChartJS,\n Filler,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect, useState } from \"react\";\nimport { Line } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport interface SimpleLineProps extends BaseChartProps {\n fill?: boolean;\n secondAxisField?: string;\n}\n\n// Force a re-mount when the secondAxisField is unset / re-set\n// https://app.shortcut.com/plasmic/story/38358/chart-component-issues-with-second-axis-field\nconst useKey = (secondAxisField?: string) => {\n const [key, setKey] = useState(0);\n\n // change key once when the secondAxisField is unset.\n if (!secondAxisField && key) {\n setKey(0);\n }\n\n // change key once when the secondAxisField value changes from undefined -> something\n if (secondAxisField && !key) {\n setKey(Math.random());\n }\n\n return key;\n};\n\nexport function SimpleLine(props: SimpleLineProps) {\n const { secondAxisField, fill, className } = props;\n const isClient = useIsClient();\n const key = useKey(props.secondAxisField);\n\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n CategoryScale,\n LinearScale,\n PointElement,\n LineElement,\n Title,\n Tooltip,\n Filler,\n Legend\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, {\n extras: (field) => ({\n fill,\n pointRadius: 0,\n yAxisID: field === secondAxisField ? \"y1\" : \"y\",\n }),\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Line\n key={key}\n options={deepmerge.all([\n ...options,\n secondAxisField\n ? {\n scales: {\n y: {\n type: \"linear\" as const,\n display: true,\n position: \"left\" as const,\n },\n y1: {\n type: \"linear\" as const,\n display: true,\n position: \"right\" as const,\n grid: {\n drawOnChartArea: false,\n },\n },\n },\n }\n : {},\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import {\n Chart as ChartJS,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Scatter } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport type SimpleScatterProps = BaseChartProps;\n\nexport function SimpleScatter(props: SimpleScatterProps) {\n const { className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n LinearScale,\n PointElement,\n LineElement,\n Tooltip,\n Legend,\n Title\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, { isScatter: true, opacity: 1 });\n const options = prepOptions(props);\n\n return (\n <div className={className}>\n <Scatter\n options={deepmerge.all([\n ...options,\n {\n scales: {\n y: {\n beginAtZero: true,\n },\n },\n },\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import React, { ReactElement } from \"react\";\nimport { SimpleBar, SimpleBarProps } from \"../simple-bar/SimpleBar\";\nimport { SimpleLine, SimpleLineProps } from \"../simple-line/SimpleLine\";\nimport {\n SimpleScatter,\n SimpleScatterProps,\n} from \"../simple-scatter/SimpleScatter\";\n\nexport type SimpleChartProps = {\n type?: \"bar\" | \"line\" | \"scatter\";\n} & (SimpleBarProps | SimpleLineProps | SimpleScatterProps);\n\nexport function SimpleChart(props: SimpleChartProps): ReactElement {\n switch (props.type ?? \"bar\") {\n case \"bar\":\n return <SimpleBar {...(props as any)} />;\n case \"line\":\n return <SimpleLine {...(props as any)} />;\n case \"scatter\":\n return <SimpleScatter {...(props as any)} />;\n }\n}\n","import {\n CodeComponentMeta,\n PropType,\n} from \"@plasmicapp/host/registerComponent\";\nimport { Registerable, registerComponentHelper } from \"../utils\";\nimport { SimpleChart, SimpleChartProps } from \"./SimpleChart\";\n\nexport * from \"./SimpleChart\";\nexport default SimpleChart;\n\nconst fieldChoice: PropType<SimpleChartProps> = {\n type: \"choice\",\n options: (props: SimpleChartProps) =>\n props.data?.[0] ? Object.keys(props.data[0]) : [],\n} as const;\nconst simpleChartMeta: CodeComponentMeta<SimpleChartProps> = {\n name: \"hostless-react-chartjs-2-simple-chart\",\n displayName: \"Chart\",\n props: {\n type: {\n type: \"choice\",\n options: [\n {\n value: \"bar\",\n label: \"Bar\",\n },\n {\n value: \"line\",\n label: \"Line\",\n },\n {\n value: \"scatter\",\n label: \"Scatter\",\n },\n ],\n defaultValueHint: \"bar\",\n },\n data: {\n type: \"exprEditor\",\n description: \"The data as an array of objects\",\n defaultExpr: JSON.stringify([\n {\n region: \"APAC\",\n revenue: 3294,\n spend: 2675,\n },\n {\n region: \"EMEA\",\n revenue: 3245,\n spend: 3895,\n },\n {\n region: \"LATAM\",\n revenue: 2165,\n spend: 3498,\n },\n {\n region: \"AMER\",\n revenue: 3215,\n spend: 1656,\n },\n ]),\n },\n labelField: {\n ...fieldChoice,\n hidden: (props) => props.type === \"scatter\",\n },\n title: \"string\",\n interactive: {\n type: \"boolean\",\n defaultValueHint: true,\n },\n // Bar chart\n direction: {\n type: \"choice\",\n options: [\"horizontal\", \"vertical\"].map((dir) => ({\n value: dir,\n label: dir[0].toUpperCase() + dir.slice(1),\n })),\n defaultValueHint: \"Vertical\",\n hidden: ({ type = \"bar\" }) => type !== \"bar\",\n },\n stacked: {\n type: \"boolean\",\n hidden: ({ type = \"bar\" }) => type !== \"bar\",\n },\n // Line chart\n fill: {\n type: \"boolean\",\n hidden: (props) => props.type !== \"line\",\n },\n secondAxisField: {\n ...fieldChoice,\n hidden: (props) => props.type !== \"line\",\n },\n\n // TODO\n // datasets: {\n // type: \"array\",\n // unstable__keyFunc: (x) => x.key,\n // unstable__minimalValue: (_props, ctx) => null,\n // itemType: {\n // type: \"object\",\n // fields: {\n // label: \"string\",\n // fieldId: \"string\",\n // hidden: {\n // type: \"boolean\",\n // },\n // },\n // },\n // },\n },\n\n defaultStyles: {\n width: \"stretch\",\n },\n\n importName: \"SimpleChart\",\n importPath: \"@plasmicpkgs/react-chartjs-2\",\n};\n\nexport function registerSimpleChart(loader?: Registerable) {\n registerComponentHelper(loader, SimpleChart, simpleChartMeta);\n}\n","import { registerSimpleChart } from \"./simple-chart\";\nimport { Registerable } from \"./utils\";\n\nexport { SimpleChart } from \"./simple-chart\";\n\nexport function registerAll(loader?: Registerable) {\n registerSimpleChart(loader);\n}\n"],"names":["registerComponentHelper","loader","component","meta","registerComponent","baseOptions","responsive","chartArea","defaultColors","useIsClient","_useState","useState","loaded","setLoaded","useEffect","range","total","Array","from","keys","getDefaultColor","index","opacity","preferredStart","end","length","start","Math","max","min","stops","map","_","i","round","selected","undefined","replace","prepData","_ref","_temp","data","_ref$data","labelField","chosenFields","scatterSeries","_ref2","isScatter","preferNonNumericAsLabel","extras","fields","Object","_data$","isFieldAllNumericOrNil","Map","key","every","item","_item$key","isNaN","realLabelField","find","field","get","numericFields","filter","name","datasets","series","_extends","label","_item$series$fields$","_item$series$fields$2","x","y","backgroundColor","autoChosenFields","labels","_item$key2","borderWidth","borderColor","prepOptions","_ref3","interactive","_ref3$interactive","title","interaction","mode","intersect","events","plugins","display","text","ChartAreaPlugin","id","beforeDraw","chart","chartAreaOptions","config","options","ctx","canvas","getContext","save","fillStyle","fillRect","left","top","right","bottom","restore","stackedOptions","scales","stacked","ticks","major","enabled","vertOptions","indexAxis","legend","position","horizOptions","SimpleBar","props","_props$direction","direction","className","isClient","ChartJS","register","CategoryScale","LinearScale","BarElement","Title","Tooltip","Legend","normalized","React","Bar","deepmerge","all","concat","useKey","secondAxisField","setKey","random","SimpleLine","fill","PointElement","LineElement","Filler","pointRadius","yAxisID","Line","type","y1","grid","drawOnChartArea","SimpleScatter","Scatter","beginAtZero","SimpleChart","_props$type","fieldChoice","_props$data","simpleChartMeta","displayName","value","defaultValueHint","description","defaultExpr","JSON","stringify","region","revenue","spend","hidden","dir","toUpperCase","slice","_ref$type","_ref2$type","defaultStyles","width","importName","importPath","registerSimpleChart","registerAll"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;SAuCgBA,uBAAuBA,CACrCC,MAAgC,EAChCC,SAAY,EACZC,IAAgD;EAEhD,IAAIF,MAAM,EAAE;IACVA,MAAM,CAACG,iBAAiB,CAACF,SAAS,EAAEC,IAAI,CAAC;GAC1C,MAAM;IACLC,iBAAiB,CAACF,SAAS,EAAEC,IAAI,CAAC;;AAEtC;;AC9CO,IAAME,WAAW,GAAG;EACzBC,UAAU,EAAE,IAAI;EAChBC,SAAS,EAAE;;;CAGZ;AAED;;;AAGA,AAAO,IAAMC,aAAa,GAAG,CAC3B,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,CACxB;AAED,SAAgBC,WAAWA;EACzB,IAAAC,SAAA,GAA4BC,cAAQ,CAAC,KAAK,CAAC;IAApCC,MAAM,GAAAF,SAAA;IAAEG,SAAS,GA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,2 @@
|
|
|
1
|
-
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("@plasmicapp/host/registerComponent"));require("@plasmicapp/host/registerGlobalContext");var
|
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("@plasmicapp/host/registerComponent"));require("@plasmicapp/host/registerGlobalContext");var r=require("react"),n=e(r),a=require("chart.js"),i=e(require("deepmerge")),l=require("react-chartjs-2");function o(){return(o=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(null,arguments)}var s={responsive:!0,chartArea:{}},c=["hsla(25,95%,53%,1.0)","hsla(38,92%,50%,1.0)","hsla(45,93%,47%,1.0)","hsla(84,81%,44%,1.0)","hsla(142,71%,45%,1.0)","hsla(160,84%,39%,1.0)","hsla(173,80%,40%,1.0)","hsla(199,89%,48%,1.0)","hsla(217,91%,60%,1.0)","hsla(239,84%,67%,1.0)","hsla(258,90%,66%,1.0)","hsla(271,91%,65%,1.0)","hsla(292,84%,61%,1.0)","hsla(293,69%,49%,1.0)","hsla(295,72%,40%,1.0)","hsla(295,70%,33%,1.0)"];function u(){var e=r.useState(!1),t=e[0],n=e[1];return r.useEffect((function(){n(!0)})),t}function d(e){return Array.from(Array(e).keys())}function p(e,t,r){var n=c.length-1,a=Math.max(0,Math.min(9,n-t)),i=t>c.length?d(c.length):d(t).map((function(e,r){return Math.round(a+(t>1?1*r/(t-1)*(n-a):0))})),l=c[i[e%i.length]];return void 0===r?l:l.replace("1.0",""+r)}function f(e,t){var r,n=e.data,a=void 0===n?[]:n,i=e.labelField,l=e.chosenFields,s=e.scatterSeries,c=void 0===t?{}:t,u=c.isScatter,d=c.preferNonNumericAsLabel,f=c.extras,h=c.opacity,v=Object.keys(null!=(r=a[0])?r:{}),m=new Map(v.map((function(e){return[e,a.every((function(t){var r;return!isNaN(null!=(r=t[e])?r:0)}))]}))),y=null!=i?i:d?v.find((function(e){return!m.get(e)})):v[0],g=v.filter((function(e){return m.get(e)}));if(u)return{datasets:(null!=(s=u?null!=s?s:[{name:g[0]+"-"+g[1],fields:[g[0],g[1]]}]:void 0)?s:[]).map((function(e,t){return o({},null==f?void 0:f(e.name),{label:e.name,data:a.map((function(t){var r,n;return{x:null!=(r=t[e.fields[0]])?r:0,y:null!=(n=t[e.fields[1]])?n:0}})),backgroundColor:p(t,(null!=s?s:[]).length,h)})}))};var b=g.filter((function(e){return e!==y}));return{labels:y?a.map((function(e){return e[y]})):void 0,datasets:(null!=l?l:b).map((function(e,t){return o({},null==f?void 0:f(e),{label:e,data:a.map((function(t){var r;return null!=(r=t[e])?r:0})),backgroundColor:p(t,(null!=l?l:b).length,1),borderWidth:2,borderColor:p(t,(null!=l?l:b).length,1)})}))}}function h(e){var t=e.interactive,r=e.title;return[s,void 0===t||t?{interaction:{mode:"index",intersect:!1},events:void 0}:{events:[]},r?{plugins:{title:{display:!0,text:r}}}:{}]}var v={id:"chartAreaPlugin",beforeDraw:function(e){var t=e.config.options.chartArea;if(t&&t.backgroundColor){var r=e.canvas.getContext("2d"),n=e.chartArea;r&&(r.save(),r.fillStyle=t.backgroundColor,r.fillRect(n.left,n.top,n.right-n.left,n.bottom-n.top),r.restore())}}},m={scales:{x:{stacked:!0,ticks:{major:{enabled:!1}}},y:{stacked:!0}}},y={indexAxis:"x",plugins:{legend:{position:"top"}}},g={indexAxis:"y",plugins:{legend:{position:"right"}}};function b(e){var t=e.direction,o=void 0===t?"vertical":t,s=e.stacked,c=e.className,d=u();if(r.useEffect((function(){a.Chart.register(v,a.CategoryScale,a.LinearScale,a.BarElement,a.Title,a.Tooltip,a.Legend)}),[]),!d)return null;var p=f(e,{preferNonNumericAsLabel:!0,opacity:1}),b=h(e);return n.createElement("div",{className:c},n.createElement(l.Bar,{key:""+e.direction+e.stacked,options:i.all([].concat(b,["vertical"===o?y:g,s?m:{}])),data:p}))}function x(e){var t=e.secondAxisField,o=e.fill,s=e.className,c=u(),d=function(e){var t=r.useState(0),n=t[0],a=t[1];return!e&&n&&a(0),e&&!n&&a(Math.random()),n}(e.secondAxisField);if(r.useEffect((function(){a.Chart.register(v,a.CategoryScale,a.LinearScale,a.PointElement,a.LineElement,a.Title,a.Tooltip,a.Filler,a.Legend)}),[]),!c)return null;var p=f(e,{extras:function(e){return{fill:o,pointRadius:0,yAxisID:e===t?"y1":"y"}}}),m=h(e);return n.createElement("div",{className:s},n.createElement(l.Line,{key:d,options:i.all([].concat(m,[t?{scales:{y:{type:"linear",display:!0,position:"left"},y1:{type:"linear",display:!0,position:"right",grid:{drawOnChartArea:!1}}}}:{}])),data:p}))}function A(e){var t=e.className,o=u();if(r.useEffect((function(){a.Chart.register(v,a.LinearScale,a.PointElement,a.LineElement,a.Tooltip,a.Legend,a.Title)}),[]),!o)return null;var s=f(e,{isScatter:!0,opacity:1}),c=h(e);return n.createElement("div",{className:t},n.createElement(l.Scatter,{options:i.all([].concat(c,[{scales:{y:{beginAtZero:!0}}}])),data:s}))}function E(e){var t;switch(null!=(t=e.type)?t:"bar"){case"bar":return n.createElement(b,o({},e));case"line":return n.createElement(x,o({},e));case"scatter":return n.createElement(A,o({},e))}}var C={type:"choice",options:function(e){var t;return null!=(t=e.data)&&t[0]?Object.keys(e.data[0]):[]}},S={name:"hostless-react-chartjs-2-simple-chart",displayName:"Chart",props:{type:{type:"choice",options:[{value:"bar",label:"Bar"},{value:"line",label:"Line"},{value:"scatter",label:"Scatter"}],defaultValueHint:"bar"},data:{type:"exprEditor",description:"The data as an array of objects",defaultExpr:JSON.stringify([{region:"APAC",revenue:3294,spend:2675},{region:"EMEA",revenue:3245,spend:3895},{region:"LATAM",revenue:2165,spend:3498},{region:"AMER",revenue:3215,spend:1656}])},labelField:o({},C,{hidden:function(e){return"scatter"===e.type}}),title:"string",interactive:{type:"boolean",defaultValueHint:!0},direction:{type:"choice",options:["horizontal","vertical"].map((function(e){return{value:e,label:e[0].toUpperCase()+e.slice(1)}})),defaultValueHint:"Vertical",hidden:function(e){var t=e.type;return"bar"!==(void 0===t?"bar":t)}},stacked:{type:"boolean",hidden:function(e){var t=e.type;return"bar"!==(void 0===t?"bar":t)}},fill:{type:"boolean",hidden:function(e){return"line"!==e.type}},secondAxisField:o({},C,{hidden:function(e){return"line"!==e.type}})},defaultStyles:{width:"stretch"},importName:"SimpleChart",importPath:"@plasmicpkgs/react-chartjs-2"};exports.SimpleChart=E,exports.registerAll=function(e){!function(e){!function(e,r,n){e?e.registerComponent(r,n):t(r,n)}(e,E,S)}(e)};
|
|
2
2
|
//# sourceMappingURL=react-chartjs-2.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-chartjs-2.cjs.production.min.js","sources":["../src/common.ts","../src/simple-bar/SimpleBar.tsx","../src/simple-line/SimpleLine.tsx","../src/simple-scatter/SimpleScatter.tsx","../src/simple-chart/SimpleChart.tsx","../src/simple-chart/index.tsx","../src/index.tsx","../src/utils.ts"],"sourcesContent":["import { Plugin } from \"chart.js/dist/types\";\nimport { useEffect, useState } from \"react\";\n\nexport const baseOptions = {\n responsive: true,\n chartArea: {\n // backgroundColor: \"#f8fafc\",\n },\n};\n\n/**\n * These are hand-picked from the Tailwind palette.\n */\nexport const defaultColors = [\n \"hsla(25,95%,53%,1.0)\",\n \"hsla(38,92%,50%,1.0)\",\n \"hsla(45,93%,47%,1.0)\",\n \"hsla(84,81%,44%,1.0)\",\n \"hsla(142,71%,45%,1.0)\",\n \"hsla(160,84%,39%,1.0)\",\n \"hsla(173,80%,40%,1.0)\",\n \"hsla(199,89%,48%,1.0)\",\n \"hsla(217,91%,60%,1.0)\",\n \"hsla(239,84%,67%,1.0)\",\n \"hsla(258,90%,66%,1.0)\",\n \"hsla(271,91%,65%,1.0)\",\n \"hsla(292,84%,61%,1.0)\",\n \"hsla(293,69%,49%,1.0)\",\n \"hsla(295,72%,40%,1.0)\",\n \"hsla(295,70%,33%,1.0)\",\n];\n\nexport function useIsClient() {\n const [loaded, setLoaded] = useState(false);\n useEffect(() => {\n setLoaded(true);\n });\n return loaded;\n}\n\nexport interface BaseChartProps {\n className?: string;\n data?: Record<string, any>[];\n labelField?: string;\n interactive?: boolean;\n title?: string;\n chosenFields?: string[];\n scatterSeries?: { name: string; fields: [string, string] }[];\n}\n\nexport interface PrepDataOpts {\n isScatter?: boolean;\n preferNonNumericAsLabel?: boolean;\n extras?: (field: string) => {};\n opacity?: number;\n}\n\nfunction range(total: number) {\n return Array.from(Array(total).keys());\n}\n\n/**\n * Returns a color from the default color palette.\n *\n * Tries to pick \"different\" colors that are somewhat spread out on the palette. With a higher 'total' colors requested, the colors will be packed more closely together.\n *\n * We prefer starting from blue when possible. This only starts getting pushed down toward yellow if too many colors requested.\n *\n * If too many colors are requested, it will recycle.\n */\nexport function getDefaultColor(\n index: number,\n total: number,\n opacity?: number\n) {\n const preferredStart = 9;\n const end = defaultColors.length - 1;\n const start = Math.max(0, Math.min(preferredStart, end - total));\n const stops =\n total > defaultColors.length\n ? range(defaultColors.length)\n : range(total).map((_, i) =>\n Math.round(\n start + (total > 1 ? ((1.0 * i) / (total - 1)) * (end - start) : 0)\n )\n );\n const selected = defaultColors[stops[index % stops.length]];\n if (opacity === undefined) {\n return selected;\n }\n return selected.replace(\"1.0\", \"\" + opacity);\n}\n\nexport function prepData(\n { data = [], labelField, chosenFields, scatterSeries }: BaseChartProps,\n { isScatter, preferNonNumericAsLabel, extras, opacity }: PrepDataOpts = {}\n) {\n const fields = Object.keys(data[0] ?? {});\n const isFieldAllNumericOrNil = new Map(\n fields.map((key) => [key, data.every((item) => !isNaN(item[key] ?? 0))])\n );\n const realLabelField =\n labelField ??\n (preferNonNumericAsLabel\n ? fields.find((field) => !isFieldAllNumericOrNil.get(field))\n : fields[0]);\n const numericFields = fields.filter((field) =>\n isFieldAllNumericOrNil.get(field)\n );\n if (isScatter) {\n scatterSeries = isScatter\n ? scatterSeries ?? [\n {\n name: `${numericFields[0]}-${numericFields[1]}`,\n fields: [numericFields[0], numericFields[1]] as [string, string],\n },\n ]\n : undefined;\n return {\n datasets: (scatterSeries ?? []).map((series, index) => ({\n ...extras?.(series.name),\n label: series.name,\n data: data.map((item) => ({\n x: item[series.fields[0]] ?? 0,\n y: item[series.fields[1]] ?? 0,\n })),\n backgroundColor: getDefaultColor(\n index,\n (scatterSeries ?? []).length,\n opacity\n ),\n })),\n };\n } else {\n const autoChosenFields = numericFields.filter(\n (field) => field !== realLabelField\n );\n return {\n labels: realLabelField\n ? data.map((item) => item[realLabelField])\n : undefined,\n datasets: (chosenFields ?? autoChosenFields).map((key, index) => {\n return {\n ...extras?.(key),\n label: key,\n data: data.map((item) => item[key] ?? 0),\n backgroundColor: getDefaultColor(\n index,\n (chosenFields ?? autoChosenFields).length,\n 1\n ),\n borderWidth: 2,\n borderColor: getDefaultColor(\n index,\n (chosenFields ?? autoChosenFields).length,\n 1\n ),\n };\n }),\n };\n }\n}\n\n// additional styling\n\n/*\n elements: {\n bar: {\n borderWidth: 2,\n },\n },\n\n */\n\nexport function prepOptions({ interactive = true, title }: BaseChartProps) {\n return [\n baseOptions,\n interactive\n ? {\n interaction: {\n mode: \"index\" as const,\n intersect: false,\n },\n events: undefined,\n }\n : {\n events: [],\n },\n title\n ? {\n plugins: {\n title: { display: true, text: title },\n },\n }\n : {},\n ];\n}\n\nexport const ChartAreaPlugin: Plugin = {\n id: \"chartAreaPlugin\",\n // eslint-disable-next-line object-shorthand\n beforeDraw: (chart) => {\n const chartAreaOptions = (chart.config.options as any).chartArea;\n if (chartAreaOptions && chartAreaOptions.backgroundColor) {\n const ctx = chart.canvas.getContext(\"2d\");\n const { chartArea } = chart;\n if (ctx) {\n ctx.save();\n ctx.fillStyle = chartAreaOptions.backgroundColor;\n // eslint-disable-next-line max-len\n ctx.fillRect(\n chartArea.left,\n chartArea.top,\n chartArea.right - chartArea.left,\n chartArea.bottom - chartArea.top\n );\n ctx.restore();\n }\n }\n },\n};\n","import {\n BarElement,\n CategoryScale,\n Chart as ChartJS,\n Legend,\n LinearScale,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Bar } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport const stackedOptions = {\n scales: {\n x: {\n stacked: true,\n ticks: {\n major: {\n enabled: false,\n },\n },\n },\n y: {\n stacked: true,\n },\n },\n};\n\nexport const vertOptions = {\n indexAxis: \"x\" as const,\n plugins: {\n legend: {\n position: \"top\" as const,\n },\n },\n};\nexport const horizOptions = {\n indexAxis: \"y\" as const,\n plugins: {\n legend: {\n position: \"right\" as const,\n },\n },\n};\n\nexport interface SimpleBarProps extends BaseChartProps {\n direction?: \"vertical\" | \"horizontal\";\n stacked?: boolean;\n}\n\nexport function SimpleBar(props: SimpleBarProps) {\n const { direction = \"vertical\", stacked, className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n CategoryScale,\n LinearScale,\n BarElement,\n Title,\n Tooltip,\n Legend\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, {\n preferNonNumericAsLabel: true,\n opacity: 1,\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Bar\n key={`${props.direction}${props.stacked}`}\n options={deepmerge.all([\n ...options,\n direction === \"vertical\" ? vertOptions : horizOptions,\n stacked ? stackedOptions : {},\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import {\n CategoryScale,\n Chart as ChartJS,\n Filler,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect, useState } from \"react\";\nimport { Line } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport interface SimpleLineProps extends BaseChartProps {\n fill?: boolean;\n secondAxisField?: string;\n}\n\n// Force a re-mount when the secondAxisField is unset / re-set\n// https://app.shortcut.com/plasmic/story/38358/chart-component-issues-with-second-axis-field\nconst useKey = (secondAxisField?: string) => {\n const [key, setKey] = useState(0);\n\n // change key once when the secondAxisField is unset.\n if (!secondAxisField && key) {\n setKey(0);\n }\n\n // change key once when the secondAxisField value changes from undefined -> something\n if (secondAxisField && !key) {\n setKey(Math.random());\n }\n\n return key;\n};\n\nexport function SimpleLine(props: SimpleLineProps) {\n const { secondAxisField, fill, className } = props;\n const isClient = useIsClient();\n const key = useKey(props.secondAxisField);\n\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n CategoryScale,\n LinearScale,\n PointElement,\n LineElement,\n Title,\n Tooltip,\n Filler,\n Legend\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, {\n extras: (field) => ({\n fill,\n pointRadius: 0,\n yAxisID: field === secondAxisField ? \"y1\" : \"y\",\n }),\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Line\n key={key}\n options={deepmerge.all([\n ...options,\n secondAxisField\n ? {\n scales: {\n y: {\n type: \"linear\" as const,\n display: true,\n position: \"left\" as const,\n },\n y1: {\n type: \"linear\" as const,\n display: true,\n position: \"right\" as const,\n grid: {\n drawOnChartArea: false,\n },\n },\n },\n }\n : {},\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import {\n Chart as ChartJS,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Scatter } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport type SimpleScatterProps = BaseChartProps;\n\nexport function SimpleScatter(props: SimpleScatterProps) {\n const { className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n LinearScale,\n PointElement,\n LineElement,\n Tooltip,\n Legend,\n Title\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, { isScatter: true, opacity: 1 });\n const options = prepOptions(props);\n\n return (\n <div className={className}>\n <Scatter\n options={deepmerge.all([\n ...options,\n {\n scales: {\n y: {\n beginAtZero: true,\n },\n },\n },\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import React, { ReactElement } from \"react\";\nimport { SimpleBar, SimpleBarProps } from \"../simple-bar/SimpleBar\";\nimport { SimpleLine, SimpleLineProps } from \"../simple-line/SimpleLine\";\nimport {\n SimpleScatter,\n SimpleScatterProps,\n} from \"../simple-scatter/SimpleScatter\";\n\nexport type SimpleChartProps = {\n type?: \"bar\" | \"line\" | \"scatter\";\n} & (SimpleBarProps | SimpleLineProps | SimpleScatterProps);\n\nexport function SimpleChart(props: SimpleChartProps): ReactElement {\n switch (props.type ?? \"bar\") {\n case \"bar\":\n return <SimpleBar {...(props as any)} />;\n case \"line\":\n return <SimpleLine {...(props as any)} />;\n case \"scatter\":\n return <SimpleScatter {...(props as any)} />;\n }\n}\n","import {\n CodeComponentMeta,\n PropType,\n} from \"@plasmicapp/host/registerComponent\";\nimport { Registerable, registerComponentHelper } from \"../utils\";\nimport { SimpleChart, SimpleChartProps } from \"./SimpleChart\";\n\nexport * from \"./SimpleChart\";\nexport default SimpleChart;\n\nconst fieldChoice: PropType<SimpleChartProps> = {\n type: \"choice\",\n options: (props: SimpleChartProps) =>\n props.data?.[0] ? Object.keys(props.data[0]) : [],\n} as const;\nconst simpleChartMeta: CodeComponentMeta<SimpleChartProps> = {\n name: \"hostless-react-chartjs-2-simple-chart\",\n displayName: \"Chart\",\n props: {\n type: {\n type: \"choice\",\n options: [\n {\n value: \"bar\",\n label: \"Bar\",\n },\n {\n value: \"line\",\n label: \"Line\",\n },\n {\n value: \"scatter\",\n label: \"Scatter\",\n },\n ],\n defaultValueHint: \"bar\",\n },\n data: {\n type: \"exprEditor\",\n description: \"The data as an array of objects\",\n defaultExpr: JSON.stringify([\n {\n region: \"APAC\",\n revenue: 3294,\n spend: 2675,\n },\n {\n region: \"EMEA\",\n revenue: 3245,\n spend: 3895,\n },\n {\n region: \"LATAM\",\n revenue: 2165,\n spend: 3498,\n },\n {\n region: \"AMER\",\n revenue: 3215,\n spend: 1656,\n },\n ]),\n },\n labelField: {\n ...fieldChoice,\n hidden: (props) => props.type === \"scatter\",\n },\n title: \"string\",\n interactive: {\n type: \"boolean\",\n defaultValueHint: true,\n },\n // Bar chart\n direction: {\n type: \"choice\",\n options: [\"horizontal\", \"vertical\"].map((dir) => ({\n value: dir,\n label: dir[0].toUpperCase() + dir.slice(1),\n })),\n defaultValueHint: \"Vertical\",\n hidden: ({ type = \"bar\" }) => type !== \"bar\",\n },\n stacked: {\n type: \"boolean\",\n hidden: ({ type = \"bar\" }) => type !== \"bar\",\n },\n // Line chart\n fill: {\n type: \"boolean\",\n hidden: (props) => props.type !== \"line\",\n },\n secondAxisField: {\n ...fieldChoice,\n hidden: (props) => props.type !== \"line\",\n },\n\n // TODO\n // datasets: {\n // type: \"array\",\n // unstable__keyFunc: (x) => x.key,\n // unstable__minimalValue: (_props, ctx) => null,\n // itemType: {\n // type: \"object\",\n // fields: {\n // label: \"string\",\n // fieldId: \"string\",\n // hidden: {\n // type: \"boolean\",\n // },\n // },\n // },\n // },\n },\n\n defaultStyles: {\n width: \"stretch\",\n },\n\n importName: \"SimpleChart\",\n importPath: \"@plasmicpkgs/react-chartjs-2\",\n};\n\nexport function registerSimpleChart(loader?: Registerable) {\n registerComponentHelper(loader, SimpleChart, simpleChartMeta);\n}\n","import { registerSimpleChart } from \"./simple-chart\";\nimport { Registerable } from \"./utils\";\n\nexport { SimpleChart } from \"./simple-chart\";\n\nexport function registerAll(loader?: Registerable) {\n registerSimpleChart(loader);\n}\n","import {\n CodeComponentMeta,\n default as registerComponent,\n} from \"@plasmicapp/host/registerComponent\";\nimport {\n GlobalContextMeta,\n default as registerGlobalContext,\n} from \"@plasmicapp/host/registerGlobalContext\";\nimport { default as registerToken } from \"@plasmicapp/host/registerToken\";\nimport React from \"react\";\n\nexport type Registerable = {\n registerComponent: typeof registerComponent;\n registerGlobalContext: typeof registerGlobalContext;\n registerToken: typeof registerToken;\n};\n\nexport function makeRegisterComponent<T extends React.ComponentType<any>>(\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n return function (loader?: Registerable) {\n registerComponentHelper(loader, component, meta);\n };\n}\n\nexport function makeRegisterGlobalContext<T extends React.ComponentType<any>>(\n component: T,\n meta: GlobalContextMeta<React.ComponentProps<T>>\n) {\n return function (loader?: Registerable) {\n if (loader) {\n loader.registerGlobalContext(component, meta);\n } else {\n registerGlobalContext(component, meta);\n }\n };\n}\n\nexport function registerComponentHelper<T extends React.ComponentType<any>>(\n loader: Registerable | undefined,\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n if (loader) {\n loader.registerComponent(component, meta);\n } else {\n registerComponent(component, meta);\n }\n}\n\ntype ReactElt = {\n children: ReactElt | ReactElt[];\n props: {\n children: ReactElt | ReactElt[];\n [prop: string]: any;\n } | null;\n type: React.ComponentType<any> | null;\n key: string | null;\n} | null;\n\nexport function traverseReactEltTree(\n children: React.ReactNode,\n callback: (elt: ReactElt) => void\n) {\n const rec = (elts: ReactElt | ReactElt[] | null) => {\n (Array.isArray(elts) ? elts : [elts]).forEach((elt) => {\n if (elt) {\n callback(elt);\n if (elt.children) {\n rec(elt.children);\n }\n if (elt.props?.children && elt.props.children !== elt.children) {\n rec(elt.props.children);\n }\n }\n });\n };\n rec(children as any);\n}\n\nexport function asArray<T>(x: T[] | T | undefined | null) {\n if (Array.isArray(x)) {\n return x;\n } else if (x == null) {\n return [];\n } else {\n return [x];\n }\n}\n"],"names":["baseOptions","responsive","chartArea","defaultColors","useIsClient","_useState","useState","loaded","setLoaded","useEffect","range","total","Array","from","keys","getDefaultColor","index","opacity","end","length","start","Math","max","min","stops","map","_","i","round","selected","undefined","replace","prepData","_ref","_temp","data","_ref$data","labelField","chosenFields","scatterSeries","_ref2","isScatter","preferNonNumericAsLabel","extras","fields","Object","_data$","isFieldAllNumericOrNil","Map","key","every","item","_item$key","isNaN","realLabelField","find","field","get","numericFields","filter","datasets","name","series","_extends","label","_item$series$fields$","_item$series$fields$2","x","y","backgroundColor","autoChosenFields","labels","_item$key2","borderWidth","borderColor","prepOptions","_ref3","interactive","title","_ref3$interactive","interaction","mode","intersect","events","plugins","display","text","ChartAreaPlugin","id","beforeDraw","chart","chartAreaOptions","config","options","ctx","canvas","getContext","save","fillStyle","fillRect","left","top","right","bottom","restore","stackedOptions","scales","stacked","ticks","major","enabled","vertOptions","indexAxis","legend","position","horizOptions","SimpleBar","props","_props$direction","direction","className","isClient","ChartJS","register","CategoryScale","LinearScale","BarElement","Title","Tooltip","Legend","normalized","React","Bar","deepmerge","all","concat","SimpleLine","secondAxisField","fill","setKey","random","useKey","PointElement","LineElement","Filler","pointRadius","yAxisID","Line","type","y1","grid","drawOnChartArea","SimpleScatter","Scatter","beginAtZero","SimpleChart","_props$type","fieldChoice","_props$data","simpleChartMeta","displayName","value","defaultValueHint","description","defaultExpr","JSON","stringify","region","revenue","spend","hidden","dir","toUpperCase","slice","_ref$type","_ref2$type","defaultStyles","width","importName","importPath","loader","component","meta","registerComponent","registerComponentHelper","registerSimpleChart"],"mappings":"qjBAGO,IAAMA,EAAc,CACzBC,YAAY,EACZC,UAAW,IAQAC,EAAgB,CAC3B,uBACA,uBACA,uBACA,uBACA,wBACA,wBACA,wBACA,wBACA,wBACA,wBACA,wBACA,wBACA,wBACA,wBACA,wBACA,yBAGF,SAAgBC,IACd,IAAAC,EAA4BC,YAAS,GAA9BC,EAAMF,KAAEG,EAASH,KAIxB,OAHAI,aAAU,WACRD,GAAU,MAELD,EAoBT,SAASG,EAAMC,GACb,OAAOC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MAAoB,SAAfA,EAAM+B,SAqB7B4B,cAAe,CACbC,MAAO,WAGTC,WAAY,cACZC,WAAY,mFClHcC,aDqHQA,aElFlCA,EACAC,EACAC,GAEIF,EACFA,EAAOG,kBAAkBF,EAAWC,GAEpCC,EAAkBF,EAAWC,GF4E/BE,CAAwBJ,EAAQzB,EAAaI,GCrH7C0B,CAAoBL"}
|
|
1
|
+
{"version":3,"file":"react-chartjs-2.cjs.production.min.js","sources":["../src/common.ts","../src/simple-bar/SimpleBar.tsx","../src/simple-line/SimpleLine.tsx","../src/simple-scatter/SimpleScatter.tsx","../src/simple-chart/SimpleChart.tsx","../src/simple-chart/index.tsx","../src/index.tsx","../src/utils.ts"],"sourcesContent":["import { Plugin } from \"chart.js/dist/types\";\nimport { useEffect, useState } from \"react\";\n\nexport const baseOptions = {\n responsive: true,\n chartArea: {\n // backgroundColor: \"#f8fafc\",\n },\n};\n\n/**\n * These are hand-picked from the Tailwind palette.\n */\nexport const defaultColors = [\n \"hsla(25,95%,53%,1.0)\",\n \"hsla(38,92%,50%,1.0)\",\n \"hsla(45,93%,47%,1.0)\",\n \"hsla(84,81%,44%,1.0)\",\n \"hsla(142,71%,45%,1.0)\",\n \"hsla(160,84%,39%,1.0)\",\n \"hsla(173,80%,40%,1.0)\",\n \"hsla(199,89%,48%,1.0)\",\n \"hsla(217,91%,60%,1.0)\",\n \"hsla(239,84%,67%,1.0)\",\n \"hsla(258,90%,66%,1.0)\",\n \"hsla(271,91%,65%,1.0)\",\n \"hsla(292,84%,61%,1.0)\",\n \"hsla(293,69%,49%,1.0)\",\n \"hsla(295,72%,40%,1.0)\",\n \"hsla(295,70%,33%,1.0)\",\n];\n\nexport function useIsClient() {\n const [loaded, setLoaded] = useState(false);\n useEffect(() => {\n setLoaded(true);\n });\n return loaded;\n}\n\nexport interface BaseChartProps {\n className?: string;\n data?: Record<string, any>[];\n labelField?: string;\n interactive?: boolean;\n title?: string;\n chosenFields?: string[];\n scatterSeries?: { name: string; fields: [string, string] }[];\n}\n\nexport interface PrepDataOpts {\n isScatter?: boolean;\n preferNonNumericAsLabel?: boolean;\n extras?: (field: string) => {};\n opacity?: number;\n}\n\nfunction range(total: number) {\n return Array.from(Array(total).keys());\n}\n\n/**\n * Returns a color from the default color palette.\n *\n * Tries to pick \"different\" colors that are somewhat spread out on the palette. With a higher 'total' colors requested, the colors will be packed more closely together.\n *\n * We prefer starting from blue when possible. This only starts getting pushed down toward yellow if too many colors requested.\n *\n * If too many colors are requested, it will recycle.\n */\nexport function getDefaultColor(\n index: number,\n total: number,\n opacity?: number\n) {\n const preferredStart = 9;\n const end = defaultColors.length - 1;\n const start = Math.max(0, Math.min(preferredStart, end - total));\n const stops =\n total > defaultColors.length\n ? range(defaultColors.length)\n : range(total).map((_, i) =>\n Math.round(\n start + (total > 1 ? ((1.0 * i) / (total - 1)) * (end - start) : 0)\n )\n );\n const selected = defaultColors[stops[index % stops.length]];\n if (opacity === undefined) {\n return selected;\n }\n return selected.replace(\"1.0\", \"\" + opacity);\n}\n\nexport function prepData(\n { data = [], labelField, chosenFields, scatterSeries }: BaseChartProps,\n { isScatter, preferNonNumericAsLabel, extras, opacity }: PrepDataOpts = {}\n) {\n const fields = Object.keys(data[0] ?? {});\n const isFieldAllNumericOrNil = new Map(\n fields.map((key) => [key, data.every((item) => !isNaN(item[key] ?? 0))])\n );\n const realLabelField =\n labelField ??\n (preferNonNumericAsLabel\n ? fields.find((field) => !isFieldAllNumericOrNil.get(field))\n : fields[0]);\n const numericFields = fields.filter((field) =>\n isFieldAllNumericOrNil.get(field)\n );\n if (isScatter) {\n scatterSeries = isScatter\n ? scatterSeries ?? [\n {\n name: `${numericFields[0]}-${numericFields[1]}`,\n fields: [numericFields[0], numericFields[1]] as [string, string],\n },\n ]\n : undefined;\n return {\n datasets: (scatterSeries ?? []).map((series, index) => ({\n ...extras?.(series.name),\n label: series.name,\n data: data.map((item) => ({\n x: item[series.fields[0]] ?? 0,\n y: item[series.fields[1]] ?? 0,\n })),\n backgroundColor: getDefaultColor(\n index,\n (scatterSeries ?? []).length,\n opacity\n ),\n })),\n };\n } else {\n const autoChosenFields = numericFields.filter(\n (field) => field !== realLabelField\n );\n return {\n labels: realLabelField\n ? data.map((item) => item[realLabelField])\n : undefined,\n datasets: (chosenFields ?? autoChosenFields).map((key, index) => {\n return {\n ...extras?.(key),\n label: key,\n data: data.map((item) => item[key] ?? 0),\n backgroundColor: getDefaultColor(\n index,\n (chosenFields ?? autoChosenFields).length,\n 1\n ),\n borderWidth: 2,\n borderColor: getDefaultColor(\n index,\n (chosenFields ?? autoChosenFields).length,\n 1\n ),\n };\n }),\n };\n }\n}\n\n// additional styling\n\n/*\n elements: {\n bar: {\n borderWidth: 2,\n },\n },\n\n */\n\nexport function prepOptions({ interactive = true, title }: BaseChartProps) {\n return [\n baseOptions,\n interactive\n ? {\n interaction: {\n mode: \"index\" as const,\n intersect: false,\n },\n events: undefined,\n }\n : {\n events: [],\n },\n title\n ? {\n plugins: {\n title: { display: true, text: title },\n },\n }\n : {},\n ];\n}\n\nexport const ChartAreaPlugin: Plugin = {\n id: \"chartAreaPlugin\",\n // eslint-disable-next-line object-shorthand\n beforeDraw: (chart) => {\n const chartAreaOptions = (chart.config.options as any).chartArea;\n if (chartAreaOptions && chartAreaOptions.backgroundColor) {\n const ctx = chart.canvas.getContext(\"2d\");\n const { chartArea } = chart;\n if (ctx) {\n ctx.save();\n ctx.fillStyle = chartAreaOptions.backgroundColor;\n // eslint-disable-next-line max-len\n ctx.fillRect(\n chartArea.left,\n chartArea.top,\n chartArea.right - chartArea.left,\n chartArea.bottom - chartArea.top\n );\n ctx.restore();\n }\n }\n },\n};\n","import {\n BarElement,\n CategoryScale,\n Chart as ChartJS,\n Legend,\n LinearScale,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Bar } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport const stackedOptions = {\n scales: {\n x: {\n stacked: true,\n ticks: {\n major: {\n enabled: false,\n },\n },\n },\n y: {\n stacked: true,\n },\n },\n};\n\nexport const vertOptions = {\n indexAxis: \"x\" as const,\n plugins: {\n legend: {\n position: \"top\" as const,\n },\n },\n};\nexport const horizOptions = {\n indexAxis: \"y\" as const,\n plugins: {\n legend: {\n position: \"right\" as const,\n },\n },\n};\n\nexport interface SimpleBarProps extends BaseChartProps {\n direction?: \"vertical\" | \"horizontal\";\n stacked?: boolean;\n}\n\nexport function SimpleBar(props: SimpleBarProps) {\n const { direction = \"vertical\", stacked, className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n CategoryScale,\n LinearScale,\n BarElement,\n Title,\n Tooltip,\n Legend\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, {\n preferNonNumericAsLabel: true,\n opacity: 1,\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Bar\n key={`${props.direction}${props.stacked}`}\n options={deepmerge.all([\n ...options,\n direction === \"vertical\" ? vertOptions : horizOptions,\n stacked ? stackedOptions : {},\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import {\n CategoryScale,\n Chart as ChartJS,\n Filler,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect, useState } from \"react\";\nimport { Line } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport interface SimpleLineProps extends BaseChartProps {\n fill?: boolean;\n secondAxisField?: string;\n}\n\n// Force a re-mount when the secondAxisField is unset / re-set\n// https://app.shortcut.com/plasmic/story/38358/chart-component-issues-with-second-axis-field\nconst useKey = (secondAxisField?: string) => {\n const [key, setKey] = useState(0);\n\n // change key once when the secondAxisField is unset.\n if (!secondAxisField && key) {\n setKey(0);\n }\n\n // change key once when the secondAxisField value changes from undefined -> something\n if (secondAxisField && !key) {\n setKey(Math.random());\n }\n\n return key;\n};\n\nexport function SimpleLine(props: SimpleLineProps) {\n const { secondAxisField, fill, className } = props;\n const isClient = useIsClient();\n const key = useKey(props.secondAxisField);\n\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n CategoryScale,\n LinearScale,\n PointElement,\n LineElement,\n Title,\n Tooltip,\n Filler,\n Legend\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, {\n extras: (field) => ({\n fill,\n pointRadius: 0,\n yAxisID: field === secondAxisField ? \"y1\" : \"y\",\n }),\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Line\n key={key}\n options={deepmerge.all([\n ...options,\n secondAxisField\n ? {\n scales: {\n y: {\n type: \"linear\" as const,\n display: true,\n position: \"left\" as const,\n },\n y1: {\n type: \"linear\" as const,\n display: true,\n position: \"right\" as const,\n grid: {\n drawOnChartArea: false,\n },\n },\n },\n }\n : {},\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import {\n Chart as ChartJS,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Scatter } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport type SimpleScatterProps = BaseChartProps;\n\nexport function SimpleScatter(props: SimpleScatterProps) {\n const { className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n LinearScale,\n PointElement,\n LineElement,\n Tooltip,\n Legend,\n Title\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, { isScatter: true, opacity: 1 });\n const options = prepOptions(props);\n\n return (\n <div className={className}>\n <Scatter\n options={deepmerge.all([\n ...options,\n {\n scales: {\n y: {\n beginAtZero: true,\n },\n },\n },\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import React, { ReactElement } from \"react\";\nimport { SimpleBar, SimpleBarProps } from \"../simple-bar/SimpleBar\";\nimport { SimpleLine, SimpleLineProps } from \"../simple-line/SimpleLine\";\nimport {\n SimpleScatter,\n SimpleScatterProps,\n} from \"../simple-scatter/SimpleScatter\";\n\nexport type SimpleChartProps = {\n type?: \"bar\" | \"line\" | \"scatter\";\n} & (SimpleBarProps | SimpleLineProps | SimpleScatterProps);\n\nexport function SimpleChart(props: SimpleChartProps): ReactElement {\n switch (props.type ?? \"bar\") {\n case \"bar\":\n return <SimpleBar {...(props as any)} />;\n case \"line\":\n return <SimpleLine {...(props as any)} />;\n case \"scatter\":\n return <SimpleScatter {...(props as any)} />;\n }\n}\n","import {\n CodeComponentMeta,\n PropType,\n} from \"@plasmicapp/host/registerComponent\";\nimport { Registerable, registerComponentHelper } from \"../utils\";\nimport { SimpleChart, SimpleChartProps } from \"./SimpleChart\";\n\nexport * from \"./SimpleChart\";\nexport default SimpleChart;\n\nconst fieldChoice: PropType<SimpleChartProps> = {\n type: \"choice\",\n options: (props: SimpleChartProps) =>\n props.data?.[0] ? Object.keys(props.data[0]) : [],\n} as const;\nconst simpleChartMeta: CodeComponentMeta<SimpleChartProps> = {\n name: \"hostless-react-chartjs-2-simple-chart\",\n displayName: \"Chart\",\n props: {\n type: {\n type: \"choice\",\n options: [\n {\n value: \"bar\",\n label: \"Bar\",\n },\n {\n value: \"line\",\n label: \"Line\",\n },\n {\n value: \"scatter\",\n label: \"Scatter\",\n },\n ],\n defaultValueHint: \"bar\",\n },\n data: {\n type: \"exprEditor\",\n description: \"The data as an array of objects\",\n defaultExpr: JSON.stringify([\n {\n region: \"APAC\",\n revenue: 3294,\n spend: 2675,\n },\n {\n region: \"EMEA\",\n revenue: 3245,\n spend: 3895,\n },\n {\n region: \"LATAM\",\n revenue: 2165,\n spend: 3498,\n },\n {\n region: \"AMER\",\n revenue: 3215,\n spend: 1656,\n },\n ]),\n },\n labelField: {\n ...fieldChoice,\n hidden: (props) => props.type === \"scatter\",\n },\n title: \"string\",\n interactive: {\n type: \"boolean\",\n defaultValueHint: true,\n },\n // Bar chart\n direction: {\n type: \"choice\",\n options: [\"horizontal\", \"vertical\"].map((dir) => ({\n value: dir,\n label: dir[0].toUpperCase() + dir.slice(1),\n })),\n defaultValueHint: \"Vertical\",\n hidden: ({ type = \"bar\" }) => type !== \"bar\",\n },\n stacked: {\n type: \"boolean\",\n hidden: ({ type = \"bar\" }) => type !== \"bar\",\n },\n // Line chart\n fill: {\n type: \"boolean\",\n hidden: (props) => props.type !== \"line\",\n },\n secondAxisField: {\n ...fieldChoice,\n hidden: (props) => props.type !== \"line\",\n },\n\n // TODO\n // datasets: {\n // type: \"array\",\n // unstable__keyFunc: (x) => x.key,\n // unstable__minimalValue: (_props, ctx) => null,\n // itemType: {\n // type: \"object\",\n // fields: {\n // label: \"string\",\n // fieldId: \"string\",\n // hidden: {\n // type: \"boolean\",\n // },\n // },\n // },\n // },\n },\n\n defaultStyles: {\n width: \"stretch\",\n },\n\n importName: \"SimpleChart\",\n importPath: \"@plasmicpkgs/react-chartjs-2\",\n};\n\nexport function registerSimpleChart(loader?: Registerable) {\n registerComponentHelper(loader, SimpleChart, simpleChartMeta);\n}\n","import { registerSimpleChart } from \"./simple-chart\";\nimport { Registerable } from \"./utils\";\n\nexport { SimpleChart } from \"./simple-chart\";\n\nexport function registerAll(loader?: Registerable) {\n registerSimpleChart(loader);\n}\n","import {\n CodeComponentMeta,\n default as registerComponent,\n} from \"@plasmicapp/host/registerComponent\";\nimport {\n GlobalContextMeta,\n default as registerGlobalContext,\n} from \"@plasmicapp/host/registerGlobalContext\";\nimport { default as registerToken } from \"@plasmicapp/host/registerToken\";\nimport React from \"react\";\n\nexport type Registerable = {\n registerComponent: typeof registerComponent;\n registerGlobalContext: typeof registerGlobalContext;\n registerToken: typeof registerToken;\n};\n\nexport function makeRegisterComponent<T extends React.ComponentType<any>>(\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n return function (loader?: Registerable) {\n registerComponentHelper(loader, component, meta);\n };\n}\n\nexport function makeRegisterGlobalContext<T extends React.ComponentType<any>>(\n component: T,\n meta: GlobalContextMeta<React.ComponentProps<T>>\n) {\n return function (loader?: Registerable) {\n if (loader) {\n loader.registerGlobalContext(component, meta);\n } else {\n registerGlobalContext(component, meta);\n }\n };\n}\n\nexport function registerComponentHelper<T extends React.ComponentType<any>>(\n loader: Registerable | undefined,\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n if (loader) {\n loader.registerComponent(component, meta);\n } else {\n registerComponent(component, meta);\n }\n}\n\ntype ReactElt = {\n children: ReactElt | ReactElt[];\n props: {\n children: ReactElt | ReactElt[];\n [prop: string]: any;\n } | null;\n type: React.ComponentType<any> | null;\n key: string | null;\n} | null;\n\nexport function traverseReactEltTree(\n children: React.ReactNode,\n callback: (elt: ReactElt) => void\n) {\n const rec = (elts: ReactElt | ReactElt[] | null) => {\n (Array.isArray(elts) ? elts : [elts]).forEach((elt) => {\n if (elt) {\n callback(elt);\n if (elt.children) {\n rec(elt.children);\n }\n if (elt.props?.children && elt.props.children !== elt.children) {\n rec(elt.props.children);\n }\n }\n });\n };\n rec(children as any);\n}\n\nexport function asArray<T>(x: T[] | T | undefined | null) {\n if (Array.isArray(x)) {\n return x;\n } else if (x == null) {\n return [];\n } else {\n return [x];\n }\n}\n"],"names":["baseOptions","responsive","chartArea","defaultColors","useIsClient","_useState","useState","loaded","setLoaded","useEffect","range","total","Array","from","keys","getDefaultColor","index","opacity","end","length","start","Math","max","min","stops","map","_","i","round","selected","undefined","replace","prepData","_ref","_temp","data","_ref$data","labelField","chosenFields","scatterSeries","_ref2","isScatter","preferNonNumericAsLabel","extras","fields","Object","_data$","isFieldAllNumericOrNil","Map","key","every","item","_item$key","isNaN","realLabelField","find","field","get","numericFields","filter","datasets","name","series","_extends","label","_item$series$fields$","_item$series$fields$2","x","y","backgroundColor","autoChosenFields","labels","_item$key2","borderWidth","borderColor","prepOptions","_ref3","interactive","title","_ref3$interactive","interaction","mode","intersect","events","plugins","display","text","ChartAreaPlugin","id","beforeDraw","chart","chartAreaOptions","config","options","ctx","canvas","getContext","save","fillStyle","fillRect","left","top","right","bottom","restore","stackedOptions","scales","stacked","ticks","major","enabled","vertOptions","indexAxis","legend","position","horizOptions","SimpleBar","props","_props$direction","direction","className","isClient","ChartJS","register","CategoryScale","LinearScale","BarElement","Title","Tooltip","Legend","normalized","React","Bar","deepmerge","all","concat","SimpleLine","secondAxisField","fill","setKey","random","useKey","PointElement","LineElement","Filler","pointRadius","yAxisID","Line","type","y1","grid","drawOnChartArea","SimpleScatter","Scatter","beginAtZero","SimpleChart","_props$type","fieldChoice","_props$data","simpleChartMeta","displayName","value","defaultValueHint","description","defaultExpr","JSON","stringify","region","revenue","spend","hidden","dir","toUpperCase","slice","_ref$type","_ref2$type","defaultStyles","width","importName","importPath","loader","component","meta","registerComponent","registerComponentHelper","registerSimpleChart"],"mappings":"qjBAGO,IAAMA,EAAc,CACzBC,YAAY,EACZC,UAAW,IAQAC,EAAgB,CAC3B,uBACA,uBACA,uBACA,uBACA,wBACA,wBACA,wBACA,wBACA,wBACA,wBACA,wBACA,wBACA,wBACA,wBACA,wBACA,yBAGF,SAAgBC,IACd,IAAAC,EAA4BC,YAAS,GAA9BC,EAAMF,KAAEG,EAASH,KAIxB,OAHAI,aAAU,WACRD,GAAU,MAELD,EAoBT,SAASG,EAAMC,GACb,OAAOC,MAAMC,KAAKD,MAAMD,GAAOG,QAYjC,SAAgBC,EACdC,EACAL,EACAM,GAEA,IACMC,EAAMf,EAAcgB,OAAS,EAC7BC,EAAQC,KAAKC,IAAI,EAAGD,KAAKE,IAFR,EAE4BL,EAAMP,IACnDa,EACJb,EAAQR,EAAcgB,OAClBT,EAAMP,EAAcgB,QACpBT,EAAMC,GAAOc,KAAI,SAACC,EAAGC,GAAC,OACpBN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,8 @@ var baseOptions = {
|
|
|
29
29
|
// backgroundColor: "#f8fafc",
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
-
/**
|
|
33
|
-
* These are hand-picked from the Tailwind palette.
|
|
32
|
+
/**
|
|
33
|
+
* These are hand-picked from the Tailwind palette.
|
|
34
34
|
*/
|
|
35
35
|
var defaultColors = ["hsla(25,95%,53%,1.0)", "hsla(38,92%,50%,1.0)", "hsla(45,93%,47%,1.0)", "hsla(84,81%,44%,1.0)", "hsla(142,71%,45%,1.0)", "hsla(160,84%,39%,1.0)", "hsla(173,80%,40%,1.0)", "hsla(199,89%,48%,1.0)", "hsla(217,91%,60%,1.0)", "hsla(239,84%,67%,1.0)", "hsla(258,90%,66%,1.0)", "hsla(271,91%,65%,1.0)", "hsla(292,84%,61%,1.0)", "hsla(293,69%,49%,1.0)", "hsla(295,72%,40%,1.0)", "hsla(295,70%,33%,1.0)"];
|
|
36
36
|
function useIsClient() {
|
|
@@ -45,14 +45,14 @@ function useIsClient() {
|
|
|
45
45
|
function range(total) {
|
|
46
46
|
return Array.from(Array(total).keys());
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Returns a color from the default color palette.
|
|
50
|
-
*
|
|
51
|
-
* Tries to pick "different" colors that are somewhat spread out on the palette. With a higher 'total' colors requested, the colors will be packed more closely together.
|
|
52
|
-
*
|
|
53
|
-
* We prefer starting from blue when possible. This only starts getting pushed down toward yellow if too many colors requested.
|
|
54
|
-
*
|
|
55
|
-
* If too many colors are requested, it will recycle.
|
|
48
|
+
/**
|
|
49
|
+
* Returns a color from the default color palette.
|
|
50
|
+
*
|
|
51
|
+
* Tries to pick "different" colors that are somewhat spread out on the palette. With a higher 'total' colors requested, the colors will be packed more closely together.
|
|
52
|
+
*
|
|
53
|
+
* We prefer starting from blue when possible. This only starts getting pushed down toward yellow if too many colors requested.
|
|
54
|
+
*
|
|
55
|
+
* If too many colors are requested, it will recycle.
|
|
56
56
|
*/
|
|
57
57
|
function getDefaultColor(index, total, opacity) {
|
|
58
58
|
var preferredStart = 9;
|
|
@@ -136,12 +136,12 @@ function prepData(_ref, _temp) {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
// additional styling
|
|
139
|
-
/*
|
|
140
|
-
elements: {
|
|
141
|
-
bar: {
|
|
142
|
-
borderWidth: 2,
|
|
143
|
-
},
|
|
144
|
-
},
|
|
139
|
+
/*
|
|
140
|
+
elements: {
|
|
141
|
+
bar: {
|
|
142
|
+
borderWidth: 2,
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
145
|
|
|
146
146
|
*/
|
|
147
147
|
function prepOptions(_ref3) {
|
|
@@ -336,11 +336,11 @@ function SimpleChart(props) {
|
|
|
336
336
|
var _props$type;
|
|
337
337
|
switch ((_props$type = props.type) != null ? _props$type : "bar") {
|
|
338
338
|
case "bar":
|
|
339
|
-
return React.createElement(SimpleBar,
|
|
339
|
+
return React.createElement(SimpleBar, _extends({}, props));
|
|
340
340
|
case "line":
|
|
341
|
-
return React.createElement(SimpleLine,
|
|
341
|
+
return React.createElement(SimpleLine, _extends({}, props));
|
|
342
342
|
case "scatter":
|
|
343
|
-
return React.createElement(SimpleScatter,
|
|
343
|
+
return React.createElement(SimpleScatter, _extends({}, props));
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
|
|
@@ -436,6 +436,22 @@ var simpleChartMeta = {
|
|
|
436
436
|
return props.type !== "line";
|
|
437
437
|
}
|
|
438
438
|
})
|
|
439
|
+
// TODO
|
|
440
|
+
// datasets: {
|
|
441
|
+
// type: "array",
|
|
442
|
+
// unstable__keyFunc: (x) => x.key,
|
|
443
|
+
// unstable__minimalValue: (_props, ctx) => null,
|
|
444
|
+
// itemType: {
|
|
445
|
+
// type: "object",
|
|
446
|
+
// fields: {
|
|
447
|
+
// label: "string",
|
|
448
|
+
// fieldId: "string",
|
|
449
|
+
// hidden: {
|
|
450
|
+
// type: "boolean",
|
|
451
|
+
// },
|
|
452
|
+
// },
|
|
453
|
+
// },
|
|
454
|
+
// },
|
|
439
455
|
},
|
|
440
456
|
defaultStyles: {
|
|
441
457
|
width: "stretch"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-chartjs-2.esm.js","sources":["../src/utils.ts","../src/common.ts","../src/simple-bar/SimpleBar.tsx","../src/simple-line/SimpleLine.tsx","../src/simple-scatter/SimpleScatter.tsx","../src/simple-chart/SimpleChart.tsx","../src/simple-chart/index.tsx","../src/index.tsx"],"sourcesContent":["import {\n CodeComponentMeta,\n default as registerComponent,\n} from \"@plasmicapp/host/registerComponent\";\nimport {\n GlobalContextMeta,\n default as registerGlobalContext,\n} from \"@plasmicapp/host/registerGlobalContext\";\nimport { default as registerToken } from \"@plasmicapp/host/registerToken\";\nimport React from \"react\";\n\nexport type Registerable = {\n registerComponent: typeof registerComponent;\n registerGlobalContext: typeof registerGlobalContext;\n registerToken: typeof registerToken;\n};\n\nexport function makeRegisterComponent<T extends React.ComponentType<any>>(\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n return function (loader?: Registerable) {\n registerComponentHelper(loader, component, meta);\n };\n}\n\nexport function makeRegisterGlobalContext<T extends React.ComponentType<any>>(\n component: T,\n meta: GlobalContextMeta<React.ComponentProps<T>>\n) {\n return function (loader?: Registerable) {\n if (loader) {\n loader.registerGlobalContext(component, meta);\n } else {\n registerGlobalContext(component, meta);\n }\n };\n}\n\nexport function registerComponentHelper<T extends React.ComponentType<any>>(\n loader: Registerable | undefined,\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n if (loader) {\n loader.registerComponent(component, meta);\n } else {\n registerComponent(component, meta);\n }\n}\n\ntype ReactElt = {\n children: ReactElt | ReactElt[];\n props: {\n children: ReactElt | ReactElt[];\n [prop: string]: any;\n } | null;\n type: React.ComponentType<any> | null;\n key: string | null;\n} | null;\n\nexport function traverseReactEltTree(\n children: React.ReactNode,\n callback: (elt: ReactElt) => void\n) {\n const rec = (elts: ReactElt | ReactElt[] | null) => {\n (Array.isArray(elts) ? elts : [elts]).forEach((elt) => {\n if (elt) {\n callback(elt);\n if (elt.children) {\n rec(elt.children);\n }\n if (elt.props?.children && elt.props.children !== elt.children) {\n rec(elt.props.children);\n }\n }\n });\n };\n rec(children as any);\n}\n\nexport function asArray<T>(x: T[] | T | undefined | null) {\n if (Array.isArray(x)) {\n return x;\n } else if (x == null) {\n return [];\n } else {\n return [x];\n }\n}\n","import { Plugin } from \"chart.js/dist/types\";\nimport { useEffect, useState } from \"react\";\n\nexport const baseOptions = {\n responsive: true,\n chartArea: {\n // backgroundColor: \"#f8fafc\",\n },\n};\n\n/**\n * These are hand-picked from the Tailwind palette.\n */\nexport const defaultColors = [\n \"hsla(25,95%,53%,1.0)\",\n \"hsla(38,92%,50%,1.0)\",\n \"hsla(45,93%,47%,1.0)\",\n \"hsla(84,81%,44%,1.0)\",\n \"hsla(142,71%,45%,1.0)\",\n \"hsla(160,84%,39%,1.0)\",\n \"hsla(173,80%,40%,1.0)\",\n \"hsla(199,89%,48%,1.0)\",\n \"hsla(217,91%,60%,1.0)\",\n \"hsla(239,84%,67%,1.0)\",\n \"hsla(258,90%,66%,1.0)\",\n \"hsla(271,91%,65%,1.0)\",\n \"hsla(292,84%,61%,1.0)\",\n \"hsla(293,69%,49%,1.0)\",\n \"hsla(295,72%,40%,1.0)\",\n \"hsla(295,70%,33%,1.0)\",\n];\n\nexport function useIsClient() {\n const [loaded, setLoaded] = useState(false);\n useEffect(() => {\n setLoaded(true);\n });\n return loaded;\n}\n\nexport interface BaseChartProps {\n className?: string;\n data?: Record<string, any>[];\n labelField?: string;\n interactive?: boolean;\n title?: string;\n chosenFields?: string[];\n scatterSeries?: { name: string; fields: [string, string] }[];\n}\n\nexport interface PrepDataOpts {\n isScatter?: boolean;\n preferNonNumericAsLabel?: boolean;\n extras?: (field: string) => {};\n opacity?: number;\n}\n\nfunction range(total: number) {\n return Array.from(Array(total).keys());\n}\n\n/**\n * Returns a color from the default color palette.\n *\n * Tries to pick \"different\" colors that are somewhat spread out on the palette. With a higher 'total' colors requested, the colors will be packed more closely together.\n *\n * We prefer starting from blue when possible. This only starts getting pushed down toward yellow if too many colors requested.\n *\n * If too many colors are requested, it will recycle.\n */\nexport function getDefaultColor(\n index: number,\n total: number,\n opacity?: number\n) {\n const preferredStart = 9;\n const end = defaultColors.length - 1;\n const start = Math.max(0, Math.min(preferredStart, end - total));\n const stops =\n total > defaultColors.length\n ? range(defaultColors.length)\n : range(total).map((_, i) =>\n Math.round(\n start + (total > 1 ? ((1.0 * i) / (total - 1)) * (end - start) : 0)\n )\n );\n const selected = defaultColors[stops[index % stops.length]];\n if (opacity === undefined) {\n return selected;\n }\n return selected.replace(\"1.0\", \"\" + opacity);\n}\n\nexport function prepData(\n { data = [], labelField, chosenFields, scatterSeries }: BaseChartProps,\n { isScatter, preferNonNumericAsLabel, extras, opacity }: PrepDataOpts = {}\n) {\n const fields = Object.keys(data[0] ?? {});\n const isFieldAllNumericOrNil = new Map(\n fields.map((key) => [key, data.every((item) => !isNaN(item[key] ?? 0))])\n );\n const realLabelField =\n labelField ??\n (preferNonNumericAsLabel\n ? fields.find((field) => !isFieldAllNumericOrNil.get(field))\n : fields[0]);\n const numericFields = fields.filter((field) =>\n isFieldAllNumericOrNil.get(field)\n );\n if (isScatter) {\n scatterSeries = isScatter\n ? scatterSeries ?? [\n {\n name: `${numericFields[0]}-${numericFields[1]}`,\n fields: [numericFields[0], numericFields[1]] as [string, string],\n },\n ]\n : undefined;\n return {\n datasets: (scatterSeries ?? []).map((series, index) => ({\n ...extras?.(series.name),\n label: series.name,\n data: data.map((item) => ({\n x: item[series.fields[0]] ?? 0,\n y: item[series.fields[1]] ?? 0,\n })),\n backgroundColor: getDefaultColor(\n index,\n (scatterSeries ?? []).length,\n opacity\n ),\n })),\n };\n } else {\n const autoChosenFields = numericFields.filter(\n (field) => field !== realLabelField\n );\n return {\n labels: realLabelField\n ? data.map((item) => item[realLabelField])\n : undefined,\n datasets: (chosenFields ?? autoChosenFields).map((key, index) => {\n return {\n ...extras?.(key),\n label: key,\n data: data.map((item) => item[key] ?? 0),\n backgroundColor: getDefaultColor(\n index,\n (chosenFields ?? autoChosenFields).length,\n 1\n ),\n borderWidth: 2,\n borderColor: getDefaultColor(\n index,\n (chosenFields ?? autoChosenFields).length,\n 1\n ),\n };\n }),\n };\n }\n}\n\n// additional styling\n\n/*\n elements: {\n bar: {\n borderWidth: 2,\n },\n },\n\n */\n\nexport function prepOptions({ interactive = true, title }: BaseChartProps) {\n return [\n baseOptions,\n interactive\n ? {\n interaction: {\n mode: \"index\" as const,\n intersect: false,\n },\n events: undefined,\n }\n : {\n events: [],\n },\n title\n ? {\n plugins: {\n title: { display: true, text: title },\n },\n }\n : {},\n ];\n}\n\nexport const ChartAreaPlugin: Plugin = {\n id: \"chartAreaPlugin\",\n // eslint-disable-next-line object-shorthand\n beforeDraw: (chart) => {\n const chartAreaOptions = (chart.config.options as any).chartArea;\n if (chartAreaOptions && chartAreaOptions.backgroundColor) {\n const ctx = chart.canvas.getContext(\"2d\");\n const { chartArea } = chart;\n if (ctx) {\n ctx.save();\n ctx.fillStyle = chartAreaOptions.backgroundColor;\n // eslint-disable-next-line max-len\n ctx.fillRect(\n chartArea.left,\n chartArea.top,\n chartArea.right - chartArea.left,\n chartArea.bottom - chartArea.top\n );\n ctx.restore();\n }\n }\n },\n};\n","import {\n BarElement,\n CategoryScale,\n Chart as ChartJS,\n Legend,\n LinearScale,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Bar } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport const stackedOptions = {\n scales: {\n x: {\n stacked: true,\n ticks: {\n major: {\n enabled: false,\n },\n },\n },\n y: {\n stacked: true,\n },\n },\n};\n\nexport const vertOptions = {\n indexAxis: \"x\" as const,\n plugins: {\n legend: {\n position: \"top\" as const,\n },\n },\n};\nexport const horizOptions = {\n indexAxis: \"y\" as const,\n plugins: {\n legend: {\n position: \"right\" as const,\n },\n },\n};\n\nexport interface SimpleBarProps extends BaseChartProps {\n direction?: \"vertical\" | \"horizontal\";\n stacked?: boolean;\n}\n\nexport function SimpleBar(props: SimpleBarProps) {\n const { direction = \"vertical\", stacked, className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n CategoryScale,\n LinearScale,\n BarElement,\n Title,\n Tooltip,\n Legend\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, {\n preferNonNumericAsLabel: true,\n opacity: 1,\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Bar\n key={`${props.direction}${props.stacked}`}\n options={deepmerge.all([\n ...options,\n direction === \"vertical\" ? vertOptions : horizOptions,\n stacked ? stackedOptions : {},\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import {\n CategoryScale,\n Chart as ChartJS,\n Filler,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect, useState } from \"react\";\nimport { Line } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport interface SimpleLineProps extends BaseChartProps {\n fill?: boolean;\n secondAxisField?: string;\n}\n\n// Force a re-mount when the secondAxisField is unset / re-set\n// https://app.shortcut.com/plasmic/story/38358/chart-component-issues-with-second-axis-field\nconst useKey = (secondAxisField?: string) => {\n const [key, setKey] = useState(0);\n\n // change key once when the secondAxisField is unset.\n if (!secondAxisField && key) {\n setKey(0);\n }\n\n // change key once when the secondAxisField value changes from undefined -> something\n if (secondAxisField && !key) {\n setKey(Math.random());\n }\n\n return key;\n};\n\nexport function SimpleLine(props: SimpleLineProps) {\n const { secondAxisField, fill, className } = props;\n const isClient = useIsClient();\n const key = useKey(props.secondAxisField);\n\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n CategoryScale,\n LinearScale,\n PointElement,\n LineElement,\n Title,\n Tooltip,\n Filler,\n Legend\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, {\n extras: (field) => ({\n fill,\n pointRadius: 0,\n yAxisID: field === secondAxisField ? \"y1\" : \"y\",\n }),\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Line\n key={key}\n options={deepmerge.all([\n ...options,\n secondAxisField\n ? {\n scales: {\n y: {\n type: \"linear\" as const,\n display: true,\n position: \"left\" as const,\n },\n y1: {\n type: \"linear\" as const,\n display: true,\n position: \"right\" as const,\n grid: {\n drawOnChartArea: false,\n },\n },\n },\n }\n : {},\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import {\n Chart as ChartJS,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Scatter } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport type SimpleScatterProps = BaseChartProps;\n\nexport function SimpleScatter(props: SimpleScatterProps) {\n const { className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n LinearScale,\n PointElement,\n LineElement,\n Tooltip,\n Legend,\n Title\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, { isScatter: true, opacity: 1 });\n const options = prepOptions(props);\n\n return (\n <div className={className}>\n <Scatter\n options={deepmerge.all([\n ...options,\n {\n scales: {\n y: {\n beginAtZero: true,\n },\n },\n },\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import React, { ReactElement } from \"react\";\nimport { SimpleBar, SimpleBarProps } from \"../simple-bar/SimpleBar\";\nimport { SimpleLine, SimpleLineProps } from \"../simple-line/SimpleLine\";\nimport {\n SimpleScatter,\n SimpleScatterProps,\n} from \"../simple-scatter/SimpleScatter\";\n\nexport type SimpleChartProps = {\n type?: \"bar\" | \"line\" | \"scatter\";\n} & (SimpleBarProps | SimpleLineProps | SimpleScatterProps);\n\nexport function SimpleChart(props: SimpleChartProps): ReactElement {\n switch (props.type ?? \"bar\") {\n case \"bar\":\n return <SimpleBar {...(props as any)} />;\n case \"line\":\n return <SimpleLine {...(props as any)} />;\n case \"scatter\":\n return <SimpleScatter {...(props as any)} />;\n }\n}\n","import {\n CodeComponentMeta,\n PropType,\n} from \"@plasmicapp/host/registerComponent\";\nimport { Registerable, registerComponentHelper } from \"../utils\";\nimport { SimpleChart, SimpleChartProps } from \"./SimpleChart\";\n\nexport * from \"./SimpleChart\";\nexport default SimpleChart;\n\nconst fieldChoice: PropType<SimpleChartProps> = {\n type: \"choice\",\n options: (props: SimpleChartProps) =>\n props.data?.[0] ? Object.keys(props.data[0]) : [],\n} as const;\nconst simpleChartMeta: CodeComponentMeta<SimpleChartProps> = {\n name: \"hostless-react-chartjs-2-simple-chart\",\n displayName: \"Chart\",\n props: {\n type: {\n type: \"choice\",\n options: [\n {\n value: \"bar\",\n label: \"Bar\",\n },\n {\n value: \"line\",\n label: \"Line\",\n },\n {\n value: \"scatter\",\n label: \"Scatter\",\n },\n ],\n defaultValueHint: \"bar\",\n },\n data: {\n type: \"exprEditor\",\n description: \"The data as an array of objects\",\n defaultExpr: JSON.stringify([\n {\n region: \"APAC\",\n revenue: 3294,\n spend: 2675,\n },\n {\n region: \"EMEA\",\n revenue: 3245,\n spend: 3895,\n },\n {\n region: \"LATAM\",\n revenue: 2165,\n spend: 3498,\n },\n {\n region: \"AMER\",\n revenue: 3215,\n spend: 1656,\n },\n ]),\n },\n labelField: {\n ...fieldChoice,\n hidden: (props) => props.type === \"scatter\",\n },\n title: \"string\",\n interactive: {\n type: \"boolean\",\n defaultValueHint: true,\n },\n // Bar chart\n direction: {\n type: \"choice\",\n options: [\"horizontal\", \"vertical\"].map((dir) => ({\n value: dir,\n label: dir[0].toUpperCase() + dir.slice(1),\n })),\n defaultValueHint: \"Vertical\",\n hidden: ({ type = \"bar\" }) => type !== \"bar\",\n },\n stacked: {\n type: \"boolean\",\n hidden: ({ type = \"bar\" }) => type !== \"bar\",\n },\n // Line chart\n fill: {\n type: \"boolean\",\n hidden: (props) => props.type !== \"line\",\n },\n secondAxisField: {\n ...fieldChoice,\n hidden: (props) => props.type !== \"line\",\n },\n\n // TODO\n // datasets: {\n // type: \"array\",\n // unstable__keyFunc: (x) => x.key,\n // unstable__minimalValue: (_props, ctx) => null,\n // itemType: {\n // type: \"object\",\n // fields: {\n // label: \"string\",\n // fieldId: \"string\",\n // hidden: {\n // type: \"boolean\",\n // },\n // },\n // },\n // },\n },\n\n defaultStyles: {\n width: \"stretch\",\n },\n\n importName: \"SimpleChart\",\n importPath: \"@plasmicpkgs/react-chartjs-2\",\n};\n\nexport function registerSimpleChart(loader?: Registerable) {\n registerComponentHelper(loader, SimpleChart, simpleChartMeta);\n}\n","import { registerSimpleChart } from \"./simple-chart\";\nimport { Registerable } from \"./utils\";\n\nexport { SimpleChart } from \"./simple-chart\";\n\nexport function registerAll(loader?: Registerable) {\n registerSimpleChart(loader);\n}\n"],"names":["registerComponentHelper","loader","component","meta","registerComponent","baseOptions","responsive","chartArea","defaultColors","useIsClient","_useState","useState","loaded","setLoaded","useEffect","range","total","Array","from","keys","getDefaultColor","index","opacity","preferredStart","end","length","start","Math","max","min","stops","map","_","i","round","selected","undefined","replace","prepData","_ref","_temp","data","_ref$data","labelField","chosenFields","scatterSeries","_ref2","isScatter","preferNonNumericAsLabel","extras","fields","Object","_data$","isFieldAllNumericOrNil","Map","key","every","item","_item$key","isNaN","realLabelField","find","field","get","numericFields","filter","name","datasets","series","_extends","label","_item$series$fields$","_item$series$fields$2","x","y","backgroundColor","autoChosenFields","labels","_item$key2","borderWidth","borderColor","prepOptions","_ref3","interactive","_ref3$interactive","title","interaction","mode","intersect","events","plugins","display","text","ChartAreaPlugin","id","beforeDraw","chart","chartAreaOptions","config","options","ctx","canvas","getContext","save","fillStyle","fillRect","left","top","right","bottom","restore","stackedOptions","scales","stacked","ticks","major","enabled","vertOptions","indexAxis","legend","position","horizOptions","SimpleBar","props","_props$direction","direction","className","isClient","ChartJS","register","CategoryScale","LinearScale","BarElement","Title","Tooltip","Legend","normalized","React","Bar","deepmerge","all","concat","useKey","secondAxisField","setKey","random","SimpleLine","fill","PointElement","LineElement","Filler","pointRadius","yAxisID","Line","type","y1","grid","drawOnChartArea","SimpleScatter","Scatter","beginAtZero","SimpleChart","_props$type","fieldChoice","_props$data","simpleChartMeta","displayName","value","defaultValueHint","description","defaultExpr","JSON","stringify","region","revenue","spend","hidden","dir","toUpperCase","slice","_ref$type","_ref2$type","defaultStyles","width","importName","importPath","registerSimpleChart","registerAll"],"mappings":";;;;;;;;;;;;;;;;;SAuCgBA,uBAAuBA,CACrCC,MAAgC,EAChCC,SAAY,EACZC,IAAgD;EAEhD,IAAIF,MAAM,EAAE;IACVA,MAAM,CAACG,iBAAiB,CAACF,SAAS,EAAEC,IAAI,CAAC;GAC1C,MAAM;IACLC,iBAAiB,CAACF,SAAS,EAAEC,IAAI,CAAC;;AAEtC;;AC9CO,IAAME,WAAW,GAAG;EACzBC,UAAU,EAAE,IAAI;EAChBC,SAAS,EAAE;;;CAGZ;AAED;;;AAGA,AAAO,IAAMC,aAAa,GAAG,CAC3B,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,CACxB;AAED,SAAgBC,WAAWA;EACzB,IAAAC,SAAA,GAA4BC,QAAQ,CAAC,KAAK,CAAC;IAApCC,MAAM,GAAAF,SA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SimpleBar.tsx","../src/simple-line/SimpleLine.tsx","../src/simple-scatter/SimpleScatter.tsx","../src/simple-chart/SimpleChart.tsx","../src/simple-chart/index.tsx","../src/index.tsx"],"sourcesContent":["import {\n CodeComponentMeta,\n default as registerComponent,\n} from \"@plasmicapp/host/registerComponent\";\nimport {\n GlobalContextMeta,\n default as registerGlobalContext,\n} from \"@plasmicapp/host/registerGlobalContext\";\nimport { default as registerToken } from \"@plasmicapp/host/registerToken\";\nimport React from \"react\";\n\nexport type Registerable = {\n registerComponent: typeof registerComponent;\n registerGlobalContext: typeof registerGlobalContext;\n registerToken: typeof registerToken;\n};\n\nexport function makeRegisterComponent<T extends React.ComponentType<any>>(\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n return function (loader?: Registerable) {\n registerComponentHelper(loader, component, meta);\n };\n}\n\nexport function makeRegisterGlobalContext<T extends React.ComponentType<any>>(\n component: T,\n meta: GlobalContextMeta<React.ComponentProps<T>>\n) {\n return function (loader?: Registerable) {\n if (loader) {\n loader.registerGlobalContext(component, meta);\n } else {\n registerGlobalContext(component, meta);\n }\n };\n}\n\nexport function registerComponentHelper<T extends React.ComponentType<any>>(\n loader: Registerable | undefined,\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n if (loader) {\n loader.registerComponent(component, meta);\n } else {\n registerComponent(component, meta);\n }\n}\n\ntype ReactElt = {\n children: ReactElt | ReactElt[];\n props: {\n children: ReactElt | ReactElt[];\n [prop: string]: any;\n } | null;\n type: React.ComponentType<any> | null;\n key: string | null;\n} | null;\n\nexport function traverseReactEltTree(\n children: React.ReactNode,\n callback: (elt: ReactElt) => void\n) {\n const rec = (elts: ReactElt | ReactElt[] | null) => {\n (Array.isArray(elts) ? elts : [elts]).forEach((elt) => {\n if (elt) {\n callback(elt);\n if (elt.children) {\n rec(elt.children);\n }\n if (elt.props?.children && elt.props.children !== elt.children) {\n rec(elt.props.children);\n }\n }\n });\n };\n rec(children as any);\n}\n\nexport function asArray<T>(x: T[] | T | undefined | null) {\n if (Array.isArray(x)) {\n return x;\n } else if (x == null) {\n return [];\n } else {\n return [x];\n }\n}\n","import { Plugin } from \"chart.js/dist/types\";\nimport { useEffect, useState } from \"react\";\n\nexport const baseOptions = {\n responsive: true,\n chartArea: {\n // backgroundColor: \"#f8fafc\",\n },\n};\n\n/**\n * These are hand-picked from the Tailwind palette.\n */\nexport const defaultColors = [\n \"hsla(25,95%,53%,1.0)\",\n \"hsla(38,92%,50%,1.0)\",\n \"hsla(45,93%,47%,1.0)\",\n \"hsla(84,81%,44%,1.0)\",\n \"hsla(142,71%,45%,1.0)\",\n \"hsla(160,84%,39%,1.0)\",\n \"hsla(173,80%,40%,1.0)\",\n \"hsla(199,89%,48%,1.0)\",\n \"hsla(217,91%,60%,1.0)\",\n \"hsla(239,84%,67%,1.0)\",\n \"hsla(258,90%,66%,1.0)\",\n \"hsla(271,91%,65%,1.0)\",\n \"hsla(292,84%,61%,1.0)\",\n \"hsla(293,69%,49%,1.0)\",\n \"hsla(295,72%,40%,1.0)\",\n \"hsla(295,70%,33%,1.0)\",\n];\n\nexport function useIsClient() {\n const [loaded, setLoaded] = useState(false);\n useEffect(() => {\n setLoaded(true);\n });\n return loaded;\n}\n\nexport interface BaseChartProps {\n className?: string;\n data?: Record<string, any>[];\n labelField?: string;\n interactive?: boolean;\n title?: string;\n chosenFields?: string[];\n scatterSeries?: { name: string; fields: [string, string] }[];\n}\n\nexport interface PrepDataOpts {\n isScatter?: boolean;\n preferNonNumericAsLabel?: boolean;\n extras?: (field: string) => {};\n opacity?: number;\n}\n\nfunction range(total: number) {\n return Array.from(Array(total).keys());\n}\n\n/**\n * Returns a color from the default color palette.\n *\n * Tries to pick \"different\" colors that are somewhat spread out on the palette. With a higher 'total' colors requested, the colors will be packed more closely together.\n *\n * We prefer starting from blue when possible. This only starts getting pushed down toward yellow if too many colors requested.\n *\n * If too many colors are requested, it will recycle.\n */\nexport function getDefaultColor(\n index: number,\n total: number,\n opacity?: number\n) {\n const preferredStart = 9;\n const end = defaultColors.length - 1;\n const start = Math.max(0, Math.min(preferredStart, end - total));\n const stops =\n total > defaultColors.length\n ? range(defaultColors.length)\n : range(total).map((_, i) =>\n Math.round(\n start + (total > 1 ? ((1.0 * i) / (total - 1)) * (end - start) : 0)\n )\n );\n const selected = defaultColors[stops[index % stops.length]];\n if (opacity === undefined) {\n return selected;\n }\n return selected.replace(\"1.0\", \"\" + opacity);\n}\n\nexport function prepData(\n { data = [], labelField, chosenFields, scatterSeries }: BaseChartProps,\n { isScatter, preferNonNumericAsLabel, extras, opacity }: PrepDataOpts = {}\n) {\n const fields = Object.keys(data[0] ?? {});\n const isFieldAllNumericOrNil = new Map(\n fields.map((key) => [key, data.every((item) => !isNaN(item[key] ?? 0))])\n );\n const realLabelField =\n labelField ??\n (preferNonNumericAsLabel\n ? fields.find((field) => !isFieldAllNumericOrNil.get(field))\n : fields[0]);\n const numericFields = fields.filter((field) =>\n isFieldAllNumericOrNil.get(field)\n );\n if (isScatter) {\n scatterSeries = isScatter\n ? scatterSeries ?? [\n {\n name: `${numericFields[0]}-${numericFields[1]}`,\n fields: [numericFields[0], numericFields[1]] as [string, string],\n },\n ]\n : undefined;\n return {\n datasets: (scatterSeries ?? []).map((series, index) => ({\n ...extras?.(series.name),\n label: series.name,\n data: data.map((item) => ({\n x: item[series.fields[0]] ?? 0,\n y: item[series.fields[1]] ?? 0,\n })),\n backgroundColor: getDefaultColor(\n index,\n (scatterSeries ?? []).length,\n opacity\n ),\n })),\n };\n } else {\n const autoChosenFields = numericFields.filter(\n (field) => field !== realLabelField\n );\n return {\n labels: realLabelField\n ? data.map((item) => item[realLabelField])\n : undefined,\n datasets: (chosenFields ?? autoChosenFields).map((key, index) => {\n return {\n ...extras?.(key),\n label: key,\n data: data.map((item) => item[key] ?? 0),\n backgroundColor: getDefaultColor(\n index,\n (chosenFields ?? autoChosenFields).length,\n 1\n ),\n borderWidth: 2,\n borderColor: getDefaultColor(\n index,\n (chosenFields ?? autoChosenFields).length,\n 1\n ),\n };\n }),\n };\n }\n}\n\n// additional styling\n\n/*\n elements: {\n bar: {\n borderWidth: 2,\n },\n },\n\n */\n\nexport function prepOptions({ interactive = true, title }: BaseChartProps) {\n return [\n baseOptions,\n interactive\n ? {\n interaction: {\n mode: \"index\" as const,\n intersect: false,\n },\n events: undefined,\n }\n : {\n events: [],\n },\n title\n ? {\n plugins: {\n title: { display: true, text: title },\n },\n }\n : {},\n ];\n}\n\nexport const ChartAreaPlugin: Plugin = {\n id: \"chartAreaPlugin\",\n // eslint-disable-next-line object-shorthand\n beforeDraw: (chart) => {\n const chartAreaOptions = (chart.config.options as any).chartArea;\n if (chartAreaOptions && chartAreaOptions.backgroundColor) {\n const ctx = chart.canvas.getContext(\"2d\");\n const { chartArea } = chart;\n if (ctx) {\n ctx.save();\n ctx.fillStyle = chartAreaOptions.backgroundColor;\n // eslint-disable-next-line max-len\n ctx.fillRect(\n chartArea.left,\n chartArea.top,\n chartArea.right - chartArea.left,\n chartArea.bottom - chartArea.top\n );\n ctx.restore();\n }\n }\n },\n};\n","import {\n BarElement,\n CategoryScale,\n Chart as ChartJS,\n Legend,\n LinearScale,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Bar } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport const stackedOptions = {\n scales: {\n x: {\n stacked: true,\n ticks: {\n major: {\n enabled: false,\n },\n },\n },\n y: {\n stacked: true,\n },\n },\n};\n\nexport const vertOptions = {\n indexAxis: \"x\" as const,\n plugins: {\n legend: {\n position: \"top\" as const,\n },\n },\n};\nexport const horizOptions = {\n indexAxis: \"y\" as const,\n plugins: {\n legend: {\n position: \"right\" as const,\n },\n },\n};\n\nexport interface SimpleBarProps extends BaseChartProps {\n direction?: \"vertical\" | \"horizontal\";\n stacked?: boolean;\n}\n\nexport function SimpleBar(props: SimpleBarProps) {\n const { direction = \"vertical\", stacked, className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n CategoryScale,\n LinearScale,\n BarElement,\n Title,\n Tooltip,\n Legend\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, {\n preferNonNumericAsLabel: true,\n opacity: 1,\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Bar\n key={`${props.direction}${props.stacked}`}\n options={deepmerge.all([\n ...options,\n direction === \"vertical\" ? vertOptions : horizOptions,\n stacked ? stackedOptions : {},\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import {\n CategoryScale,\n Chart as ChartJS,\n Filler,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect, useState } from \"react\";\nimport { Line } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport interface SimpleLineProps extends BaseChartProps {\n fill?: boolean;\n secondAxisField?: string;\n}\n\n// Force a re-mount when the secondAxisField is unset / re-set\n// https://app.shortcut.com/plasmic/story/38358/chart-component-issues-with-second-axis-field\nconst useKey = (secondAxisField?: string) => {\n const [key, setKey] = useState(0);\n\n // change key once when the secondAxisField is unset.\n if (!secondAxisField && key) {\n setKey(0);\n }\n\n // change key once when the secondAxisField value changes from undefined -> something\n if (secondAxisField && !key) {\n setKey(Math.random());\n }\n\n return key;\n};\n\nexport function SimpleLine(props: SimpleLineProps) {\n const { secondAxisField, fill, className } = props;\n const isClient = useIsClient();\n const key = useKey(props.secondAxisField);\n\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n CategoryScale,\n LinearScale,\n PointElement,\n LineElement,\n Title,\n Tooltip,\n Filler,\n Legend\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, {\n extras: (field) => ({\n fill,\n pointRadius: 0,\n yAxisID: field === secondAxisField ? \"y1\" : \"y\",\n }),\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Line\n key={key}\n options={deepmerge.all([\n ...options,\n secondAxisField\n ? {\n scales: {\n y: {\n type: \"linear\" as const,\n display: true,\n position: \"left\" as const,\n },\n y1: {\n type: \"linear\" as const,\n display: true,\n position: \"right\" as const,\n grid: {\n drawOnChartArea: false,\n },\n },\n },\n }\n : {},\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import {\n Chart as ChartJS,\n Legend,\n LinearScale,\n LineElement,\n PointElement,\n Title,\n Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Scatter } from \"react-chartjs-2\";\nimport {\n BaseChartProps,\n ChartAreaPlugin,\n prepData,\n prepOptions,\n useIsClient,\n} from \"../common\";\n\nexport type SimpleScatterProps = BaseChartProps;\n\nexport function SimpleScatter(props: SimpleScatterProps) {\n const { className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\n ChartAreaPlugin,\n LinearScale,\n PointElement,\n LineElement,\n Tooltip,\n Legend,\n Title\n );\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, { isScatter: true, opacity: 1 });\n const options = prepOptions(props);\n\n return (\n <div className={className}>\n <Scatter\n options={deepmerge.all([\n ...options,\n {\n scales: {\n y: {\n beginAtZero: true,\n },\n },\n },\n ])}\n data={normalized}\n />\n </div>\n );\n}\n","import React, { ReactElement } from \"react\";\nimport { SimpleBar, SimpleBarProps } from \"../simple-bar/SimpleBar\";\nimport { SimpleLine, SimpleLineProps } from \"../simple-line/SimpleLine\";\nimport {\n SimpleScatter,\n SimpleScatterProps,\n} from \"../simple-scatter/SimpleScatter\";\n\nexport type SimpleChartProps = {\n type?: \"bar\" | \"line\" | \"scatter\";\n} & (SimpleBarProps | SimpleLineProps | SimpleScatterProps);\n\nexport function SimpleChart(props: SimpleChartProps): ReactElement {\n switch (props.type ?? \"bar\") {\n case \"bar\":\n return <SimpleBar {...(props as any)} />;\n case \"line\":\n return <SimpleLine {...(props as any)} />;\n case \"scatter\":\n return <SimpleScatter {...(props as any)} />;\n }\n}\n","import {\n CodeComponentMeta,\n PropType,\n} from \"@plasmicapp/host/registerComponent\";\nimport { Registerable, registerComponentHelper } from \"../utils\";\nimport { SimpleChart, SimpleChartProps } from \"./SimpleChart\";\n\nexport * from \"./SimpleChart\";\nexport default SimpleChart;\n\nconst fieldChoice: PropType<SimpleChartProps> = {\n type: \"choice\",\n options: (props: SimpleChartProps) =>\n props.data?.[0] ? Object.keys(props.data[0]) : [],\n} as const;\nconst simpleChartMeta: CodeComponentMeta<SimpleChartProps> = {\n name: \"hostless-react-chartjs-2-simple-chart\",\n displayName: \"Chart\",\n props: {\n type: {\n type: \"choice\",\n options: [\n {\n value: \"bar\",\n label: \"Bar\",\n },\n {\n value: \"line\",\n label: \"Line\",\n },\n {\n value: \"scatter\",\n label: \"Scatter\",\n },\n ],\n defaultValueHint: \"bar\",\n },\n data: {\n type: \"exprEditor\",\n description: \"The data as an array of objects\",\n defaultExpr: JSON.stringify([\n {\n region: \"APAC\",\n revenue: 3294,\n spend: 2675,\n },\n {\n region: \"EMEA\",\n revenue: 3245,\n spend: 3895,\n },\n {\n region: \"LATAM\",\n revenue: 2165,\n spend: 3498,\n },\n {\n region: \"AMER\",\n revenue: 3215,\n spend: 1656,\n },\n ]),\n },\n labelField: {\n ...fieldChoice,\n hidden: (props) => props.type === \"scatter\",\n },\n title: \"string\",\n interactive: {\n type: \"boolean\",\n defaultValueHint: true,\n },\n // Bar chart\n direction: {\n type: \"choice\",\n options: [\"horizontal\", \"vertical\"].map((dir) => ({\n value: dir,\n label: dir[0].toUpperCase() + dir.slice(1),\n })),\n defaultValueHint: \"Vertical\",\n hidden: ({ type = \"bar\" }) => type !== \"bar\",\n },\n stacked: {\n type: \"boolean\",\n hidden: ({ type = \"bar\" }) => type !== \"bar\",\n },\n // Line chart\n fill: {\n type: \"boolean\",\n hidden: (props) => props.type !== \"line\",\n },\n secondAxisField: {\n ...fieldChoice,\n hidden: (props) => props.type !== \"line\",\n },\n\n // TODO\n // datasets: {\n // type: \"array\",\n // unstable__keyFunc: (x) => x.key,\n // unstable__minimalValue: (_props, ctx) => null,\n // itemType: {\n // type: \"object\",\n // fields: {\n // label: \"string\",\n // fieldId: \"string\",\n // hidden: {\n // type: \"boolean\",\n // },\n // },\n // },\n // },\n },\n\n defaultStyles: {\n width: \"stretch\",\n },\n\n importName: \"SimpleChart\",\n importPath: \"@plasmicpkgs/react-chartjs-2\",\n};\n\nexport function registerSimpleChart(loader?: Registerable) {\n registerComponentHelper(loader, SimpleChart, simpleChartMeta);\n}\n","import { registerSimpleChart } from \"./simple-chart\";\nimport { Registerable } from \"./utils\";\n\nexport { SimpleChart } from \"./simple-chart\";\n\nexport function registerAll(loader?: Registerable) {\n registerSimpleChart(loader);\n}\n"],"names":["registerComponentHelper","loader","component","meta","registerComponent","baseOptions","responsive","chartArea","defaultColors","useIsClient","_useState","useState","loaded","setLoaded","useEffect","range","total","Array","from","keys","getDefaultColor","index","opacity","preferredStart","end","length","start","Math","max","min","stops","map","_","i","round","selected","undefined","replace","prepData","_ref","_temp","data","_ref$data","labelField","chosenFields","scatterSeries","_ref2","isScatter","preferNonNumericAsLabel","extras","fields","Object","_data$","isFieldAllNumericOrNil","Map","key","every","item","_item$key","isNaN","realLabelField","find","field","get","numericFields","filter","name","datasets","series","_extends","label","_item$series$fields$","_item$series$fields$2","x","y","backgroundColor","autoChosenFields","labels","_item$key2","borderWidth","borderColor","prepOptions","_ref3","interactive","_ref3$interactive","title","interaction","mode","intersect","events","plugins","display","text","ChartAreaPlugin","id","beforeDraw","chart","chartAreaOptions","config","options","ctx","canvas","getContext","save","fillStyle","fillRect","left","top","right","bottom","restore","stackedOptions","scales","stacked","ticks","major","enabled","vertOptions","indexAxis","legend","position","horizOptions","SimpleBar","props","_props$direction","direction","className","isClient","ChartJS","register","CategoryScale","LinearScale","BarElement","Title","Tooltip","Legend","normalized","React","Bar","deepmerge","all","concat","useKey","secondAxisField","setKey","random","SimpleLine","fill","PointElement","LineElement","Filler","pointRadius","yAxisID","Line","type","y1","grid","drawOnChartArea","SimpleScatter","Scatter","beginAtZero","SimpleChart","_props$type","fieldChoice","_props$data","simpleChartMeta","displayName","value","defaultValueHint","description","defaultExpr","JSON","stringify","region","revenue","spend","hidden","dir","toUpperCase","slice","_ref$type","_ref2$type","defaultStyles","width","importName","importPath","registerSimpleChart","registerAll"],"mappings":";;;;;;;;;;;;;;;;;SAuCgBA,uBAAuBA,CACrCC,MAAgC,EAChCC,SAAY,EACZC,IAAgD;EAEhD,IAAIF,MAAM,EAAE;IACVA,MAAM,CAACG,iBAAiB,CAACF,SAAS,EAAEC,IAAI,CAAC;GAC1C,MAAM;IACLC,iBAAiB,CAACF,SAAS,EAAEC,IAAI,CAAC;;AAEtC;;AC9CO,IAAME,WAAW,GAAG;EACzBC,UAAU,EAAE,IAAI;EAChBC,SAAS,EAAE;;;CAGZ;AAED;;;AAGA,AAAO,IAAMC,aAAa,GAAG,CAC3B,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,CACxB;AAED,SAAgBC,WAAWA;EACzB,IAAAC,SAAA,GAA4BC,QAAQ,CAAC,KAAK,CAAC;IAApCC,MAAM,GAAAF,SAAA;IAAEG,SAAS,GAAAH,SAAA;EACxBI,SAAS,CAAC;IACRD,SAAS,CAAC,IAAI,CAAC;GAChB,CAAC;EACF,OAAOD,MAAM;AACf;AAmBA,SAASG,KAAKA,CAACC,KAAa;EAC1B,OAAOC,KAAK,CAACC,IAAI,CAACD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B,EAAE,UAAU;MAC5BQ,MAAM,EAAE,SAARA,MAAMA,CAAAzI,IAAA;QAAA,IAAA6I,SAAA,GAAA7I,IAAA,CAAKmH,IAAI;UAAJA,IAAI,GAAA0B,SAAA,cAAG,KAAK,GAAAA,SAAA;QAAA,OAAO1B,IAAI,KAAK,KAAK;;KAC7C;IACDzC,OAAO,EAAE;MACPyC,IAAI,EAAE,SAAS;MACfsB,MAAM,EAAE,SAARA,MAAMA,CAAAlI,KAAA;QAAA,IAAAuI,UAAA,GAAAvI,KAAA,CAAK4G,IAAI;UAAJA,IAAI,GAAA2B,UAAA,cAAG,KAAK,GAAAA,UAAA;QAAA,OAAO3B,IAAI,KAAK,KAAK;;KAC7C;;IAEDP,IAAI,EAAE;MACJO,IAAI,EAAE,SAAS;MACfsB,MAAM,EAAE,SAARA,MAAMA,CAAGrD,KAAK;QAAA,OAAKA,KAAK,CAAC+B,IAAI,KAAK,MAAM;;KACzC;IACDX,eAAe,eAAA1E,QAAA,KACV8F,WAAW;MACda,MAAM,EAAE,SAARA,MAAMA,CAAGrD,KAAK;QAAA,OAAKA,KAAK,CAAC+B,IAAI,KAAK,MAAM;;;;;;;;;;;;;;;;;;;GAmB3C;EAED4B,aAAa,EAAE;IACbC,KAAK,EAAE;GACR;EAEDC,UAAU,EAAE,aAAa;EACzBC,UAAU,EAAE;CACb;AAED,SAAgBC,mBAAmBA,CAACzL,MAAqB;EACvDD,uBAAuB,CAACC,MAAM,EAAEgK,WAAW,EAAEI,eAAe,CAAC;AAC/D;;SCvHgBsB,WAAWA,CAAC1L,MAAqB;EAC/CyL,mBAAmB,CAACzL,MAAM,CAAC;AAC7B;;;;"}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { BaseChartProps } from "../common";
|
|
3
|
-
export declare const stackedOptions: {
|
|
4
|
-
scales: {
|
|
5
|
-
x: {
|
|
6
|
-
stacked: boolean;
|
|
7
|
-
ticks: {
|
|
8
|
-
major: {
|
|
9
|
-
enabled: boolean;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
y: {
|
|
14
|
-
stacked: boolean;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export declare const vertOptions: {
|
|
19
|
-
indexAxis: "x";
|
|
20
|
-
plugins: {
|
|
21
|
-
legend: {
|
|
22
|
-
position: "top";
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
export declare const horizOptions: {
|
|
27
|
-
indexAxis: "y";
|
|
28
|
-
plugins: {
|
|
29
|
-
legend: {
|
|
30
|
-
position: "right";
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
export interface SimpleBarProps extends BaseChartProps {
|
|
35
|
-
direction?: "vertical" | "horizontal";
|
|
36
|
-
stacked?: boolean;
|
|
37
|
-
}
|
|
38
|
-
export declare function SimpleBar(props: SimpleBarProps): React.JSX.Element | null;
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { BaseChartProps } from "../common";
|
|
3
|
+
export declare const stackedOptions: {
|
|
4
|
+
scales: {
|
|
5
|
+
x: {
|
|
6
|
+
stacked: boolean;
|
|
7
|
+
ticks: {
|
|
8
|
+
major: {
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
y: {
|
|
14
|
+
stacked: boolean;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare const vertOptions: {
|
|
19
|
+
indexAxis: "x";
|
|
20
|
+
plugins: {
|
|
21
|
+
legend: {
|
|
22
|
+
position: "top";
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export declare const horizOptions: {
|
|
27
|
+
indexAxis: "y";
|
|
28
|
+
plugins: {
|
|
29
|
+
legend: {
|
|
30
|
+
position: "right";
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export interface SimpleBarProps extends BaseChartProps {
|
|
35
|
+
direction?: "vertical" | "horizontal";
|
|
36
|
+
stacked?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export declare function SimpleBar(props: SimpleBarProps): React.JSX.Element | null;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ReactElement } from "react";
|
|
2
|
-
import { SimpleBarProps } from "../simple-bar/SimpleBar";
|
|
3
|
-
import { SimpleLineProps } from "../simple-line/SimpleLine";
|
|
4
|
-
import { SimpleScatterProps } from "../simple-scatter/SimpleScatter";
|
|
5
|
-
export
|
|
6
|
-
type?: "bar" | "line" | "scatter";
|
|
7
|
-
} & (SimpleBarProps | SimpleLineProps | SimpleScatterProps);
|
|
8
|
-
export declare function SimpleChart(props: SimpleChartProps): ReactElement;
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
import { SimpleBarProps } from "../simple-bar/SimpleBar";
|
|
3
|
+
import { SimpleLineProps } from "../simple-line/SimpleLine";
|
|
4
|
+
import { SimpleScatterProps } from "../simple-scatter/SimpleScatter";
|
|
5
|
+
export type SimpleChartProps = {
|
|
6
|
+
type?: "bar" | "line" | "scatter";
|
|
7
|
+
} & (SimpleBarProps | SimpleLineProps | SimpleScatterProps);
|
|
8
|
+
export declare function SimpleChart(props: SimpleChartProps): ReactElement;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Registerable } from "../utils";
|
|
2
|
-
import { SimpleChart } from "./SimpleChart";
|
|
3
|
-
export * from "./SimpleChart";
|
|
4
|
-
export default SimpleChart;
|
|
5
|
-
export declare function registerSimpleChart(loader?: Registerable): void;
|
|
1
|
+
import { Registerable } from "../utils";
|
|
2
|
+
import { SimpleChart } from "./SimpleChart";
|
|
3
|
+
export * from "./SimpleChart";
|
|
4
|
+
export default SimpleChart;
|
|
5
|
+
export declare function registerSimpleChart(loader?: Registerable): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { BaseChartProps } from "../common";
|
|
3
|
-
export interface SimpleLineProps extends BaseChartProps {
|
|
4
|
-
fill?: boolean;
|
|
5
|
-
secondAxisField?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare function SimpleLine(props: SimpleLineProps): React.JSX.Element | null;
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { BaseChartProps } from "../common";
|
|
3
|
+
export interface SimpleLineProps extends BaseChartProps {
|
|
4
|
+
fill?: boolean;
|
|
5
|
+
secondAxisField?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function SimpleLine(props: SimpleLineProps): React.JSX.Element | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { BaseChartProps } from "../common";
|
|
3
|
-
export
|
|
4
|
-
export declare function SimpleScatter(props: SimpleScatterProps): React.JSX.Element | null;
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { BaseChartProps } from "../common";
|
|
3
|
+
export type SimpleScatterProps = BaseChartProps;
|
|
4
|
+
export declare function SimpleScatter(props: SimpleScatterProps): React.JSX.Element | null;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { CodeComponentMeta, default as registerComponent } from "@plasmicapp/host/registerComponent";
|
|
2
|
-
import { GlobalContextMeta, default as registerGlobalContext } from "@plasmicapp/host/registerGlobalContext";
|
|
3
|
-
import { default as registerToken } from "@plasmicapp/host/registerToken";
|
|
4
|
-
import React from "react";
|
|
5
|
-
export
|
|
6
|
-
registerComponent: typeof registerComponent;
|
|
7
|
-
registerGlobalContext: typeof registerGlobalContext;
|
|
8
|
-
registerToken: typeof registerToken;
|
|
9
|
-
};
|
|
10
|
-
export declare function makeRegisterComponent<T extends React.ComponentType<any>>(component: T, meta: CodeComponentMeta<React.ComponentProps<T>>): (loader?: Registerable
|
|
11
|
-
export declare function makeRegisterGlobalContext<T extends React.ComponentType<any>>(component: T, meta: GlobalContextMeta<React.ComponentProps<T>>): (loader?: Registerable
|
|
12
|
-
export declare function registerComponentHelper<T extends React.ComponentType<any>>(loader: Registerable | undefined, component: T, meta: CodeComponentMeta<React.ComponentProps<T>>): void;
|
|
13
|
-
|
|
14
|
-
children: ReactElt | ReactElt[];
|
|
15
|
-
props: {
|
|
16
|
-
children: ReactElt | ReactElt[];
|
|
17
|
-
[prop: string]: any;
|
|
18
|
-
} | null;
|
|
19
|
-
type: React.ComponentType<any> | null;
|
|
20
|
-
key: string | null;
|
|
21
|
-
} | null;
|
|
22
|
-
export declare function traverseReactEltTree(children: React.ReactNode, callback: (elt: ReactElt) => void): void;
|
|
23
|
-
export declare function asArray<T>(x: T[] | T | undefined | null): T[];
|
|
24
|
-
export {};
|
|
1
|
+
import { CodeComponentMeta, default as registerComponent } from "@plasmicapp/host/registerComponent";
|
|
2
|
+
import { GlobalContextMeta, default as registerGlobalContext } from "@plasmicapp/host/registerGlobalContext";
|
|
3
|
+
import { default as registerToken } from "@plasmicapp/host/registerToken";
|
|
4
|
+
import React from "react";
|
|
5
|
+
export type Registerable = {
|
|
6
|
+
registerComponent: typeof registerComponent;
|
|
7
|
+
registerGlobalContext: typeof registerGlobalContext;
|
|
8
|
+
registerToken: typeof registerToken;
|
|
9
|
+
};
|
|
10
|
+
export declare function makeRegisterComponent<T extends React.ComponentType<any>>(component: T, meta: CodeComponentMeta<React.ComponentProps<T>>): (loader?: Registerable) => void;
|
|
11
|
+
export declare function makeRegisterGlobalContext<T extends React.ComponentType<any>>(component: T, meta: GlobalContextMeta<React.ComponentProps<T>>): (loader?: Registerable) => void;
|
|
12
|
+
export declare function registerComponentHelper<T extends React.ComponentType<any>>(loader: Registerable | undefined, component: T, meta: CodeComponentMeta<React.ComponentProps<T>>): void;
|
|
13
|
+
type ReactElt = {
|
|
14
|
+
children: ReactElt | ReactElt[];
|
|
15
|
+
props: {
|
|
16
|
+
children: ReactElt | ReactElt[];
|
|
17
|
+
[prop: string]: any;
|
|
18
|
+
} | null;
|
|
19
|
+
type: React.ComponentType<any> | null;
|
|
20
|
+
key: string | null;
|
|
21
|
+
} | null;
|
|
22
|
+
export declare function traverseReactEltTree(children: React.ReactNode, callback: (elt: ReactElt) => void): void;
|
|
23
|
+
export declare function asArray<T>(x: T[] | T | undefined | null): T[];
|
|
24
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicpkgs/react-chartjs-2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.160",
|
|
4
4
|
"description": "Chart.js 2.x components for React",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsdx build",
|
|
23
23
|
"start": "tsdx watch",
|
|
24
|
-
"test": "TEST_CWD=`pwd`
|
|
24
|
+
"test": "TEST_CWD=`pwd` pnpm -w test --passWithNoTests",
|
|
25
25
|
"lint": "tsdx lint",
|
|
26
26
|
"prepublishOnly": "npm run build",
|
|
27
27
|
"size": "size-limit",
|
|
28
28
|
"analyze": "size-limit --why"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@plasmicapp/host": "2.0.
|
|
31
|
+
"@plasmicapp/host": "2.0.7",
|
|
32
32
|
"@types/node": "^14.0.26",
|
|
33
33
|
"@types/react": "^18",
|
|
34
34
|
"chart.js": "^4.2.1",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"deepmerge": "^4.3.1"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "6087f1621240c66b20d4a8fcf02c8bf889c554aa"
|
|
53
53
|
}
|