Skip to content

Commit 2ba75ca

Browse files
committed
Improve commerce demo bundle
1 parent 5cd8c5a commit 2ba75ca

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

examples/demo/src/dashboard/OrderChart.tsx

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,61 @@
11
import * as React from 'react';
22
import { Card, CardHeader, CardContent } from '@mui/material';
3-
import * as echarts from 'echarts';
3+
import * as echarts from 'echarts/core';
4+
// Import bar charts, all suffixed with Chart
5+
import { LineChart } from 'echarts/charts';
6+
7+
// Import the title, tooltip, rectangular coordinate system, dataset and transform components
8+
import {
9+
TitleComponent,
10+
TooltipComponent,
11+
GridComponent,
12+
DatasetComponent,
13+
TransformComponent,
14+
} from 'echarts/components';
415
import { useTranslate } from 'react-admin';
16+
// Features like Universal Transition and Label Layout
17+
import { LabelLayout, UniversalTransition } from 'echarts/features';
18+
19+
// Import the Canvas renderer
20+
// Note that including the CanvasRenderer or SVGRenderer is a required step
21+
import { SVGRenderer } from 'echarts/renderers';
22+
523
import { format, subDays, addDays } from 'date-fns';
624

725
import { Order } from '../types';
26+
import type {
27+
DatasetComponentOption,
28+
GridComponentOption,
29+
LineSeriesOption,
30+
TitleComponentOption,
31+
TooltipComponentOption,
32+
} from 'echarts';
833

934
const lastDay = new Date();
1035
const lastMonthDays = Array.from({ length: 30 }, (_, i) => subDays(lastDay, i));
1136
const aMonthAgo = subDays(new Date(), 30);
1237

38+
// Create an Option type with only the required components and charts via ComposeOption
39+
type ECOption = echarts.ComposeOption<
40+
| LineSeriesOption
41+
| TitleComponentOption
42+
| TooltipComponentOption
43+
| GridComponentOption
44+
| DatasetComponentOption
45+
>;
46+
47+
echarts.use([
48+
TitleComponent,
49+
TooltipComponent,
50+
GridComponent,
51+
DatasetComponent,
52+
TransformComponent,
53+
LineChart,
54+
LabelLayout,
55+
UniversalTransition,
56+
SVGRenderer,
57+
]);
58+
1359
const dateFormatter = (date: number): string =>
1460
new Date(date).toLocaleDateString();
1561

@@ -53,7 +99,7 @@ const OrderChart = (props: { orders?: Order[] }) => {
5399
const revenueData = getRevenuePerDay(orders);
54100

55101
// Configure the chart
56-
const option = {
102+
const option: ECOption = {
57103
xAxis: {
58104
type: 'time',
59105
min: addDays(aMonthAgo, 1).getTime(),
@@ -90,8 +136,7 @@ const OrderChart = (props: { orders?: Order[] }) => {
90136
axisPointer: {
91137
type: 'line',
92138
lineStyle: {
93-
type: 'dashed',
94-
dashArray: [3, 3],
139+
type: [3, 3],
95140
},
96141
},
97142
},

examples/demo/vite.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ export default defineConfig(async ({ mode }) => {
4747
}),
4848
],
4949
define: {
50-
'process.env': process.env,
50+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
51+
'process.env.REACT_APP_DATA_PROVIDER': JSON.stringify(
52+
process.env.REACT_APP_DATA_PROVIDER
53+
),
5154
},
5255
server: {
5356
port: 8000,

0 commit comments

Comments
 (0)