@plasmicpkgs/react-chartjs-2 1.0.1

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Plasmic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ Chart.js 2.x components for React
@@ -0,0 +1,57 @@
1
+ export declare const defaultColors: string[];
2
+ export declare function useIsClient(): boolean;
3
+ export interface BaseChartProps {
4
+ className?: string;
5
+ data?: Record<string, any>[];
6
+ labelField?: string;
7
+ interactive?: boolean;
8
+ title?: string;
9
+ chosenFields?: string[];
10
+ scatterSeries?: {
11
+ name: string;
12
+ fields: [string, string];
13
+ }[];
14
+ }
15
+ export interface PrepDataOpts {
16
+ isScatter?: boolean;
17
+ preferNonNumericAsLabel?: boolean;
18
+ extras?: (field: string) => {};
19
+ opacity?: number;
20
+ }
21
+ export declare function getDefaultColor(index: number, opacity?: number): string;
22
+ export declare function prepData({ data, labelField, chosenFields, scatterSeries }: BaseChartProps, { isScatter, preferNonNumericAsLabel, extras, opacity }?: PrepDataOpts): {
23
+ datasets: {
24
+ label: string;
25
+ data: {
26
+ x: any;
27
+ y: any;
28
+ }[];
29
+ backgroundColor: string;
30
+ }[];
31
+ labels?: undefined;
32
+ } | {
33
+ labels: any[] | undefined;
34
+ datasets: {
35
+ label: string;
36
+ data: any[];
37
+ backgroundColor: string;
38
+ }[];
39
+ };
40
+ export declare function prepOptions({ interactive, title }: BaseChartProps): ({
41
+ responsive: boolean;
42
+ } | {
43
+ interaction: {
44
+ mode: "index";
45
+ intersect: boolean;
46
+ };
47
+ title?: undefined;
48
+ } | {
49
+ interaction?: undefined;
50
+ title?: undefined;
51
+ } | {
52
+ title: {
53
+ display: boolean;
54
+ text: string;
55
+ };
56
+ interaction?: undefined;
57
+ })[];
@@ -0,0 +1,2 @@
1
+ import { Registerable } from "./utils";
2
+ export declare function registerAll(loader?: Registerable): void;
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./react-chartjs-2.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./react-chartjs-2.cjs.development.js')
8
+ }
@@ -0,0 +1,357 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
+
7
+ var registerComponent = _interopDefault(require('@plasmicapp/host/registerComponent'));
8
+ require('@plasmicapp/host/registerGlobalContext');
9
+ var React = require('react');
10
+ var React__default = _interopDefault(React);
11
+ var chart_js = require('chart.js');
12
+ var deepmerge = _interopDefault(require('deepmerge'));
13
+ var reactChartjs2 = require('react-chartjs-2');
14
+
15
+ function registerComponentHelper(loader, component, meta) {
16
+ if (loader) {
17
+ loader.registerComponent(component, meta);
18
+ } else {
19
+ registerComponent(component, meta);
20
+ }
21
+ }
22
+
23
+ function _extends() {
24
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
25
+ for (var i = 1; i < arguments.length; i++) {
26
+ var source = arguments[i];
27
+ for (var key in source) {
28
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
29
+ target[key] = source[key];
30
+ }
31
+ }
32
+ }
33
+ return target;
34
+ };
35
+ return _extends.apply(this, arguments);
36
+ }
37
+
38
+ var defaultColors = ["rgba(255, 99, 132, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(255, 206, 86, 0.2)", "rgba(75, 192, 192, 0.2)", "rgba(153, 102, 255, 0.2)", "rgba(255, 159, 64, 0.2)"];
39
+ function useIsClient() {
40
+ var _useState = React.useState(false),
41
+ loaded = _useState[0],
42
+ setLoaded = _useState[1];
43
+ React.useEffect(function () {
44
+ setLoaded(true);
45
+ });
46
+ return loaded;
47
+ }
48
+ function getDefaultColor(index, opacity) {
49
+ if (opacity === void 0) {
50
+ opacity = 0.2;
51
+ }
52
+ return defaultColors[index % defaultColors.length].replace("0.2", "" + opacity);
53
+ }
54
+ function prepData(_ref, _temp) {
55
+ var _data$;
56
+ var _ref$data = _ref.data,
57
+ data = _ref$data === void 0 ? [] : _ref$data,
58
+ labelField = _ref.labelField,
59
+ chosenFields = _ref.chosenFields,
60
+ scatterSeries = _ref.scatterSeries;
61
+ var _ref2 = _temp === void 0 ? {} : _temp,
62
+ isScatter = _ref2.isScatter,
63
+ preferNonNumericAsLabel = _ref2.preferNonNumericAsLabel,
64
+ extras = _ref2.extras,
65
+ opacity = _ref2.opacity;
66
+ var fields = Object.keys((_data$ = data[0]) != null ? _data$ : {});
67
+ var isFieldAllNumericOrNil = new Map(fields.map(function (key) {
68
+ return [key, data.every(function (item) {
69
+ var _item$key;
70
+ return !isNaN((_item$key = item[key]) != null ? _item$key : 0);
71
+ })];
72
+ }));
73
+ var realLabelField = labelField != null ? labelField : preferNonNumericAsLabel ? fields.find(function (field) {
74
+ return !isFieldAllNumericOrNil.get(field);
75
+ }) : fields[0];
76
+ var numericFields = fields.filter(function (field) {
77
+ return isFieldAllNumericOrNil.get(field);
78
+ });
79
+ if (isScatter) {
80
+ var _scatterSeries, _scatterSeries2;
81
+ scatterSeries = isScatter ? (_scatterSeries = scatterSeries) != null ? _scatterSeries : [{
82
+ name: numericFields[0] + "-" + numericFields[1],
83
+ fields: [numericFields[0], numericFields[1]]
84
+ }] : undefined;
85
+ return {
86
+ datasets: ((_scatterSeries2 = scatterSeries) != null ? _scatterSeries2 : []).map(function (series, index) {
87
+ return _extends({}, extras == null ? void 0 : extras(series.name), {
88
+ label: series.name,
89
+ data: data.map(function (item) {
90
+ var _item$series$fields$, _item$series$fields$2;
91
+ return {
92
+ x: (_item$series$fields$ = item[series.fields[0]]) != null ? _item$series$fields$ : 0,
93
+ y: (_item$series$fields$2 = item[series.fields[1]]) != null ? _item$series$fields$2 : 0
94
+ };
95
+ }),
96
+ backgroundColor: getDefaultColor(index, opacity)
97
+ });
98
+ })
99
+ };
100
+ } else {
101
+ var autoChosenFields = numericFields.filter(function (field) {
102
+ return field !== realLabelField;
103
+ });
104
+ return {
105
+ labels: realLabelField ? data.map(function (item) {
106
+ return item[realLabelField];
107
+ }) : undefined,
108
+ datasets: (chosenFields != null ? chosenFields : autoChosenFields).map(function (key, index) {
109
+ return _extends({}, extras == null ? void 0 : extras(key), {
110
+ label: key,
111
+ data: data.map(function (item) {
112
+ var _item$key2;
113
+ return (_item$key2 = item[key]) != null ? _item$key2 : 0;
114
+ }),
115
+ backgroundColor: getDefaultColor(index, opacity)
116
+ });
117
+ })
118
+ };
119
+ }
120
+ }
121
+ // additional styling
122
+ /*
123
+ elements: {
124
+ bar: {
125
+ borderWidth: 2,
126
+ },
127
+ },
128
+
129
+ */
130
+ function prepOptions(_ref3) {
131
+ var _ref3$interactive = _ref3.interactive,
132
+ interactive = _ref3$interactive === void 0 ? true : _ref3$interactive,
133
+ title = _ref3.title;
134
+ return [baseOptions, interactive ? {
135
+ interaction: {
136
+ mode: "index",
137
+ intersect: false
138
+ }
139
+ } : {}, title ? {
140
+ title: {
141
+ display: true,
142
+ text: title
143
+ }
144
+ } : {}];
145
+ }
146
+
147
+ var baseOptions = {
148
+ responsive: true
149
+ };
150
+ var stackedOptions = {
151
+ scales: {
152
+ x: {
153
+ stacked: true
154
+ },
155
+ y: {
156
+ stacked: true
157
+ }
158
+ }
159
+ };
160
+ var vertOptions = {
161
+ plugins: {
162
+ legend: {
163
+ position: "top"
164
+ }
165
+ }
166
+ };
167
+ var horizOptions = {
168
+ indexAxis: "y",
169
+ plugins: {
170
+ legend: {
171
+ position: "right"
172
+ }
173
+ }
174
+ };
175
+ function SimpleBar(props) {
176
+ var _props$direction = props.direction,
177
+ direction = _props$direction === void 0 ? "vertical" : _props$direction,
178
+ stacked = props.stacked,
179
+ className = props.className;
180
+ var isClient = useIsClient();
181
+ React.useEffect(function () {
182
+ chart_js.Chart.register(chart_js.CategoryScale, chart_js.LinearScale, chart_js.BarElement, chart_js.Title, chart_js.Tooltip, chart_js.Legend);
183
+ }, []);
184
+ if (!isClient) {
185
+ return null;
186
+ }
187
+ var normalized = prepData(props, {
188
+ preferNonNumericAsLabel: true,
189
+ opacity: 0.5
190
+ });
191
+ var options = prepOptions(props);
192
+ return React__default.createElement("div", {
193
+ className: className
194
+ }, React__default.createElement(reactChartjs2.Bar, {
195
+ options: deepmerge.all([].concat(options, [direction === "vertical" ? vertOptions : horizOptions, stacked ? stackedOptions : {}])),
196
+ data: normalized
197
+ }));
198
+ }
199
+
200
+ function SimpleLine(props) {
201
+ var secondAxisField = props.secondAxisField,
202
+ fill = props.fill,
203
+ className = props.className;
204
+ var isClient = useIsClient();
205
+ React.useEffect(function () {
206
+ chart_js.Chart.register(chart_js.CategoryScale, chart_js.LinearScale, chart_js.PointElement, chart_js.LineElement, chart_js.Title, chart_js.Tooltip, chart_js.Filler, chart_js.Legend);
207
+ }, []);
208
+ if (!isClient) {
209
+ return null;
210
+ }
211
+ var normalized = prepData(props, {
212
+ extras: function extras(field) {
213
+ return {
214
+ fill: fill,
215
+ yAxisID: field === secondAxisField ? "y1" : "y"
216
+ };
217
+ }
218
+ });
219
+ var options = prepOptions(props);
220
+ return React__default.createElement("div", {
221
+ className: className
222
+ }, React__default.createElement(reactChartjs2.Line, {
223
+ options: deepmerge.all([].concat(options, [secondAxisField ? {
224
+ scales: {
225
+ y: {
226
+ type: "linear",
227
+ display: true,
228
+ position: "left"
229
+ },
230
+ y1: {
231
+ type: "linear",
232
+ display: true,
233
+ position: "right",
234
+ grid: {
235
+ drawOnChartArea: false
236
+ }
237
+ }
238
+ }
239
+ } : {}])),
240
+ data: normalized
241
+ }));
242
+ }
243
+
244
+ function SimpleScatter(props) {
245
+ var className = props.className;
246
+ var isClient = useIsClient();
247
+ React.useEffect(function () {
248
+ chart_js.Chart.register(chart_js.LinearScale, chart_js.PointElement, chart_js.LineElement, chart_js.Tooltip, chart_js.Legend);
249
+ }, []);
250
+ if (!isClient) {
251
+ return null;
252
+ }
253
+ var normalized = prepData(props, {
254
+ isScatter: true,
255
+ opacity: 1
256
+ });
257
+ var options = prepOptions(props);
258
+ console.log("!!", normalized, options);
259
+ return React__default.createElement("div", {
260
+ className: className
261
+ }, React__default.createElement(reactChartjs2.Scatter, {
262
+ options: deepmerge.all([].concat(options, [{
263
+ scales: {
264
+ y: {
265
+ beginAtZero: true
266
+ }
267
+ }
268
+ }])),
269
+ data: normalized
270
+ }));
271
+ }
272
+
273
+ function SimpleChart(props) {
274
+ var _props$type;
275
+ switch ((_props$type = props.type) != null ? _props$type : "bar") {
276
+ case "bar":
277
+ return React__default.createElement(SimpleBar, Object.assign({}, props));
278
+ case "line":
279
+ return React__default.createElement(SimpleLine, Object.assign({}, props));
280
+ case "scatter":
281
+ return React__default.createElement(SimpleScatter, Object.assign({}, props));
282
+ }
283
+ }
284
+
285
+ var simpleChartMeta = {
286
+ name: "hostless-react-chartjs-2-simple-chart",
287
+ displayName: "Chart",
288
+ props: {
289
+ type: {
290
+ type: "choice",
291
+ options: [{
292
+ value: "bar",
293
+ label: "Bar"
294
+ }, {
295
+ value: "line",
296
+ label: "Line"
297
+ }, {
298
+ value: "scatter",
299
+ label: "Scatter"
300
+ }],
301
+ defaultValueHint: "bar"
302
+ },
303
+ data: {
304
+ type: "exprEditor",
305
+ description: "The data as an array of objects",
306
+ defaultExpr: /*#__PURE__*/JSON.stringify([{
307
+ region: "APAC",
308
+ revenue: 3294,
309
+ spend: 2675
310
+ }, {
311
+ region: "EMEA",
312
+ revenue: 3245,
313
+ spend: 3895
314
+ }, {
315
+ region: "LATAM",
316
+ revenue: 2165,
317
+ spend: 3498
318
+ }, {
319
+ region: "AMER",
320
+ revenue: 3215,
321
+ spend: 1656
322
+ }])
323
+ },
324
+ labelField: {
325
+ type: "choice",
326
+ hidden: function hidden(props) {
327
+ return props.type === "scatter";
328
+ },
329
+ options: function options(props) {
330
+ var _props$data;
331
+ return (_props$data = props.data) != null && _props$data[0] ? Object.keys(props.data[0]) : [];
332
+ }
333
+ },
334
+ title: "string",
335
+ fill: {
336
+ type: "boolean",
337
+ hidden: function hidden(props) {
338
+ return props.type !== "line";
339
+ }
340
+ }
341
+ },
342
+ defaultStyles: {
343
+ width: "stretch"
344
+ },
345
+ importName: "SimpleChart",
346
+ importPath: "@plasmicpkgs/react-chartjs-2/dist/simple-chart/SimpleChart"
347
+ };
348
+ function registerSimpleChart(loader) {
349
+ registerComponentHelper(loader, SimpleChart, simpleChartMeta);
350
+ }
351
+
352
+ function registerAll(loader) {
353
+ registerSimpleChart(loader);
354
+ }
355
+
356
+ exports.registerAll = registerAll;
357
+ //# sourceMappingURL=react-chartjs-2.cjs.development.js.map
@@ -0,0 +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 ComponentMeta,\n default as registerComponent,\n} from \"@plasmicapp/host/registerComponent\";\nimport {\n default as registerGlobalContext,\n GlobalContextMeta,\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: ComponentMeta<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: ComponentMeta<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 { useEffect, useState } from \"react\";\nimport { baseOptions } from \"./simple-bar/SimpleBar\";\n\nexport const defaultColors = [\n \"rgba(255, 99, 132, 0.2)\",\n \"rgba(54, 162, 235, 0.2)\",\n \"rgba(255, 206, 86, 0.2)\",\n \"rgba(75, 192, 192, 0.2)\",\n \"rgba(153, 102, 255, 0.2)\",\n \"rgba(255, 159, 64, 0.2)\",\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\nexport function getDefaultColor(index: number, opacity = 0.2) {\n return defaultColors[index % defaultColors.length].replace(\n \"0.2\",\n \"\" + opacity\n );\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(index, opacity),\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(index, opacity),\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 }\n : {},\n title ? { title: { display: true, text: title } } : {},\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 { BaseChartProps, prepData, prepOptions, useIsClient } from \"../common\";\n\nexport const baseOptions = {\n responsive: true,\n};\n\nexport const stackedOptions = {\n scales: {\n x: {\n stacked: true,\n },\n y: {\n stacked: true,\n },\n },\n};\n\nexport const vertOptions = {\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 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: 0.5,\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Bar\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 } from \"react\";\nimport { Line } from \"react-chartjs-2\";\nimport { BaseChartProps, prepData, prepOptions, useIsClient } from \"../common\";\n\nexport interface SimpleLineProps extends BaseChartProps {\n fill?: boolean;\n secondAxisField?: string;\n}\n\nexport function SimpleLine(props: SimpleLineProps) {\n const { secondAxisField, fill, className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\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 yAxisID: field === secondAxisField ? \"y1\" : \"y\",\n }),\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Line\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 Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Scatter } from \"react-chartjs-2\";\nimport { BaseChartProps, prepData, prepOptions, useIsClient } from \"../common\";\n\nexport interface SimpleScatterProps extends BaseChartProps {}\n\nexport function SimpleScatter(props: SimpleScatterProps) {\n const { className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(LinearScale, PointElement, LineElement, Tooltip, Legend);\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, { isScatter: true, opacity: 1 });\n const options = prepOptions(props);\n console.log(\"!!\", normalized, options);\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 { ComponentMeta } from \"@plasmicapp/host/registerComponent\";\nimport { Registerable, registerComponentHelper } from \"../utils\";\nimport { SimpleChart, SimpleChartProps } from \"./SimpleChart\";\n\nexport * from \"./SimpleChart\";\nexport default SimpleChart;\n\nconst simpleChartMeta: ComponentMeta<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\" as any,\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 type: \"choice\",\n hidden: (props) => props.type === \"scatter\",\n options: (props) => (props.data?.[0] ? Object.keys(props.data[0]) : []),\n },\n title: \"string\",\n fill: {\n type: \"boolean\",\n hidden: (props) => props.type !== \"line\",\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/dist/simple-chart/SimpleChart\",\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 function registerAll(loader?: Registerable) {\n registerSimpleChart(loader);\n}\n"],"names":["registerComponentHelper","loader","component","meta","registerComponent","defaultColors","useIsClient","useState","loaded","setLoaded","useEffect","getDefaultColor","index","opacity","length","replace","prepData","data","labelField","chosenFields","scatterSeries","isScatter","preferNonNumericAsLabel","extras","fields","Object","keys","isFieldAllNumericOrNil","Map","map","key","every","item","isNaN","realLabelField","find","field","get","numericFields","filter","name","undefined","datasets","series","label","x","y","backgroundColor","autoChosenFields","labels","prepOptions","interactive","title","baseOptions","interaction","mode","intersect","display","text","responsive","stackedOptions","scales","stacked","vertOptions","plugins","legend","position","horizOptions","indexAxis","SimpleBar","props","direction","className","isClient","ChartJS","register","CategoryScale","LinearScale","BarElement","Title","Tooltip","Legend","normalized","options","React","Bar","deepmerge","all","SimpleLine","secondAxisField","fill","PointElement","LineElement","Filler","yAxisID","Line","type","y1","grid","drawOnChartArea","SimpleScatter","console","log","Scatter","beginAtZero","SimpleChart","simpleChartMeta","displayName","value","defaultValueHint","description","defaultExpr","JSON","stringify","region","revenue","spend","hidden","defaultStyles","width","importName","importPath","registerSimpleChart","registerAll"],"mappings":";;;;;;;;;;;;;;SAuCgBA,uBAAuB,CACrCC,MAAgC,EAChCC,SAAY,EACZC,IAA4C;EAE5C,IAAIF,MAAM,EAAE;IACVA,MAAM,CAACG,iBAAiB,CAACF,SAAS,EAAEC,IAAI,CAAC;GAC1C,MAAM;IACLC,iBAAiB,CAACF,SAAS,EAAEC,IAAI,CAAC;;AAEtC;;;;;;;;;;;;;;;;;AC9CO,IAAME,aAAa,GAAG,CAC3B,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,CAC1B;AAED,SAAgBC,WAAW;EACzB,gBAA4BC,cAAQ,CAAC,KAAK,CAAC;IAApCC,MAAM;IAAEC,SAAS;EACxBC,eAAS,CAAC;IACRD,SAAS,CAAC,IAAI,CAAC;GAChB,CAAC;EACF,OAAOD,MAAM;AACf;AAmBA,SAAgBG,eAAe,CAACC,KAAa,EAAEC,OAAO;MAAPA,OAAO;IAAPA,OAAO,GAAG,GAAG;;EAC1D,OAAOR,aAAa,CAACO,KAAK,GAAGP,aAAa,CAACS,MAAM,CAAC,CAACC,OAAO,CACxD,KAAK,EACL,EAAE,GAAGF,OAAO,CACb;AACH;AAEA,SAAgBG,QAAQ;;uBACpBC,IAAI;IAAJA,IAAI,0BAAG,EAAE;IAAEC,UAAU,QAAVA,UAAU;IAAEC,YAAY,QAAZA,YAAY;IAAEC,aAAa,QAAbA,aAAa;EAAA,+BACoB,EAAE;IAAxEC,SAAS,SAATA,SAAS;IAAEC,uBAAuB,SAAvBA,uBAAuB;IAAEC,MAAM,SAANA,MAAM;IAAEV,OAAO,SAAPA,OAAO;EAErD,IA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H,MAAqB;EAC/CyH,mBAAmB,CAACzH,MAAM,CAAC;AAC7B;;;;"}
@@ -0,0 +1,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 r=require("react"),n=e(r),a=require("chart.js"),i=e(require("deepmerge")),l=require("react-chartjs-2");function c(){return(c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var o=["rgba(255, 99, 132, 0.2)","rgba(54, 162, 235, 0.2)","rgba(255, 206, 86, 0.2)","rgba(75, 192, 192, 0.2)","rgba(153, 102, 255, 0.2)","rgba(255, 159, 64, 0.2)"];function s(){var e=r.useState(!1),t=e[0],n=e[1];return r.useEffect((function(){n(!0)})),t}function u(e,t){return void 0===t&&(t=.2),o[e%o.length].replace("0.2",""+t)}function p(e,t){var r,n,a,i=e.data,l=void 0===i?[]:i,o=e.labelField,s=e.chosenFields,p=e.scatterSeries,d=void 0===t?{}:t,f=d.isScatter,v=d.preferNonNumericAsLabel,m=d.extras,g=d.opacity,y=Object.keys(null!=(r=l[0])?r:{}),b=new Map(y.map((function(e){return[e,l.every((function(t){var r;return!isNaN(null!=(r=t[e])?r:0)}))]}))),h=null!=o?o:v?y.find((function(e){return!b.get(e)})):y[0],E=y.filter((function(e){return b.get(e)}));if(f)return{datasets:(null!=(a=p=f?null!=(n=p)?n:[{name:E[0]+"-"+E[1],fields:[E[0],E[1]]}]:void 0)?a:[]).map((function(e,t){return c({},null==m?void 0:m(e.name),{label:e.name,data:l.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:u(t,g)})}))};var j=E.filter((function(e){return e!==h}));return{labels:h?l.map((function(e){return e[h]})):void 0,datasets:(null!=s?s:j).map((function(e,t){return c({},null==m?void 0:m(e),{label:e,data:l.map((function(t){var r;return null!=(r=t[e])?r:0})),backgroundColor:u(t,g)})}))}}function d(e){var t=e.interactive,r=e.title;return[f,void 0===t||t?{interaction:{mode:"index",intersect:!1}}:{},r?{title:{display:!0,text:r}}:{}]}var f={responsive:!0},v={scales:{x:{stacked:!0},y:{stacked:!0}}},m={plugins:{legend:{position:"top"}}},g={indexAxis:"y",plugins:{legend:{position:"right"}}};function y(e){var t=e.direction,c=void 0===t?"vertical":t,o=e.stacked,u=e.className,f=s();if(r.useEffect((function(){a.Chart.register(a.CategoryScale,a.LinearScale,a.BarElement,a.Title,a.Tooltip,a.Legend)}),[]),!f)return null;var y=p(e,{preferNonNumericAsLabel:!0,opacity:.5}),b=d(e);return n.createElement("div",{className:u},n.createElement(l.Bar,{options:i.all([].concat(b,["vertical"===c?m:g,o?v:{}])),data:y}))}function b(e){var t=e.secondAxisField,c=e.fill,o=e.className,u=s();if(r.useEffect((function(){a.Chart.register(a.CategoryScale,a.LinearScale,a.PointElement,a.LineElement,a.Title,a.Tooltip,a.Filler,a.Legend)}),[]),!u)return null;var f=p(e,{extras:function(e){return{fill:c,yAxisID:e===t?"y1":"y"}}}),v=d(e);return n.createElement("div",{className:o},n.createElement(l.Line,{options:i.all([].concat(v,[t?{scales:{y:{type:"linear",display:!0,position:"left"},y1:{type:"linear",display:!0,position:"right",grid:{drawOnChartArea:!1}}}}:{}])),data:f}))}function h(e){var t=e.className,c=s();if(r.useEffect((function(){a.Chart.register(a.LinearScale,a.PointElement,a.LineElement,a.Tooltip,a.Legend)}),[]),!c)return null;var o=p(e,{isScatter:!0,opacity:1}),u=d(e);return console.log("!!",o,u),n.createElement("div",{className:t},n.createElement(l.Scatter,{options:i.all([].concat(u,[{scales:{y:{beginAtZero:!0}}}])),data:o}))}function E(e){var t;switch(null!=(t=e.type)?t:"bar"){case"bar":return n.createElement(y,Object.assign({},e));case"line":return n.createElement(b,Object.assign({},e));case"scatter":return n.createElement(h,Object.assign({},e))}}var j={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:{type:"choice",hidden:function(e){return"scatter"===e.type},options:function(e){var t;return null!=(t=e.data)&&t[0]?Object.keys(e.data[0]):[]}},title:"string",fill:{type:"boolean",hidden:function(e){return"line"!==e.type}}},defaultStyles:{width:"stretch"},importName:"SimpleChart",importPath:"@plasmicpkgs/react-chartjs-2/dist/simple-chart/SimpleChart"};exports.registerAll=function(e){!function(e){!function(e,r,n){e?e.registerComponent(r,n):t(r,n)}(e,E,j)}(e)};
2
+ //# sourceMappingURL=react-chartjs-2.cjs.production.min.js.map
@@ -0,0 +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 { useEffect, useState } from \"react\";\nimport { baseOptions } from \"./simple-bar/SimpleBar\";\n\nexport const defaultColors = [\n \"rgba(255, 99, 132, 0.2)\",\n \"rgba(54, 162, 235, 0.2)\",\n \"rgba(255, 206, 86, 0.2)\",\n \"rgba(75, 192, 192, 0.2)\",\n \"rgba(153, 102, 255, 0.2)\",\n \"rgba(255, 159, 64, 0.2)\",\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\nexport function getDefaultColor(index: number, opacity = 0.2) {\n return defaultColors[index % defaultColors.length].replace(\n \"0.2\",\n \"\" + opacity\n );\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(index, opacity),\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(index, opacity),\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 }\n : {},\n title ? { title: { display: true, text: title } } : {},\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 { BaseChartProps, prepData, prepOptions, useIsClient } from \"../common\";\n\nexport const baseOptions = {\n responsive: true,\n};\n\nexport const stackedOptions = {\n scales: {\n x: {\n stacked: true,\n },\n y: {\n stacked: true,\n },\n },\n};\n\nexport const vertOptions = {\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 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: 0.5,\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Bar\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 } from \"react\";\nimport { Line } from \"react-chartjs-2\";\nimport { BaseChartProps, prepData, prepOptions, useIsClient } from \"../common\";\n\nexport interface SimpleLineProps extends BaseChartProps {\n fill?: boolean;\n secondAxisField?: string;\n}\n\nexport function SimpleLine(props: SimpleLineProps) {\n const { secondAxisField, fill, className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\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 yAxisID: field === secondAxisField ? \"y1\" : \"y\",\n }),\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Line\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 Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Scatter } from \"react-chartjs-2\";\nimport { BaseChartProps, prepData, prepOptions, useIsClient } from \"../common\";\n\nexport interface SimpleScatterProps extends BaseChartProps {}\n\nexport function SimpleScatter(props: SimpleScatterProps) {\n const { className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(LinearScale, PointElement, LineElement, Tooltip, Legend);\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, { isScatter: true, opacity: 1 });\n const options = prepOptions(props);\n console.log(\"!!\", normalized, options);\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 { ComponentMeta } from \"@plasmicapp/host/registerComponent\";\nimport { Registerable, registerComponentHelper } from \"../utils\";\nimport { SimpleChart, SimpleChartProps } from \"./SimpleChart\";\n\nexport * from \"./SimpleChart\";\nexport default SimpleChart;\n\nconst simpleChartMeta: ComponentMeta<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\" as any,\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 type: \"choice\",\n hidden: (props) => props.type === \"scatter\",\n options: (props) => (props.data?.[0] ? Object.keys(props.data[0]) : []),\n },\n title: \"string\",\n fill: {\n type: \"boolean\",\n hidden: (props) => props.type !== \"line\",\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/dist/simple-chart/SimpleChart\",\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 function registerAll(loader?: Registerable) {\n registerSimpleChart(loader);\n}\n","import {\n ComponentMeta,\n default as registerComponent,\n} from \"@plasmicapp/host/registerComponent\";\nimport {\n default as registerGlobalContext,\n GlobalContextMeta,\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: ComponentMeta<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: ComponentMeta<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":["defaultColors","useIsClient","useState","loaded","setLoaded","useEffect","getDefaultColor","index","opacity","length","replace","prepData","data","labelField","chosenFields","scatterSeries","isScatter","preferNonNumericAsLabel","extras","fields","Object","keys","isFieldAllNumericOrNil","Map","map","key","every","item","isNaN","realLabelField","find","field","get","numericFields","filter","datasets","name","undefined","series","label","x","y","backgroundColor","autoChosenFields","labels","prepOptions","interactive","title","baseOptions","interaction","mode","intersect","display","text","responsive","stackedOptions","scales","stacked","vertOptions","plugins","legend","position","horizOptions","indexAxis","SimpleBar","props","direction","className","isClient","ChartJS","register","CategoryScale","LinearScale","BarElement","Title","Tooltip","Legend","normalized","options","React","Bar","deepmerge","all","SimpleLine","secondAxisField","fill","PointElement","LineElement","Filler","yAxisID","Line","type","y1","grid","drawOnChartArea","SimpleScatter","console","log","Scatter","beginAtZero","SimpleChart","simpleChartMeta","displayName","value","defaultValueHint","description","defaultExpr","JSON","stringify","region","revenue","spend","hidden","_props$data","defaultStyles","width","importName","importPath","loader","component","meta","registerComponent","registerComponentHelper","registerSimpleChart"],"mappings":"ikBAGO,IAAMA,EAAgB,CAC3B,0BACA,0BACA,0BACA,0BACA,2BACA,2BAGF,SAAgBC,IACd,MAA4BC,YAAS,GAA9BC,OAAQC,OAIf,OAHAC,aAAU,WACRD,GAAU,MAELD,WAoBOG,EAAgBC,EAAeC,GAC7C,gBAD6CA,IAAAA,EAAU,IAChDR,EAAcO,EAAQP,EAAcS,QAAQC,QACjD,MACA,GAAKF,Y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QAAS,KACTC,MAAO,SAIblG,WAAY,CACV8E,KAAM,SACNqB,OAAQ,SAAC/C,GAAK,MAAoB,YAAfA,EAAM0B,MACzBb,QAAS,SAACb,GAAK,MAAA,gBAAMA,EAAMrD,OAANqG,EAAa,GAAK7F,OAAOC,KAAK4C,EAAMrD,KAAK,IAAM,KAEtEmC,MAAO,SACPsC,KAAM,CACJM,KAAM,UACNqB,OAAQ,SAAC/C,GAAK,MAAoB,SAAfA,EAAM0B,QAoB7BuB,cAAe,CACbC,MAAO,WAGTC,WAAY,cACZC,WAAY,2FCrFcC,aDwFQA,aEnDlCA,EACAC,EACAC,GAEIF,EACFA,EAAOG,kBAAkBF,EAAWC,GAEpCC,EAAkBF,EAAWC,GF6C/BE,CAAwBJ,EAAQlB,EAAaC,GCxF7CsB,CAAoBL"}
@@ -0,0 +1,350 @@
1
+ import registerComponent from '@plasmicapp/host/registerComponent';
2
+ import '@plasmicapp/host/registerGlobalContext';
3
+ import React, { useState, useEffect } from 'react';
4
+ import { Chart, CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend, PointElement, LineElement, Filler } from 'chart.js';
5
+ import deepmerge from 'deepmerge';
6
+ import { Bar, Line, Scatter } from 'react-chartjs-2';
7
+
8
+ function registerComponentHelper(loader, component, meta) {
9
+ if (loader) {
10
+ loader.registerComponent(component, meta);
11
+ } else {
12
+ registerComponent(component, meta);
13
+ }
14
+ }
15
+
16
+ function _extends() {
17
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
18
+ for (var i = 1; i < arguments.length; i++) {
19
+ var source = arguments[i];
20
+ for (var key in source) {
21
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
22
+ target[key] = source[key];
23
+ }
24
+ }
25
+ }
26
+ return target;
27
+ };
28
+ return _extends.apply(this, arguments);
29
+ }
30
+
31
+ var defaultColors = ["rgba(255, 99, 132, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(255, 206, 86, 0.2)", "rgba(75, 192, 192, 0.2)", "rgba(153, 102, 255, 0.2)", "rgba(255, 159, 64, 0.2)"];
32
+ function useIsClient() {
33
+ var _useState = useState(false),
34
+ loaded = _useState[0],
35
+ setLoaded = _useState[1];
36
+ useEffect(function () {
37
+ setLoaded(true);
38
+ });
39
+ return loaded;
40
+ }
41
+ function getDefaultColor(index, opacity) {
42
+ if (opacity === void 0) {
43
+ opacity = 0.2;
44
+ }
45
+ return defaultColors[index % defaultColors.length].replace("0.2", "" + opacity);
46
+ }
47
+ function prepData(_ref, _temp) {
48
+ var _data$;
49
+ var _ref$data = _ref.data,
50
+ data = _ref$data === void 0 ? [] : _ref$data,
51
+ labelField = _ref.labelField,
52
+ chosenFields = _ref.chosenFields,
53
+ scatterSeries = _ref.scatterSeries;
54
+ var _ref2 = _temp === void 0 ? {} : _temp,
55
+ isScatter = _ref2.isScatter,
56
+ preferNonNumericAsLabel = _ref2.preferNonNumericAsLabel,
57
+ extras = _ref2.extras,
58
+ opacity = _ref2.opacity;
59
+ var fields = Object.keys((_data$ = data[0]) != null ? _data$ : {});
60
+ var isFieldAllNumericOrNil = new Map(fields.map(function (key) {
61
+ return [key, data.every(function (item) {
62
+ var _item$key;
63
+ return !isNaN((_item$key = item[key]) != null ? _item$key : 0);
64
+ })];
65
+ }));
66
+ var realLabelField = labelField != null ? labelField : preferNonNumericAsLabel ? fields.find(function (field) {
67
+ return !isFieldAllNumericOrNil.get(field);
68
+ }) : fields[0];
69
+ var numericFields = fields.filter(function (field) {
70
+ return isFieldAllNumericOrNil.get(field);
71
+ });
72
+ if (isScatter) {
73
+ var _scatterSeries, _scatterSeries2;
74
+ scatterSeries = isScatter ? (_scatterSeries = scatterSeries) != null ? _scatterSeries : [{
75
+ name: numericFields[0] + "-" + numericFields[1],
76
+ fields: [numericFields[0], numericFields[1]]
77
+ }] : undefined;
78
+ return {
79
+ datasets: ((_scatterSeries2 = scatterSeries) != null ? _scatterSeries2 : []).map(function (series, index) {
80
+ return _extends({}, extras == null ? void 0 : extras(series.name), {
81
+ label: series.name,
82
+ data: data.map(function (item) {
83
+ var _item$series$fields$, _item$series$fields$2;
84
+ return {
85
+ x: (_item$series$fields$ = item[series.fields[0]]) != null ? _item$series$fields$ : 0,
86
+ y: (_item$series$fields$2 = item[series.fields[1]]) != null ? _item$series$fields$2 : 0
87
+ };
88
+ }),
89
+ backgroundColor: getDefaultColor(index, opacity)
90
+ });
91
+ })
92
+ };
93
+ } else {
94
+ var autoChosenFields = numericFields.filter(function (field) {
95
+ return field !== realLabelField;
96
+ });
97
+ return {
98
+ labels: realLabelField ? data.map(function (item) {
99
+ return item[realLabelField];
100
+ }) : undefined,
101
+ datasets: (chosenFields != null ? chosenFields : autoChosenFields).map(function (key, index) {
102
+ return _extends({}, extras == null ? void 0 : extras(key), {
103
+ label: key,
104
+ data: data.map(function (item) {
105
+ var _item$key2;
106
+ return (_item$key2 = item[key]) != null ? _item$key2 : 0;
107
+ }),
108
+ backgroundColor: getDefaultColor(index, opacity)
109
+ });
110
+ })
111
+ };
112
+ }
113
+ }
114
+ // additional styling
115
+ /*
116
+ elements: {
117
+ bar: {
118
+ borderWidth: 2,
119
+ },
120
+ },
121
+
122
+ */
123
+ function prepOptions(_ref3) {
124
+ var _ref3$interactive = _ref3.interactive,
125
+ interactive = _ref3$interactive === void 0 ? true : _ref3$interactive,
126
+ title = _ref3.title;
127
+ return [baseOptions, interactive ? {
128
+ interaction: {
129
+ mode: "index",
130
+ intersect: false
131
+ }
132
+ } : {}, title ? {
133
+ title: {
134
+ display: true,
135
+ text: title
136
+ }
137
+ } : {}];
138
+ }
139
+
140
+ var baseOptions = {
141
+ responsive: true
142
+ };
143
+ var stackedOptions = {
144
+ scales: {
145
+ x: {
146
+ stacked: true
147
+ },
148
+ y: {
149
+ stacked: true
150
+ }
151
+ }
152
+ };
153
+ var vertOptions = {
154
+ plugins: {
155
+ legend: {
156
+ position: "top"
157
+ }
158
+ }
159
+ };
160
+ var horizOptions = {
161
+ indexAxis: "y",
162
+ plugins: {
163
+ legend: {
164
+ position: "right"
165
+ }
166
+ }
167
+ };
168
+ function SimpleBar(props) {
169
+ var _props$direction = props.direction,
170
+ direction = _props$direction === void 0 ? "vertical" : _props$direction,
171
+ stacked = props.stacked,
172
+ className = props.className;
173
+ var isClient = useIsClient();
174
+ useEffect(function () {
175
+ Chart.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend);
176
+ }, []);
177
+ if (!isClient) {
178
+ return null;
179
+ }
180
+ var normalized = prepData(props, {
181
+ preferNonNumericAsLabel: true,
182
+ opacity: 0.5
183
+ });
184
+ var options = prepOptions(props);
185
+ return React.createElement("div", {
186
+ className: className
187
+ }, React.createElement(Bar, {
188
+ options: deepmerge.all([].concat(options, [direction === "vertical" ? vertOptions : horizOptions, stacked ? stackedOptions : {}])),
189
+ data: normalized
190
+ }));
191
+ }
192
+
193
+ function SimpleLine(props) {
194
+ var secondAxisField = props.secondAxisField,
195
+ fill = props.fill,
196
+ className = props.className;
197
+ var isClient = useIsClient();
198
+ useEffect(function () {
199
+ Chart.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Filler, Legend);
200
+ }, []);
201
+ if (!isClient) {
202
+ return null;
203
+ }
204
+ var normalized = prepData(props, {
205
+ extras: function extras(field) {
206
+ return {
207
+ fill: fill,
208
+ yAxisID: field === secondAxisField ? "y1" : "y"
209
+ };
210
+ }
211
+ });
212
+ var options = prepOptions(props);
213
+ return React.createElement("div", {
214
+ className: className
215
+ }, React.createElement(Line, {
216
+ options: deepmerge.all([].concat(options, [secondAxisField ? {
217
+ scales: {
218
+ y: {
219
+ type: "linear",
220
+ display: true,
221
+ position: "left"
222
+ },
223
+ y1: {
224
+ type: "linear",
225
+ display: true,
226
+ position: "right",
227
+ grid: {
228
+ drawOnChartArea: false
229
+ }
230
+ }
231
+ }
232
+ } : {}])),
233
+ data: normalized
234
+ }));
235
+ }
236
+
237
+ function SimpleScatter(props) {
238
+ var className = props.className;
239
+ var isClient = useIsClient();
240
+ useEffect(function () {
241
+ Chart.register(LinearScale, PointElement, LineElement, Tooltip, Legend);
242
+ }, []);
243
+ if (!isClient) {
244
+ return null;
245
+ }
246
+ var normalized = prepData(props, {
247
+ isScatter: true,
248
+ opacity: 1
249
+ });
250
+ var options = prepOptions(props);
251
+ console.log("!!", normalized, options);
252
+ return React.createElement("div", {
253
+ className: className
254
+ }, React.createElement(Scatter, {
255
+ options: deepmerge.all([].concat(options, [{
256
+ scales: {
257
+ y: {
258
+ beginAtZero: true
259
+ }
260
+ }
261
+ }])),
262
+ data: normalized
263
+ }));
264
+ }
265
+
266
+ function SimpleChart(props) {
267
+ var _props$type;
268
+ switch ((_props$type = props.type) != null ? _props$type : "bar") {
269
+ case "bar":
270
+ return React.createElement(SimpleBar, Object.assign({}, props));
271
+ case "line":
272
+ return React.createElement(SimpleLine, Object.assign({}, props));
273
+ case "scatter":
274
+ return React.createElement(SimpleScatter, Object.assign({}, props));
275
+ }
276
+ }
277
+
278
+ var simpleChartMeta = {
279
+ name: "hostless-react-chartjs-2-simple-chart",
280
+ displayName: "Chart",
281
+ props: {
282
+ type: {
283
+ type: "choice",
284
+ options: [{
285
+ value: "bar",
286
+ label: "Bar"
287
+ }, {
288
+ value: "line",
289
+ label: "Line"
290
+ }, {
291
+ value: "scatter",
292
+ label: "Scatter"
293
+ }],
294
+ defaultValueHint: "bar"
295
+ },
296
+ data: {
297
+ type: "exprEditor",
298
+ description: "The data as an array of objects",
299
+ defaultExpr: /*#__PURE__*/JSON.stringify([{
300
+ region: "APAC",
301
+ revenue: 3294,
302
+ spend: 2675
303
+ }, {
304
+ region: "EMEA",
305
+ revenue: 3245,
306
+ spend: 3895
307
+ }, {
308
+ region: "LATAM",
309
+ revenue: 2165,
310
+ spend: 3498
311
+ }, {
312
+ region: "AMER",
313
+ revenue: 3215,
314
+ spend: 1656
315
+ }])
316
+ },
317
+ labelField: {
318
+ type: "choice",
319
+ hidden: function hidden(props) {
320
+ return props.type === "scatter";
321
+ },
322
+ options: function options(props) {
323
+ var _props$data;
324
+ return (_props$data = props.data) != null && _props$data[0] ? Object.keys(props.data[0]) : [];
325
+ }
326
+ },
327
+ title: "string",
328
+ fill: {
329
+ type: "boolean",
330
+ hidden: function hidden(props) {
331
+ return props.type !== "line";
332
+ }
333
+ }
334
+ },
335
+ defaultStyles: {
336
+ width: "stretch"
337
+ },
338
+ importName: "SimpleChart",
339
+ importPath: "@plasmicpkgs/react-chartjs-2/dist/simple-chart/SimpleChart"
340
+ };
341
+ function registerSimpleChart(loader) {
342
+ registerComponentHelper(loader, SimpleChart, simpleChartMeta);
343
+ }
344
+
345
+ function registerAll(loader) {
346
+ registerSimpleChart(loader);
347
+ }
348
+
349
+ export { registerAll };
350
+ //# sourceMappingURL=react-chartjs-2.esm.js.map
@@ -0,0 +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 ComponentMeta,\n default as registerComponent,\n} from \"@plasmicapp/host/registerComponent\";\nimport {\n default as registerGlobalContext,\n GlobalContextMeta,\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: ComponentMeta<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: ComponentMeta<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 { useEffect, useState } from \"react\";\nimport { baseOptions } from \"./simple-bar/SimpleBar\";\n\nexport const defaultColors = [\n \"rgba(255, 99, 132, 0.2)\",\n \"rgba(54, 162, 235, 0.2)\",\n \"rgba(255, 206, 86, 0.2)\",\n \"rgba(75, 192, 192, 0.2)\",\n \"rgba(153, 102, 255, 0.2)\",\n \"rgba(255, 159, 64, 0.2)\",\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\nexport function getDefaultColor(index: number, opacity = 0.2) {\n return defaultColors[index % defaultColors.length].replace(\n \"0.2\",\n \"\" + opacity\n );\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(index, opacity),\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(index, opacity),\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 }\n : {},\n title ? { title: { display: true, text: title } } : {},\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 { BaseChartProps, prepData, prepOptions, useIsClient } from \"../common\";\n\nexport const baseOptions = {\n responsive: true,\n};\n\nexport const stackedOptions = {\n scales: {\n x: {\n stacked: true,\n },\n y: {\n stacked: true,\n },\n },\n};\n\nexport const vertOptions = {\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 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: 0.5,\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Bar\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 } from \"react\";\nimport { Line } from \"react-chartjs-2\";\nimport { BaseChartProps, prepData, prepOptions, useIsClient } from \"../common\";\n\nexport interface SimpleLineProps extends BaseChartProps {\n fill?: boolean;\n secondAxisField?: string;\n}\n\nexport function SimpleLine(props: SimpleLineProps) {\n const { secondAxisField, fill, className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(\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 yAxisID: field === secondAxisField ? \"y1\" : \"y\",\n }),\n });\n const options = prepOptions(props);\n return (\n <div className={className}>\n <Line\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 Tooltip,\n} from \"chart.js\";\nimport deepmerge from \"deepmerge\";\nimport React, { useEffect } from \"react\";\nimport { Scatter } from \"react-chartjs-2\";\nimport { BaseChartProps, prepData, prepOptions, useIsClient } from \"../common\";\n\nexport interface SimpleScatterProps extends BaseChartProps {}\n\nexport function SimpleScatter(props: SimpleScatterProps) {\n const { className } = props;\n const isClient = useIsClient();\n useEffect(() => {\n ChartJS.register(LinearScale, PointElement, LineElement, Tooltip, Legend);\n }, []);\n if (!isClient) {\n return null;\n }\n const normalized = prepData(props, { isScatter: true, opacity: 1 });\n const options = prepOptions(props);\n console.log(\"!!\", normalized, options);\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 { ComponentMeta } from \"@plasmicapp/host/registerComponent\";\nimport { Registerable, registerComponentHelper } from \"../utils\";\nimport { SimpleChart, SimpleChartProps } from \"./SimpleChart\";\n\nexport * from \"./SimpleChart\";\nexport default SimpleChart;\n\nconst simpleChartMeta: ComponentMeta<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\" as any,\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 type: \"choice\",\n hidden: (props) => props.type === \"scatter\",\n options: (props) => (props.data?.[0] ? Object.keys(props.data[0]) : []),\n },\n title: \"string\",\n fill: {\n type: \"boolean\",\n hidden: (props) => props.type !== \"line\",\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/dist/simple-chart/SimpleChart\",\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 function registerAll(loader?: Registerable) {\n registerSimpleChart(loader);\n}\n"],"names":["registerComponentHelper","loader","component","meta","registerComponent","defaultColors","useIsClient","useState","loaded","setLoaded","useEffect","getDefaultColor","index","opacity","length","replace","prepData","data","labelField","chosenFields","scatterSeries","isScatter","preferNonNumericAsLabel","extras","fields","Object","keys","isFieldAllNumericOrNil","Map","map","key","every","item","isNaN","realLabelField","find","field","get","numericFields","filter","name","undefined","datasets","series","label","x","y","backgroundColor","autoChosenFields","labels","prepOptions","interactive","title","baseOptions","interaction","mode","intersect","display","text","responsive","stackedOptions","scales","stacked","vertOptions","plugins","legend","position","horizOptions","indexAxis","SimpleBar","props","direction","className","isClient","ChartJS","register","CategoryScale","LinearScale","BarElement","Title","Tooltip","Legend","normalized","options","React","Bar","deepmerge","all","SimpleLine","secondAxisField","fill","PointElement","LineElement","Filler","yAxisID","Line","type","y1","grid","drawOnChartArea","SimpleScatter","console","log","Scatter","beginAtZero","SimpleChart","simpleChartMeta","displayName","value","defaultValueHint","description","defaultExpr","JSON","stringify","region","revenue","spend","hidden","defaultStyles","width","importName","importPath","registerSimpleChart","registerAll"],"mappings":";;;;;;;SAuCgBA,uBAAuB,CACrCC,MAAgC,EAChCC,SAAY,EACZC,IAA4C;EAE5C,IAAIF,MAAM,EAAE;IACVA,MAAM,CAACG,iBAAiB,CAACF,SAAS,EAAEC,IAAI,CAAC;GAC1C,MAAM;IACLC,iBAAiB,CAACF,SAAS,EAAEC,IAAI,CAAC;;AAEtC;;;;;;;;;;;;;;;;;AC9CO,IAAME,aAAa,GAAG,CAC3B,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,CAC1B;AAED,SAAgBC,WAAW;EACzB,gBAA4BC,QAAQ,CAAC,KAAK,CAAC;IAApCC,MAAM;IAAEC,SAAS;EACxBC,SAA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;QAAA,OAAM,eAAAA,KAAK,CAACrD,IAAI,aAAV,YAAa,CAAC,CAAC,GAAGQ,MAAM,CAACC,IAAI,CAAC4C,KAAK,CAACrD,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE;;KACvE;IACDmC,KAAK,EAAE,QAAQ;IACfsC,IAAI,EAAE;MACJM,IAAI,EAAE,SAAS;MACfqB,MAAM,EAAE,gBAAC/C,KAAK;QAAA,OAAKA,KAAK,CAAC0B,IAAI,KAAK,MAAM;;;GAkB3C;EAEDsB,aAAa,EAAE;IACbC,KAAK,EAAE;GACR;EAEDC,UAAU,EAAE,aAAa;EACzBC,UAAU,EAAE;CACb;AAED,SAAgBC,mBAAmB,CAACzH,MAAqB;EACvDD,uBAAuB,CAACC,MAAM,EAAEwG,WAAW,EAAEC,eAAe,CAAC;AAC/D;;SC1FgBiB,WAAW,CAAC1H,MAAqB;EAC/CyH,mBAAmB,CAACzH,MAAM,CAAC;AAC7B;;;;"}
@@ -0,0 +1,35 @@
1
+ /// <reference types="react" />
2
+ import { BaseChartProps } from "../common";
3
+ export declare const baseOptions: {
4
+ responsive: boolean;
5
+ };
6
+ export declare const stackedOptions: {
7
+ scales: {
8
+ x: {
9
+ stacked: boolean;
10
+ };
11
+ y: {
12
+ stacked: boolean;
13
+ };
14
+ };
15
+ };
16
+ export declare const vertOptions: {
17
+ plugins: {
18
+ legend: {
19
+ position: "top";
20
+ };
21
+ };
22
+ };
23
+ export declare const horizOptions: {
24
+ indexAxis: "y";
25
+ plugins: {
26
+ legend: {
27
+ position: "right";
28
+ };
29
+ };
30
+ };
31
+ export interface SimpleBarProps extends BaseChartProps {
32
+ direction?: "vertical" | "horizontal";
33
+ stacked?: boolean;
34
+ }
35
+ export declare function SimpleBar(props: SimpleBarProps): JSX.Element | null;
@@ -0,0 +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 declare type SimpleChartProps = {
6
+ type?: "bar" | "line" | "scatter";
7
+ } & (SimpleBarProps | SimpleLineProps | SimpleScatterProps);
8
+ export declare function SimpleChart(props: SimpleChartProps): ReactElement;
@@ -0,0 +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;
@@ -0,0 +1,7 @@
1
+ /// <reference types="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): JSX.Element | null;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { BaseChartProps } from "../common";
3
+ export interface SimpleScatterProps extends BaseChartProps {
4
+ }
5
+ export declare function SimpleScatter(props: SimpleScatterProps): JSX.Element | null;
@@ -0,0 +1,24 @@
1
+ import { ComponentMeta, default as registerComponent } from "@plasmicapp/host/registerComponent";
2
+ import { default as registerGlobalContext, GlobalContextMeta } from "@plasmicapp/host/registerGlobalContext";
3
+ import { default as registerToken } from "@plasmicapp/host/registerToken";
4
+ import React from "react";
5
+ export declare 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: ComponentMeta<React.ComponentProps<T>>): (loader?: Registerable | undefined) => void;
11
+ export declare function makeRegisterGlobalContext<T extends React.ComponentType<any>>(component: T, meta: GlobalContextMeta<React.ComponentProps<T>>): (loader?: Registerable | undefined) => void;
12
+ export declare function registerComponentHelper<T extends React.ComponentType<any>>(loader: Registerable | undefined, component: T, meta: ComponentMeta<React.ComponentProps<T>>): void;
13
+ declare 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 ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@plasmicpkgs/react-chartjs-2",
3
+ "version": "1.0.1",
4
+ "description": "Chart.js 2.x components for React",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "module": "dist/react-chartjs-2.esm.js",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "size-limit": [
12
+ {
13
+ "path": "dist/react-chartjs-2.cjs.production.min.js",
14
+ "limit": "10 KB"
15
+ },
16
+ {
17
+ "path": "dist/react-chartjs-2.esm.js",
18
+ "limit": "10 KB"
19
+ }
20
+ ],
21
+ "scripts": {
22
+ "build": "tsdx build",
23
+ "start": "tsdx watch",
24
+ "test": "tsdx test --passWithNoTests",
25
+ "lint": "tsdx lint",
26
+ "prepare": "if-env PREPARE_NO_BUILD=true || yarn build",
27
+ "size": "size-limit",
28
+ "analyze": "size-limit --why"
29
+ },
30
+ "devDependencies": {
31
+ "@plasmicapp/data-sources": "0.1.60",
32
+ "@plasmicapp/host": "1.0.122",
33
+ "@size-limit/preset-small-lib": "^4.11.0",
34
+ "@types/node": "^14.0.26",
35
+ "chart.js": "^4.2.1",
36
+ "react-chartjs-2": "^5.2.0",
37
+ "size-limit": "^4.11.0",
38
+ "tsdx": "^0.14.1",
39
+ "tslib": "^2.2.0",
40
+ "typescript": "^3.9.7"
41
+ },
42
+ "peerDependencies": {
43
+ "@plasmicapp/data-sources": ">=0.1.52",
44
+ "@plasmicapp/host": ">=1.0.0",
45
+ "react": ">=16.8.0",
46
+ "react-dom": ">=16.8.0"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "dependencies": {
52
+ "deepmerge": "^4.3.1"
53
+ },
54
+ "gitHead": "96b7db457fb8ad72167bc8a793d2718406d763a5"
55
+ }