@react-fabric/chart 1.0.0-beta.8 → 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/{src/wrapper/Chart.module.css → css/_chart.css} +11 -11
- package/css/styles.css +24 -0
- package/dist/cjs/charts/ActivityMap.js +70 -36
- package/dist/cjs/charts/CountSeries.js +67 -35
- package/dist/cjs/charts/DataSeries.js +75 -40
- package/dist/cjs/charts/Generic.js +41 -19
- package/dist/cjs/charts/MapSeries.js +41 -17
- package/dist/cjs/charts/TimeSeries.js +73 -40
- package/dist/cjs/charts/TimeSlider.js +40 -21
- package/dist/cjs/charts/WordBubble.js +65 -29
- package/dist/cjs/index.js +28 -0
- package/dist/cjs/theme/darkBase.js +13 -10
- package/dist/cjs/theme/index.js +43 -23
- package/dist/cjs/theme/lightBase.js +18 -15
- package/dist/cjs/theme/palettes.js +5 -54
- package/dist/cjs/types/charts.js +4 -2
- package/dist/cjs/types/utils.js +6 -9
- package/dist/cjs/wrapper/ChartContainer.js +26 -18
- package/dist/cjs/wrapper/ChartToolbar.js +4 -5
- package/dist/cjs/wrapper/ChartWrapper.js +4 -5
- package/dist/cjs/wrapper/PaletteSelect.js +31 -18
- package/dist/esm/charts/ActivityMap.js +71 -37
- package/dist/esm/charts/CountSeries.js +68 -36
- package/dist/esm/charts/DataSeries.js +76 -41
- package/dist/esm/charts/Generic.js +43 -21
- package/dist/esm/charts/MapSeries.js +41 -17
- package/dist/esm/charts/TimeSeries.js +74 -41
- package/dist/esm/charts/TimeSlider.js +41 -22
- package/dist/esm/charts/WordBubble.js +67 -31
- package/dist/esm/index.js +30 -0
- package/dist/esm/theme/darkBase.js +13 -10
- package/dist/esm/theme/index.js +43 -23
- package/dist/esm/theme/lightBase.js +18 -15
- package/dist/esm/theme/palettes.js +5 -54
- package/dist/esm/types/charts.js +4 -2
- package/dist/esm/types/utils.js +6 -9
- package/dist/esm/wrapper/ChartContainer.js +27 -19
- package/dist/esm/wrapper/ChartToolbar.js +4 -5
- package/dist/esm/wrapper/ChartWrapper.js +4 -5
- package/dist/esm/wrapper/PaletteSelect.js +32 -19
- package/dist/types/charts/ActivityMap.d.ts +20 -4
- package/dist/types/charts/CountSeries.d.ts +25 -3
- package/dist/types/charts/DataSeries.d.ts +26 -1
- package/dist/types/charts/Generic.d.ts +36 -52
- package/dist/types/charts/MapSeries.d.ts +31 -3
- package/dist/types/charts/TimeSeries.d.ts +24 -1
- package/dist/types/charts/TimeSlider.d.ts +19 -5
- package/dist/types/charts/WordBubble.d.ts +28 -5
- package/dist/types/index.d.ts +26 -0
- package/dist/types/theme/darkBase.d.ts +8 -5
- package/dist/types/theme/index.d.ts +3 -2
- package/dist/types/theme/lightBase.d.ts +8 -5
- package/dist/types/types/charts.d.ts +2 -1
- package/dist/types/types/index.d.ts +30 -12
- package/dist/types/types/world.svg.d.ts +1 -1
- package/dist/types/wrapper/ChartContainer.d.ts +7 -7
- package/dist/types/wrapper/ChartToolbar.d.ts +2 -3
- package/dist/types/wrapper/ChartWrapper.d.ts +3 -5
- package/dist/types/wrapper/PaletteSelect.d.ts +6 -1
- package/package.json +17 -21
- package/src/charts/ActivityMap.tsx +95 -94
- package/src/charts/CountSeries.tsx +73 -65
- package/src/charts/DataSeries.tsx +104 -98
- package/src/charts/Generic.tsx +56 -86
- package/src/charts/MapSeries.tsx +153 -151
- package/src/charts/TimeSeries.tsx +96 -79
- package/src/charts/TimeSlider.tsx +194 -195
- package/src/charts/WordBubble.tsx +97 -62
- package/src/index.ts +22 -17
- package/src/theme/darkBase.ts +12 -9
- package/src/theme/index.ts +92 -30
- package/src/theme/lightBase.ts +17 -14
- package/src/theme/palettes.ts +1 -52
- package/src/types/charts.ts +6 -2
- package/src/types/index.ts +40 -4
- package/src/types/utils.ts +18 -30
- package/src/wrapper/ChartContainer.tsx +48 -79
- package/src/wrapper/ChartToolbar.tsx +5 -12
- package/src/wrapper/ChartWrapper.tsx +5 -10
- package/src/wrapper/PaletteSelect.tsx +43 -40
- package/dist/cjs/wrapper/Chart.module.css +0 -1
- package/dist/esm/wrapper/Chart.module.css +0 -1
package/src/types/utils.ts
CHANGED
|
@@ -21,6 +21,12 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
25
|
+
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
26
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
27
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
28
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
29
|
+
|
|
24
30
|
import { Format } from "@react-fabric/utilities";
|
|
25
31
|
|
|
26
32
|
interface Series {
|
|
@@ -40,8 +46,7 @@ interface MultiSeries {
|
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
export const countRenderer = (opt: KeyValue) => {
|
|
43
|
-
const axis =
|
|
44
|
-
opt.xAxis?.[0].type !== "value" ? opt.xAxis?.[0] : opt.yAxis?.[0];
|
|
49
|
+
const axis = opt.xAxis?.[0].type !== "value" ? opt.xAxis?.[0] : opt.yAxis?.[0];
|
|
45
50
|
const series = opt.series;
|
|
46
51
|
const table = [
|
|
47
52
|
'<div class="grid gap-2 p-2" style="grid-template-columns: repeat(auto-fill, minmax(8rem, max-content));grid-auto-flow: row;">',
|
|
@@ -58,8 +63,8 @@ export const countRenderer = (opt: KeyValue) => {
|
|
|
58
63
|
} else {
|
|
59
64
|
table.push(
|
|
60
65
|
...series[0].data.map(
|
|
61
|
-
(s:
|
|
62
|
-
`<div class="py-1 px-2 rounded ring-1"><label class="font-medium text-sm text-muted block">${s.name ?? s.id}</label><div class="text-end text-lg">${Format.number(s.value)}</div></div>`,
|
|
66
|
+
(s: AnyObject) =>
|
|
67
|
+
`<div class="py-1 px-2 rounded ring-1"><label class="font-medium text-sm text-muted block">${s.name ?? s.id}</label><div class="text-end text-lg">${Format.number(s.value[1] ?? s.value)}</div></div>`,
|
|
63
68
|
),
|
|
64
69
|
);
|
|
65
70
|
}
|
|
@@ -69,25 +74,17 @@ export const countRenderer = (opt: KeyValue) => {
|
|
|
69
74
|
|
|
70
75
|
export const seriesRenderer = (opt: KeyValue) => {
|
|
71
76
|
const radar = opt.radar?.[0];
|
|
72
|
-
const axis =
|
|
73
|
-
opt.xAxis?.[0].type !== "value" ? opt.xAxis?.[0] : opt.yAxis?.[0];
|
|
77
|
+
const axis = opt.xAxis?.[0].type !== "value" ? opt.xAxis?.[0] : opt.yAxis?.[0];
|
|
74
78
|
const series = opt.series;
|
|
75
79
|
const table = [
|
|
76
|
-
'<table class="border-separate border-spacing-1 mx-auto table-fixed min-w-full"><thead><tr class="sticky top-0 bg-
|
|
80
|
+
'<table class="border-separate border-spacing-1 mx-auto table-fixed min-w-full"><thead><tr class="sticky top-0 bg-default"><th></th>',
|
|
77
81
|
];
|
|
78
|
-
table.push(
|
|
79
|
-
...series.map((s: Series) => `<th class="truncate">${s.name ?? s.id}</th>`),
|
|
80
|
-
);
|
|
82
|
+
table.push(...series.map((s: Series) => `<th class="truncate">${s.name ?? s.id}</th>`));
|
|
81
83
|
table.push("</tr></thead><tbody class='bg-alternate'>");
|
|
82
84
|
if (axis?.data) {
|
|
83
85
|
axis.data.forEach((ax: string, i: number) => {
|
|
84
86
|
table.push(`<tr><th class="truncate">${ax}</th>`);
|
|
85
|
-
table.push(
|
|
86
|
-
...series.map(
|
|
87
|
-
(s: SubSeries) =>
|
|
88
|
-
`<td class="text-end">${Format.number(s.data[i])}</td>`,
|
|
89
|
-
),
|
|
90
|
-
);
|
|
87
|
+
table.push(...series.map((s: SubSeries) => `<td class="text-end">${Format.number(s.data[i])}</td>`));
|
|
91
88
|
table.push("</tr>");
|
|
92
89
|
});
|
|
93
90
|
}
|
|
@@ -96,8 +93,7 @@ export const seriesRenderer = (opt: KeyValue) => {
|
|
|
96
93
|
table.push(`<tr><th>${ax.name}</th>`);
|
|
97
94
|
table.push(
|
|
98
95
|
...series.map(
|
|
99
|
-
(s: ListSeries) =>
|
|
100
|
-
`<td class="text-end">${Format.number((s.data[0] ?? { value: [] }).value[i] ?? 0)}</td>`,
|
|
96
|
+
(s: ListSeries) => `<td class="text-end">${Format.number((s.data[0] ?? { value: [] }).value[i] ?? 0)}</td>`,
|
|
101
97
|
),
|
|
102
98
|
);
|
|
103
99
|
table.push("</tr>");
|
|
@@ -110,18 +106,13 @@ export const seriesRenderer = (opt: KeyValue) => {
|
|
|
110
106
|
export const timeSeriesRenderer = (opt: KeyValue) => {
|
|
111
107
|
const series = opt.series;
|
|
112
108
|
const table = [
|
|
113
|
-
'<table class="border-separate border-spacing-1 mx-auto table-fixed min-w-full"><thead><tr class="sticky top-0 bg-
|
|
109
|
+
'<table class="border-separate border-spacing-1 mx-auto table-fixed min-w-full"><thead><tr class="sticky top-0 bg-default"><th></th>',
|
|
114
110
|
];
|
|
115
111
|
table.push(...series.map((s: Series) => `<th>${s.name ?? s.id}</th>`));
|
|
116
112
|
table.push("</tr></thead><tbody class='bg-alternate'>");
|
|
117
113
|
series[0].data.forEach((ax: AnyObject, i: number) => {
|
|
118
114
|
table.push(`<tr><th>${Format.date(ax[0])}</th>`);
|
|
119
|
-
series.forEach((s: MultiSeries) =>
|
|
120
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
121
|
-
table.push(
|
|
122
|
-
`<td class="text-end">${Format.number(s.data?.[i]?.[1] ?? 0)}</td>`,
|
|
123
|
-
),
|
|
124
|
-
);
|
|
115
|
+
series.forEach((s: MultiSeries) => table.push(`<td class="text-end">${Format.number(s.data?.[i]?.[1] ?? 0)}</td>`));
|
|
125
116
|
table.push("</tr>");
|
|
126
117
|
});
|
|
127
118
|
table.push("</tbody></table>");
|
|
@@ -132,17 +123,14 @@ export const activityRenderer = (opt: KeyValue) => {
|
|
|
132
123
|
const axis = opt.xAxis[0];
|
|
133
124
|
const series = opt.series;
|
|
134
125
|
const table = [
|
|
135
|
-
'<table class="border-separate border-spacing-1 mx-auto table-fixed min-w-full"><thead><tr><th class="sticky top-0 bg-
|
|
126
|
+
'<table class="border-separate border-spacing-1 mx-auto table-fixed min-w-full"><thead><tr><th class="sticky top-0 bg-default"></th>',
|
|
136
127
|
];
|
|
137
128
|
table.push(...series.map((s: Series) => `<th>${s.name ?? s.id}</th>`));
|
|
138
129
|
table.push("</tr></thead><tbody class='bg-alternate'>");
|
|
139
130
|
table.push(
|
|
140
131
|
...axis.data.map((s: string, i: number) => [
|
|
141
132
|
`<tr><th>${s}</th>`,
|
|
142
|
-
...series.map(
|
|
143
|
-
(s: MultiSeries) =>
|
|
144
|
-
`<td class="text-end">${Format.number((s.data[i] ?? [])[2] ?? 0)}</td>`,
|
|
145
|
-
),
|
|
133
|
+
...series.map((s: MultiSeries) => `<td class="text-end">${Format.number((s.data[i] ?? [])[2] ?? 0)}</td>`),
|
|
146
134
|
"</tr>",
|
|
147
135
|
]),
|
|
148
136
|
);
|
|
@@ -21,31 +21,13 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
25
|
-
Button,
|
|
26
|
-
CoreIcons,
|
|
27
|
-
EmptyContent,
|
|
28
|
-
Title,
|
|
29
|
-
useIsDark,
|
|
30
|
-
useResizeObserver,
|
|
31
|
-
} from "@react-fabric/core";
|
|
24
|
+
import { Button, EmptyContent, Title, useIsDark, useResizeObserver } from "@react-fabric/core";
|
|
32
25
|
import { type SizeObject } from "@react-fabric/core/dist/types/types";
|
|
33
|
-
import
|
|
34
|
-
import { type
|
|
35
|
-
import "
|
|
36
|
-
import {
|
|
37
|
-
Fragment,
|
|
38
|
-
memo,
|
|
39
|
-
useCallback,
|
|
40
|
-
useEffect,
|
|
41
|
-
useImperativeHandle,
|
|
42
|
-
useMemo,
|
|
43
|
-
useState,
|
|
44
|
-
type RefObject,
|
|
45
|
-
} from "react";
|
|
26
|
+
import { cn } from "@react-fabric/utilities";
|
|
27
|
+
import { type EChartsOption, type EChartsType } from "echarts";
|
|
28
|
+
import { Fragment, memo, useCallback, useEffect, useImperativeHandle, useMemo, useState, type Ref } from "react";
|
|
46
29
|
import { type Theme } from "../types";
|
|
47
30
|
import echarts from "../types/charts";
|
|
48
|
-
import classes from "./Chart.module.css";
|
|
49
31
|
import { ChartToolbar } from "./ChartToolbar";
|
|
50
32
|
|
|
51
33
|
const defaultOptions = {
|
|
@@ -57,15 +39,14 @@ const defaultOptions = {
|
|
|
57
39
|
},
|
|
58
40
|
tooltip: {
|
|
59
41
|
trigger: "item",
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
} as AnyObject,
|
|
42
|
+
appendToBody: true,
|
|
43
|
+
},
|
|
63
44
|
legend: {
|
|
64
45
|
type: "scroll",
|
|
65
46
|
bottom: 0,
|
|
66
|
-
}
|
|
47
|
+
},
|
|
67
48
|
};
|
|
68
|
-
const toolboxOptions = (renderer
|
|
49
|
+
const toolboxOptions = (renderer?: KeyValue) => ({
|
|
69
50
|
show: true,
|
|
70
51
|
feature: {
|
|
71
52
|
dataView: {
|
|
@@ -98,10 +79,10 @@ export const ChartContainer = memo(
|
|
|
98
79
|
theme?: Theme;
|
|
99
80
|
isEmpty?: boolean;
|
|
100
81
|
emptyIcon?: string;
|
|
101
|
-
options:
|
|
82
|
+
options: EChartsOption;
|
|
102
83
|
children?: AnyObject;
|
|
103
|
-
chartRef?:
|
|
104
|
-
onClick?: (event:
|
|
84
|
+
chartRef?: Ref<EChartsType>;
|
|
85
|
+
onClick?: (event: echarts.ECElementEvent) => void;
|
|
105
86
|
onExport?: (event: AnyObject) => void;
|
|
106
87
|
dataTableRenderer?: (opt: KeyValue) => string;
|
|
107
88
|
onResize?: (size: { width: number; height: number }) => void;
|
|
@@ -112,62 +93,67 @@ export const ChartContainer = memo(
|
|
|
112
93
|
const handleResize = useCallback(
|
|
113
94
|
(size: SizeObject) => {
|
|
114
95
|
onResize?.(size);
|
|
115
|
-
chartRef?.resize(size);
|
|
96
|
+
if (chartRef && !chartRef.isDisposed()) chartRef?.resize(size);
|
|
116
97
|
},
|
|
98
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
117
99
|
[chartRef],
|
|
118
100
|
);
|
|
119
101
|
const containerRef = useResizeObserver(handleResize);
|
|
120
102
|
|
|
121
|
-
useImperativeHandle<EChartsType | undefined, EChartsType | undefined>(
|
|
122
|
-
_ref,
|
|
123
|
-
() => chartRef,
|
|
124
|
-
[chartRef],
|
|
125
|
-
);
|
|
103
|
+
useImperativeHandle<EChartsType | undefined, EChartsType | undefined>(_ref, () => chartRef, [chartRef]);
|
|
126
104
|
|
|
127
|
-
const chartTheme = useMemo(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
);
|
|
105
|
+
const chartTheme = useMemo(() => {
|
|
106
|
+
return isDark ? `${theme}_dark` : theme;
|
|
107
|
+
}, [theme, isDark]);
|
|
131
108
|
|
|
132
109
|
useEffect(() => {
|
|
133
110
|
if (containerRef.current) {
|
|
134
|
-
const { offsetWidth: width, offsetHeight: height } =
|
|
135
|
-
containerRef.current;
|
|
111
|
+
const { offsetWidth: width, offsetHeight: height } = containerRef.current;
|
|
136
112
|
const chartRef = echarts.init(containerRef.current, chartTheme);
|
|
137
113
|
chartRef.resize({ width, height });
|
|
138
114
|
onResize?.({ width, height });
|
|
115
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
139
116
|
setChartRef(chartRef);
|
|
140
117
|
|
|
141
118
|
return () => {
|
|
142
119
|
chartRef.dispose();
|
|
143
120
|
};
|
|
144
121
|
}
|
|
122
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
123
|
+
}, []);
|
|
124
|
+
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (chartRef && !chartRef.isDisposed()) chartRef?.setTheme(chartTheme);
|
|
127
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
145
128
|
}, [chartTheme]);
|
|
146
129
|
|
|
147
130
|
useEffect(() => {
|
|
148
131
|
const chart = chartRef;
|
|
149
|
-
if (chart) {
|
|
150
|
-
onClick != null
|
|
132
|
+
if (chart && !chart.isDisposed()) {
|
|
133
|
+
if (onClick != null) chart.on("click", onClick);
|
|
151
134
|
return () => {
|
|
152
|
-
!chart.isDisposed()
|
|
135
|
+
if (!chart.isDisposed()) chart.off("click");
|
|
153
136
|
};
|
|
154
137
|
}
|
|
155
138
|
}, [chartRef, onClick]);
|
|
156
139
|
|
|
157
|
-
const toolbox = useMemo(
|
|
158
|
-
() => toolboxOptions(dataTableRenderer),
|
|
159
|
-
[dataTableRenderer],
|
|
160
|
-
);
|
|
140
|
+
const toolbox = useMemo(() => toolboxOptions(dataTableRenderer), [dataTableRenderer]);
|
|
161
141
|
|
|
162
142
|
useEffect(() => {
|
|
163
|
-
chartRef
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
143
|
+
if (chartRef && !chartRef.isDisposed())
|
|
144
|
+
chartRef?.setOption(
|
|
145
|
+
{
|
|
146
|
+
...defaultOptions,
|
|
147
|
+
toolbox,
|
|
148
|
+
...options,
|
|
149
|
+
tooltip: {
|
|
150
|
+
...defaultOptions.tooltip,
|
|
151
|
+
...options.tooltip,
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
true,
|
|
155
|
+
);
|
|
156
|
+
// eslint-disable-next-line @eslint-react/exhaustive-deps
|
|
171
157
|
}, [options, chartRef]);
|
|
172
158
|
|
|
173
159
|
const handleExport = useCallback(() => {
|
|
@@ -181,33 +167,16 @@ export const ChartContainer = memo(
|
|
|
181
167
|
return (
|
|
182
168
|
<Fragment>
|
|
183
169
|
<ChartToolbar>
|
|
184
|
-
{title &&
|
|
185
|
-
<Title className="flex-fill px-2 py-1 text-dimmed">{title}</Title>
|
|
186
|
-
)}
|
|
170
|
+
{title && <Title className="flex-1 px-2 py-1 text-dimmed">{title}</Title>}
|
|
187
171
|
{children}
|
|
188
172
|
{onExport && (
|
|
189
|
-
<Button
|
|
190
|
-
size="sm"
|
|
191
|
-
variant="link"
|
|
192
|
-
icon={CoreIcons.exporter}
|
|
193
|
-
onClick={handleExport}
|
|
194
|
-
aria-label="export"
|
|
195
|
-
/>
|
|
173
|
+
<Button size="sm" variant="link" icon="icon-[mdi--export-variant]" onClick={handleExport} aria-label="export" />
|
|
196
174
|
)}
|
|
197
175
|
</ChartToolbar>
|
|
198
|
-
<div
|
|
199
|
-
ref={containerRef}
|
|
200
|
-
className={classNames(
|
|
201
|
-
classes.chartContainer,
|
|
202
|
-
"overflow-hidden area-content",
|
|
203
|
-
)}
|
|
204
|
-
/>
|
|
176
|
+
<div ref={containerRef} className={cn("fabric-chartContainer", "overflow-hidden area-content")} />
|
|
205
177
|
{isEmpty && (
|
|
206
|
-
<div className="absolute inset-0 bg-
|
|
207
|
-
<EmptyContent
|
|
208
|
-
icon={emptyIcon ?? CoreIcons.chartLine}
|
|
209
|
-
message="Empty chart"
|
|
210
|
-
/>
|
|
178
|
+
<div className="absolute inset-0 bg-default grid place-content-center">
|
|
179
|
+
<EmptyContent icon={emptyIcon ?? "icon-[mdi--chart-line]"} message="Empty chart" />
|
|
211
180
|
</div>
|
|
212
181
|
)}
|
|
213
182
|
</Fragment>
|
|
@@ -21,20 +21,13 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
25
|
-
import
|
|
26
|
-
import { type FC } from "react";
|
|
27
|
-
import classes from "./Chart.module.css";
|
|
24
|
+
import { cn } from "@react-fabric/utilities";
|
|
25
|
+
import type { PropsWithChildren } from "react";
|
|
28
26
|
|
|
29
|
-
export
|
|
27
|
+
export function ChartToolbar({ children }: PropsWithChildren) {
|
|
30
28
|
return (
|
|
31
|
-
<div
|
|
32
|
-
className={classNames(
|
|
33
|
-
"flex flex-nowrap items-center justify-end bg-base area-head",
|
|
34
|
-
classes.chartToolbar,
|
|
35
|
-
)}
|
|
36
|
-
>
|
|
29
|
+
<div className={cn("flex flex-nowrap items-center justify-end bg-default area-head", "fabric-chartToolbar empty:hidden")}>
|
|
37
30
|
{children}
|
|
38
31
|
</div>
|
|
39
32
|
);
|
|
40
|
-
}
|
|
33
|
+
}
|
|
@@ -22,25 +22,20 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import { ErrorBoundary } from "@react-fabric/core";
|
|
25
|
-
import "echarts-wordcloud";
|
|
26
|
-
import { type FC } from "react";
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
function Error({ error = "" }: { error?: string }) {
|
|
29
27
|
return (
|
|
30
28
|
<div className="text-sm">
|
|
31
29
|
<span className="bg-danger text-white py-1 px-2 mx-2 rounded">Error</span>
|
|
32
30
|
<span>{error}</span>
|
|
33
31
|
</div>
|
|
34
32
|
);
|
|
35
|
-
}
|
|
33
|
+
}
|
|
36
34
|
|
|
37
|
-
export
|
|
35
|
+
export function ChartWrapper({ children }: { children?: React.ReactElement }) {
|
|
38
36
|
return (
|
|
39
|
-
<div
|
|
40
|
-
className="grid overflow-hidden area-content relative"
|
|
41
|
-
style={{ gridTemplate: `"head" auto "content" 1fr / 1fr` }}
|
|
42
|
-
>
|
|
37
|
+
<div className="grid overflow-hidden area-content relative" style={{ gridTemplate: `"head" auto "content" 1fr / 1fr` }}>
|
|
43
38
|
<ErrorBoundary errorElement={Error}>{children}</ErrorBoundary>
|
|
44
39
|
</div>
|
|
45
40
|
);
|
|
46
|
-
}
|
|
41
|
+
}
|
|
@@ -21,51 +21,45 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
25
|
-
Button,
|
|
26
|
-
CoreIcons,
|
|
27
|
-
Dropdown,
|
|
28
|
-
Menu,
|
|
29
|
-
MenuItem,
|
|
30
|
-
} from "@react-fabric/core";
|
|
24
|
+
import { Button, Dropdown, Menu, MenuItem } from "@react-fabric/core";
|
|
31
25
|
import { ChartPalette } from "../theme/palettes";
|
|
26
|
+
import type { Theme } from "../types";
|
|
32
27
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
key={c}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
</div>
|
|
44
|
-
);
|
|
28
|
+
function PaletteMap({ colors = [], label = "" }: { label: string; colors: string[] }) {
|
|
29
|
+
return (
|
|
30
|
+
<div className="flex items-center">
|
|
31
|
+
{colors.slice(0, 8).map((c: string) => (
|
|
32
|
+
<div key={c} className="inline-block rounded-full outline w-3 h-3 mx-px" style={{ backgroundColor: c }} />
|
|
33
|
+
))}
|
|
34
|
+
<div className="text-xs text-muted px-2">{label}</div>
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
45
38
|
|
|
46
|
-
export
|
|
39
|
+
export function PaletteSelect({
|
|
47
40
|
onClick,
|
|
48
41
|
theme = "default",
|
|
49
42
|
defaultTheme = "default",
|
|
50
|
-
}:
|
|
43
|
+
}: {
|
|
44
|
+
theme?: Theme;
|
|
45
|
+
defaultTheme?: Theme;
|
|
46
|
+
onClick: (theme: Theme) => void;
|
|
47
|
+
}) {
|
|
51
48
|
return (
|
|
52
49
|
<Dropdown>
|
|
53
|
-
<Button
|
|
54
|
-
|
|
55
|
-
aria-label="palette"
|
|
56
|
-
size="sm"
|
|
57
|
-
variant="link"
|
|
58
|
-
/>
|
|
59
|
-
<Menu onClick={onClick}>
|
|
50
|
+
<Button icon="icon-[mdi--palette-outline]" aria-label="palette" size="sm" variant="link" />
|
|
51
|
+
<Menu onClick={(t) => onClick(t as Theme)}>
|
|
60
52
|
<MenuItem
|
|
61
53
|
id={defaultTheme}
|
|
62
54
|
icon={theme === defaultTheme ? "◉" : "◯"}
|
|
63
|
-
label=
|
|
55
|
+
label="Default"
|
|
56
|
+
labelRender={PaletteMap({ label: "Default", colors: ChartPalette.Default })}
|
|
64
57
|
/>
|
|
65
58
|
<MenuItem
|
|
66
59
|
id="qualitative"
|
|
67
60
|
icon={theme === "qualitative" ? "◉" : "◯"}
|
|
68
|
-
label=
|
|
61
|
+
label="Qualitative"
|
|
62
|
+
labelRender={PaletteMap({
|
|
69
63
|
label: "Qualitative",
|
|
70
64
|
colors: ChartPalette.Qualitative,
|
|
71
65
|
})}
|
|
@@ -73,7 +67,8 @@ export const PaletteSelect = ({
|
|
|
73
67
|
<MenuItem
|
|
74
68
|
id="diverging"
|
|
75
69
|
icon={theme === "diverging" ? "◉" : "◯"}
|
|
76
|
-
label=
|
|
70
|
+
label="Diverging"
|
|
71
|
+
labelRender={PaletteMap({
|
|
77
72
|
label: "Diverging",
|
|
78
73
|
colors: ChartPalette.Diverging,
|
|
79
74
|
})}
|
|
@@ -81,7 +76,8 @@ export const PaletteSelect = ({
|
|
|
81
76
|
<MenuItem
|
|
82
77
|
id="sequential"
|
|
83
78
|
icon={theme === "sequential" ? "◉" : "◯"}
|
|
84
|
-
label=
|
|
79
|
+
label="Sequential"
|
|
80
|
+
labelRender={PaletteMap({
|
|
85
81
|
label: "Sequential",
|
|
86
82
|
colors: ChartPalette.Sequential,
|
|
87
83
|
})}
|
|
@@ -89,7 +85,8 @@ export const PaletteSelect = ({
|
|
|
89
85
|
<MenuItem
|
|
90
86
|
id="spectral"
|
|
91
87
|
icon={theme === "spectral" ? "◉" : "◯"}
|
|
92
|
-
label=
|
|
88
|
+
label="Spectral"
|
|
89
|
+
labelRender={PaletteMap({
|
|
93
90
|
label: "Spectral",
|
|
94
91
|
colors: ChartPalette.Spectral,
|
|
95
92
|
})}
|
|
@@ -97,7 +94,8 @@ export const PaletteSelect = ({
|
|
|
97
94
|
<MenuItem
|
|
98
95
|
id="uber"
|
|
99
96
|
icon={theme === "uber" ? "◉" : "◯"}
|
|
100
|
-
label=
|
|
97
|
+
label="Uber Pool"
|
|
98
|
+
labelRender={PaletteMap({
|
|
101
99
|
label: "Uber Pool",
|
|
102
100
|
colors: ChartPalette.UberPool,
|
|
103
101
|
})}
|
|
@@ -105,7 +103,8 @@ export const PaletteSelect = ({
|
|
|
105
103
|
<MenuItem
|
|
106
104
|
id="fireice"
|
|
107
105
|
icon={theme === "fireice" ? "◉" : "◯"}
|
|
108
|
-
label=
|
|
106
|
+
label="Fire Ice"
|
|
107
|
+
labelRender={PaletteMap({
|
|
109
108
|
label: "Fire Ice",
|
|
110
109
|
colors: ChartPalette.FireIce,
|
|
111
110
|
})}
|
|
@@ -113,7 +112,8 @@ export const PaletteSelect = ({
|
|
|
113
112
|
<MenuItem
|
|
114
113
|
id="warming"
|
|
115
114
|
icon={theme === "warming" ? "◉" : "◯"}
|
|
116
|
-
label=
|
|
115
|
+
label="Global Warming"
|
|
116
|
+
labelRender={PaletteMap({
|
|
117
117
|
label: "Global Warming",
|
|
118
118
|
colors: ChartPalette.GlobalWarming,
|
|
119
119
|
})}
|
|
@@ -121,19 +121,22 @@ export const PaletteSelect = ({
|
|
|
121
121
|
<MenuItem
|
|
122
122
|
id="sunrise"
|
|
123
123
|
icon={theme === "sunrise" ? "◉" : "◯"}
|
|
124
|
-
label=
|
|
124
|
+
label="Sunrise"
|
|
125
|
+
labelRender={PaletteMap({ label: "Sunrise", colors: ChartPalette.Sunrise })}
|
|
125
126
|
/>
|
|
126
127
|
<MenuItem
|
|
127
128
|
id="ocean"
|
|
128
129
|
icon={theme === "ocean" ? "◉" : "◯"}
|
|
129
|
-
label=
|
|
130
|
+
label="Ocean"
|
|
131
|
+
labelRender={PaletteMap({ label: "Ocean", colors: ChartPalette.Ocean })}
|
|
130
132
|
/>
|
|
131
133
|
<MenuItem
|
|
132
134
|
id="wine"
|
|
133
135
|
icon={theme === "wine" ? "◉" : "◯"}
|
|
134
|
-
label=
|
|
136
|
+
label="Wine"
|
|
137
|
+
labelRender={PaletteMap({ label: "Wine", colors: ChartPalette.Wine })}
|
|
135
138
|
/>
|
|
136
139
|
</Menu>
|
|
137
140
|
</Dropdown>
|
|
138
141
|
);
|
|
139
|
-
}
|
|
142
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.chartContainer{&>div:last-child:not(:first-child)>:last-child{bottom:unset!important;inset-inline-end:0!important;left:unset!important;padding:.5rem;right:unset!important;top:0;&>div{float:unset!important;margin:0!important}}}.chartToolbar{input[type=range]{appearance:none;border-radius:999px;color:theme(colors.primary.500);overflow:hidden;position:relative;&::-webkit-slider-thumb{appearance:none;background:theme(colors.primary.500);border:1px solid theme(colors.tint.50);border-radius:.5rem;box-shadow:calc(-100vmax - 1rem) 0 0 100vmax currentColor;clip-path:polygon(100% -1px,.125rem -1px,0 .375rem,-100vmax .375rem,-100vmax .625rem,0 .625rem,.125rem 100%,calc(100% + 1px) calc(100% + 1px));cursor:pointer;filter:brightness(100%);height:1rem;opacity:.7;position:relative;width:1rem;&:hover{background:theme(colors.primary.600)}}&&::-webkit-slider-runnable-track{background:linear-gradient(theme(colors.tint.100) 0 0) scroll no-repeat 50% /100% .25rem;border-radius:99px;height:1rem}}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.chartContainer{&>div:last-child:not(:first-child)>:last-child{bottom:unset!important;inset-inline-end:0!important;left:unset!important;padding:.5rem;right:unset!important;top:0;&>div{float:unset!important;margin:0!important}}}.chartToolbar{input[type=range]{appearance:none;border-radius:999px;color:theme(colors.primary.500);overflow:hidden;position:relative;&::-webkit-slider-thumb{appearance:none;background:theme(colors.primary.500);border:1px solid theme(colors.tint.50);border-radius:.5rem;box-shadow:calc(-100vmax - 1rem) 0 0 100vmax currentColor;clip-path:polygon(100% -1px,.125rem -1px,0 .375rem,-100vmax .375rem,-100vmax .625rem,0 .625rem,.125rem 100%,calc(100% + 1px) calc(100% + 1px));cursor:pointer;filter:brightness(100%);height:1rem;opacity:.7;position:relative;width:1rem;&:hover{background:theme(colors.primary.600)}}&&::-webkit-slider-runnable-track{background:linear-gradient(theme(colors.tint.100) 0 0) scroll no-repeat 50% /100% .25rem;border-radius:99px;height:1rem}}}
|