@tsingroc/tsingroc-components 5.0.1 → 5.1.0

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.
Files changed (82) hide show
  1. package/dist/components/BarLineChart/BarLineChart.module.css +10 -0
  2. package/dist/components/BarLineChart/index.d.ts +66 -0
  3. package/dist/components/BarLineChart/index.js +590 -0
  4. package/dist/components/BaseBarChart/BaseBarChart.module.css +12 -0
  5. package/dist/components/BaseBarChart/index.d.ts +33 -0
  6. package/dist/components/BaseBarChart/index.js +121 -0
  7. package/dist/components/DataCellNumber/DataCellNumber.module.css +20 -0
  8. package/dist/components/DataCellNumber/index.d.ts +14 -0
  9. package/dist/components/DataCellNumber/index.js +142 -0
  10. package/dist/components/FlexColLayout/index.d.ts +6 -0
  11. package/dist/components/FlexColLayout/index.js +40 -0
  12. package/dist/components/FlexRowLayout/index.d.ts +5 -0
  13. package/dist/components/FlexRowLayout/index.js +45 -0
  14. package/dist/components/HighlightSyncedECharts/index.d.ts +47 -0
  15. package/dist/components/HighlightSyncedECharts/index.js +260 -0
  16. package/dist/components/HighlightSyncedTable/index.d.ts +8 -0
  17. package/dist/components/HighlightSyncedTable/index.js +183 -0
  18. package/dist/components/LoadingSection/index.d.ts +41 -0
  19. package/dist/components/LoadingSection/index.js +183 -0
  20. package/dist/components/LoadingSkeleton/index.d.ts +42 -0
  21. package/dist/components/LoadingSkeleton/index.js +634 -0
  22. package/dist/components/ScrollableTable/ScrollableTable.module.css +21 -0
  23. package/dist/components/ScrollableTable/index.d.ts +13 -0
  24. package/dist/components/ScrollableTable/index.js +29 -0
  25. package/dist/components/TsingrocTable/TsingrocTable.module.css +32 -0
  26. package/dist/components/TsingrocTable/index.d.ts +12 -0
  27. package/dist/components/TsingrocTable/index.js +23 -0
  28. package/dist/components/TsingrocTheme/index.js +3 -3
  29. package/dist/index.d.ts +4 -0
  30. package/dist/index.js +4 -0
  31. package/dist/pages/DayAheadReviewPage/components/PricePlot/index.d.ts +7 -0
  32. package/dist/pages/DayAheadReviewPage/components/PricePlot/index.js +136 -0
  33. package/dist/pages/DayAheadReviewPage/components/ProfitBarChart/ProfitBarChart.module.css +13 -0
  34. package/dist/pages/DayAheadReviewPage/components/ProfitBarChart/index.d.ts +17 -0
  35. package/dist/pages/DayAheadReviewPage/components/ProfitBarChart/index.js +278 -0
  36. package/dist/pages/DayAheadReviewPage/components/RevenueCard/RevenueCard.module.css +40 -0
  37. package/dist/pages/DayAheadReviewPage/components/RevenueCard/index.d.ts +9 -0
  38. package/dist/pages/DayAheadReviewPage/components/RevenueCard/index.js +195 -0
  39. package/dist/pages/DayAheadReviewPage/components/RevenueSummaryCard/RevenueSummaryCard.module.css +38 -0
  40. package/dist/pages/DayAheadReviewPage/components/RevenueSummaryCard/index.d.ts +10 -0
  41. package/dist/pages/DayAheadReviewPage/components/RevenueSummaryCard/index.js +117 -0
  42. package/dist/pages/DayAheadReviewPage/components/ReviewLineChart/ReviewLineChart.module.css +11 -0
  43. package/dist/pages/DayAheadReviewPage/components/ReviewLineChart/index.d.ts +53 -0
  44. package/dist/pages/DayAheadReviewPage/components/ReviewLineChart/index.js +398 -0
  45. package/dist/pages/DayAheadReviewPage/components/ReviewSummaryTable/ReviewSummaryTable.module.css +33 -0
  46. package/dist/pages/DayAheadReviewPage/components/ReviewSummaryTable/index.d.ts +17 -0
  47. package/dist/pages/DayAheadReviewPage/components/ReviewSummaryTable/index.js +187 -0
  48. package/dist/pages/DayAheadReviewPage/components/StrategyPlot/index.d.ts +10 -0
  49. package/dist/pages/DayAheadReviewPage/components/StrategyPlot/index.js +223 -0
  50. package/dist/pages/DayAheadReviewPage/components/SummaryTable/index.d.ts +7 -0
  51. package/dist/pages/DayAheadReviewPage/components/SummaryTable/index.js +39 -0
  52. package/dist/pages/DayAheadReviewPage/components/SummaryTable/useTableColumns.d.ts +10 -0
  53. package/dist/pages/DayAheadReviewPage/components/SummaryTable/useTableColumns.js +307 -0
  54. package/dist/pages/DayAheadReviewPage/hook/useDayAheadReviewDate.d.ts +137 -0
  55. package/dist/pages/DayAheadReviewPage/hook/useDayAheadReviewDate.js +252 -0
  56. package/dist/pages/DayAheadReviewPage/index.d.ts +149 -0
  57. package/dist/pages/DayAheadReviewPage/index.js +259 -0
  58. package/dist/pages/DayAheadReviewPage/layout/LeftChartContainer.d.ts +12 -0
  59. package/dist/pages/DayAheadReviewPage/layout/LeftChartContainer.js +236 -0
  60. package/dist/pages/DayAheadReviewPage/layout/ReviewPageLayout.d.ts +4 -0
  61. package/dist/pages/DayAheadReviewPage/layout/ReviewPageLayout.js +32 -0
  62. package/dist/pages/DayAheadReviewPage/layout/RightSummaryContainer.d.ts +14 -0
  63. package/dist/pages/DayAheadReviewPage/layout/RightSummaryContainer.js +199 -0
  64. package/dist/pages/DayAheadReviewPage/layout/TopDayReviewHeader.d.ts +9 -0
  65. package/dist/pages/DayAheadReviewPage/layout/TopDayReviewHeader.js +115 -0
  66. package/dist/pages/DayAheadReviewPage/types/dayahead.d.ts +172 -0
  67. package/dist/pages/DayAheadReviewPage/types/dayahead.js +1 -0
  68. package/dist/utils/accessibility.d.ts +114 -0
  69. package/dist/utils/accessibility.js +214 -0
  70. package/dist/utils/constants.d.ts +18 -0
  71. package/dist/utils/constants.js +34 -0
  72. package/dist/utils/export.d.ts +10 -0
  73. package/dist/utils/export.js +72 -0
  74. package/dist/utils/formatters.d.ts +46 -0
  75. package/dist/utils/formatters.js +84 -0
  76. package/dist/utils/index.d.ts +1 -0
  77. package/dist/utils/index.js +1 -0
  78. package/dist/utils/presenters.d.ts +24 -0
  79. package/dist/utils/presenters.js +48 -0
  80. package/dist/utils/ui.d.ts +116 -0
  81. package/dist/utils/ui.js +171 -0
  82. package/package.json +32 -31
@@ -0,0 +1,121 @@
1
+ import { Card } from "antd";
2
+ import * as echarts from "#src/echarts";
3
+ import { COLOR_CHART_AXIS } from "#src/utils/constants";
4
+ import HighlightSyncedECharts from "../HighlightSyncedECharts";
5
+ import styles from "./BaseBarChart.module.css";
6
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
7
+ /** Default x-axis labels when no data (match ReviewLineChart: 00:00–24:00). */
8
+ const DEFAULT_CATEGORIES = [...Array.from({
9
+ length: 24
10
+ }, (_, i) => `${String(i).padStart(2, "0")}:00`), "24:00"];
11
+ export default function BaseBarChart({
12
+ title,
13
+ categories,
14
+ series,
15
+ yAxisName,
16
+ gridOption,
17
+ tooltipValueFormatter = v => String(v),
18
+ showLegend = true,
19
+ showSplitLine = true
20
+ }) {
21
+ const effectiveCategories = categories.length > 0 ? categories : DEFAULT_CATEGORIES;
22
+ const seriesWithValues = series.filter(s => s.data.some(v_0 => typeof v_0 === "number" && !Number.isNaN(v_0)));
23
+ const barWidth = seriesWithValues.length > 1 ? "30%" : "50%";
24
+ return /*#__PURE__*/_jsxs(Card, {
25
+ className: styles.root,
26
+ styles: {
27
+ body: {
28
+ height: "100%",
29
+ width: "100%",
30
+ padding: 0,
31
+ minHeight: 200,
32
+ display: "flex",
33
+ flexDirection: "column"
34
+ }
35
+ },
36
+ children: [title != null && title !== "" && /*#__PURE__*/_jsx("div", {
37
+ style: {
38
+ fontSize: "1.1rem"
39
+ },
40
+ children: /*#__PURE__*/_jsx("span", {
41
+ children: title
42
+ })
43
+ }), /*#__PURE__*/_jsx(HighlightSyncedECharts, {
44
+ className: styles.chartContainer,
45
+ style: {
46
+ height: "100%"
47
+ },
48
+ option: echarts.buildEChartsOption({}, echarts.grid({
49
+ option: {
50
+ left: gridOption?.left ?? 0,
51
+ right: gridOption?.right ?? 0,
52
+ top: gridOption?.top ?? 10,
53
+ bottom: gridOption?.bottom ?? 0
54
+ },
55
+ xAxis: {
56
+ type: "category",
57
+ boundaryGap: true,
58
+ data: effectiveCategories,
59
+ show: true,
60
+ axisLine: {
61
+ show: true,
62
+ lineStyle: {
63
+ color: "#ADADAD",
64
+ width: 1
65
+ }
66
+ },
67
+ axisTick: {
68
+ show: true
69
+ },
70
+ axisLabel: {
71
+ show: true,
72
+ color: "#ADADAD",
73
+ fontSize: 11
74
+ }
75
+ },
76
+ yAxis: {
77
+ name: yAxisName ?? "",
78
+ nameTextStyle: {
79
+ color: COLOR_CHART_AXIS
80
+ },
81
+ show: true,
82
+ axisLabel: {
83
+ color: COLOR_CHART_AXIS,
84
+ show: true
85
+ },
86
+ axisLine: {
87
+ show: false
88
+ },
89
+ splitLine: {
90
+ show: showSplitLine
91
+ }
92
+ },
93
+ series: series.map(s_0 => echarts.barSeries({
94
+ name: s_0.name,
95
+ data: s_0.data.length > 0 ? s_0.data : [],
96
+ option: {
97
+ color: s_0.color,
98
+ barWidth,
99
+ tooltip: {
100
+ valueFormatter: value => tooltipValueFormatter(typeof value === "number" && !Number.isNaN(value) ? value : 0)
101
+ },
102
+ ...s_0.option
103
+ }
104
+ }))
105
+ }), showLegend ? echarts.legend({
106
+ // Legend should represent the configured series even if a series has only null gaps.
107
+ data: series.map(s_1 => s_1.name)
108
+ }) : {}, echarts.tooltip({
109
+ backgroundColor: "rgba(255, 255, 255, 0.95)",
110
+ borderColor: COLOR_CHART_AXIS,
111
+ position: ([x, y], _0, _1, _2, {
112
+ viewSize: [vw, vh],
113
+ contentSize: [, ch]
114
+ }) => ({
115
+ left: x + vw / 100,
116
+ top: Math.min(y + vw / 100, vh - (ch ?? 0) + 24)
117
+ })
118
+ }))
119
+ })]
120
+ });
121
+ }
@@ -0,0 +1,20 @@
1
+ .dataCell {
2
+ display: flex;
3
+ }
4
+
5
+ .dataCellLeft {
6
+ flex: 50%;
7
+ border-right: 1px solid #d3d3d3;
8
+ padding-inline: 4px;
9
+ display: flex;
10
+ align-items: center;
11
+ justify-content: flex-end;
12
+ color: #85008c;
13
+ }
14
+
15
+ .dataCellRight {
16
+ flex: 50%;
17
+ padding-inline: 4px;
18
+ text-align: left;
19
+ color: #ff6937;
20
+ }
@@ -0,0 +1,14 @@
1
+ type KeysMatching<T, V> = {
2
+ [K in keyof T]-?: Exclude<T[K], undefined> extends V ? K : never;
3
+ }[keyof T];
4
+ /** Keys that hold number or number | null (for editable numeric cells) */
5
+ type NumericKey<T> = KeysMatching<T, number> | KeysMatching<T, number | null>;
6
+ export declare function DataCellNumber<Value>({ value1, value2, modified, fractionDigits, valueKey, onChange }: {
7
+ value1: number | null;
8
+ value2?: number | null;
9
+ modified?: boolean;
10
+ fractionDigits?: number;
11
+ valueKey: NumericKey<Value>;
12
+ onChange?: (key: NumericKey<Value>, value: number) => void;
13
+ }): import("react/jsx-runtime").JSX.Element;
14
+ export {};
@@ -0,0 +1,142 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { InputNumber } from "antd";
3
+ import { COLOR_POWER_MANUAL } from "#src/utils/constants";
4
+ import styles from "./DataCellNumber.module.css";
5
+
6
+ /** Keys that hold number or number | null (for editable numeric cells) */
7
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
+ function DataCell(t0) {
9
+ const $ = _c(17);
10
+ const {
11
+ value1,
12
+ value2,
13
+ formatter,
14
+ editorRender
15
+ } = t0;
16
+ if (value2 !== undefined) {
17
+ let t1;
18
+ if ($[0] !== formatter || $[1] !== value1) {
19
+ t1 = formatter(value1);
20
+ $[0] = formatter;
21
+ $[1] = value1;
22
+ $[2] = t1;
23
+ } else {
24
+ t1 = $[2];
25
+ }
26
+ let t2;
27
+ if ($[3] !== t1) {
28
+ t2 = /*#__PURE__*/_jsx("div", {
29
+ className: styles.dataCellLeft,
30
+ children: t1
31
+ });
32
+ $[3] = t1;
33
+ $[4] = t2;
34
+ } else {
35
+ t2 = $[4];
36
+ }
37
+ let t3;
38
+ if ($[5] !== editorRender || $[6] !== formatter || $[7] !== value2) {
39
+ t3 = editorRender ? editorRender(value2) : formatter(value2);
40
+ $[5] = editorRender;
41
+ $[6] = formatter;
42
+ $[7] = value2;
43
+ $[8] = t3;
44
+ } else {
45
+ t3 = $[8];
46
+ }
47
+ let t4;
48
+ if ($[9] !== t3) {
49
+ t4 = /*#__PURE__*/_jsx("div", {
50
+ className: styles.dataCellRight,
51
+ children: t3
52
+ });
53
+ $[9] = t3;
54
+ $[10] = t4;
55
+ } else {
56
+ t4 = $[10];
57
+ }
58
+ let t5;
59
+ if ($[11] !== t2 || $[12] !== t4) {
60
+ t5 = /*#__PURE__*/_jsxs("div", {
61
+ className: styles.dataCell,
62
+ children: [t2, t4]
63
+ });
64
+ $[11] = t2;
65
+ $[12] = t4;
66
+ $[13] = t5;
67
+ } else {
68
+ t5 = $[13];
69
+ }
70
+ return t5;
71
+ } else {
72
+ let t1;
73
+ if ($[14] !== formatter || $[15] !== value1) {
74
+ t1 = formatter(value1);
75
+ $[14] = formatter;
76
+ $[15] = value1;
77
+ $[16] = t1;
78
+ } else {
79
+ t1 = $[16];
80
+ }
81
+ return t1;
82
+ }
83
+ }
84
+ export function DataCellNumber(t0) {
85
+ const $ = _c(12);
86
+ const {
87
+ value1,
88
+ value2,
89
+ modified,
90
+ fractionDigits: t1,
91
+ valueKey,
92
+ onChange
93
+ } = t0;
94
+ const fractionDigits = t1 === undefined ? 3 : t1;
95
+ let t2;
96
+ if ($[0] !== fractionDigits) {
97
+ t2 = value => value == null ? "" : value.toFixed(fractionDigits);
98
+ $[0] = fractionDigits;
99
+ $[1] = t2;
100
+ } else {
101
+ t2 = $[1];
102
+ }
103
+ const formatter = t2;
104
+ let t3;
105
+ if ($[2] !== fractionDigits || $[3] !== modified || $[4] !== onChange || $[5] !== valueKey) {
106
+ t3 = onChange && (value_0 => /*#__PURE__*/_jsx(InputNumber, {
107
+ value: value_0 ?? 0,
108
+ formatter: v => v != null ? Number(v).toFixed(fractionDigits) : "",
109
+ min: 0,
110
+ onChange: v_0 => v_0 !== null && onChange(valueKey, v_0),
111
+ styles: {
112
+ input: {
113
+ color: modified ? COLOR_POWER_MANUAL : undefined
114
+ }
115
+ }
116
+ }));
117
+ $[2] = fractionDigits;
118
+ $[3] = modified;
119
+ $[4] = onChange;
120
+ $[5] = valueKey;
121
+ $[6] = t3;
122
+ } else {
123
+ t3 = $[6];
124
+ }
125
+ let t4;
126
+ if ($[7] !== formatter || $[8] !== t3 || $[9] !== value1 || $[10] !== value2) {
127
+ t4 = /*#__PURE__*/_jsx(DataCell, {
128
+ value1: value1,
129
+ value2: value2,
130
+ formatter: formatter,
131
+ editorRender: t3
132
+ });
133
+ $[7] = formatter;
134
+ $[8] = t3;
135
+ $[9] = value1;
136
+ $[10] = value2;
137
+ $[11] = t4;
138
+ } else {
139
+ t4 = $[11];
140
+ }
141
+ return t4;
142
+ }
@@ -0,0 +1,6 @@
1
+ declare const FlexColLayout: ({ children, style, gap }: {
2
+ children: React.ReactNode;
3
+ style?: React.CSSProperties;
4
+ gap?: number;
5
+ }) => import("react/jsx-runtime").JSX.Element;
6
+ export default FlexColLayout;
@@ -0,0 +1,40 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ const FlexColLayout = t0 => {
4
+ const $ = _c(6);
5
+ const {
6
+ children,
7
+ style,
8
+ gap: t1
9
+ } = t0;
10
+ const gap = t1 === undefined ? 16 : t1;
11
+ let t2;
12
+ if ($[0] !== gap || $[1] !== style) {
13
+ t2 = {
14
+ display: "flex",
15
+ flexDirection: "column",
16
+ gap,
17
+ height: "100%",
18
+ ...style
19
+ };
20
+ $[0] = gap;
21
+ $[1] = style;
22
+ $[2] = t2;
23
+ } else {
24
+ t2 = $[2];
25
+ }
26
+ let t3;
27
+ if ($[3] !== children || $[4] !== t2) {
28
+ t3 = /*#__PURE__*/_jsx("div", {
29
+ style: t2,
30
+ children: children
31
+ });
32
+ $[3] = children;
33
+ $[4] = t2;
34
+ $[5] = t3;
35
+ } else {
36
+ t3 = $[5];
37
+ }
38
+ return t3;
39
+ };
40
+ export default FlexColLayout;
@@ -0,0 +1,5 @@
1
+ declare const FlexRowLayout: ({ children, styles }: {
2
+ children: React.ReactNode;
3
+ styles?: React.CSSProperties;
4
+ }) => import("react/jsx-runtime").JSX.Element;
5
+ export default FlexRowLayout;
@@ -0,0 +1,45 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ const FlexRowLayout = t0 => {
4
+ const $ = _c(7);
5
+ const {
6
+ children,
7
+ styles: t1
8
+ } = t0;
9
+ let t2;
10
+ if ($[0] !== t1) {
11
+ t2 = t1 === undefined ? {} : t1;
12
+ $[0] = t1;
13
+ $[1] = t2;
14
+ } else {
15
+ t2 = $[1];
16
+ }
17
+ const styles = t2;
18
+ let t3;
19
+ if ($[2] !== styles) {
20
+ t3 = {
21
+ display: "flex",
22
+ flexDirection: "row",
23
+ gap: 16,
24
+ ...styles
25
+ };
26
+ $[2] = styles;
27
+ $[3] = t3;
28
+ } else {
29
+ t3 = $[3];
30
+ }
31
+ let t4;
32
+ if ($[4] !== children || $[5] !== t3) {
33
+ t4 = /*#__PURE__*/_jsx("div", {
34
+ style: t3,
35
+ children: children
36
+ });
37
+ $[4] = children;
38
+ $[5] = t3;
39
+ $[6] = t4;
40
+ } else {
41
+ t4 = $[6];
42
+ }
43
+ return t4;
44
+ };
45
+ export default FlexRowLayout;
@@ -0,0 +1,47 @@
1
+ import type { EChartsHOCType } from "../ECharts";
2
+ export type Highlight = {
3
+ source: string;
4
+ index: number;
5
+ } | undefined;
6
+ /**
7
+ * 为 {@linkcode HighlightSyncedECharts}/{@linkcode withHighlightSync | withHighlightSync(ECharts)}
8
+ * 提供联动上下文,只有同一个上下文内的 ECharts 会联动。
9
+ */
10
+ export declare function HighlightProvider({ children }: {
11
+ children: React.ReactNode;
12
+ }): import("react/jsx-runtime").JSX.Element;
13
+ /**
14
+ * 获取当前高亮同步上下文的高亮状态和更新函数。
15
+ */
16
+ export declare function useHighlight(): [Highlight, import("react").Dispatch<import("react").SetStateAction<Highlight>>];
17
+ /**
18
+ * 在当前高亮同步上下文内消费高亮状态和更新函数。
19
+ */
20
+ export declare const HighlightConsumer: import("react").Consumer<[Highlight, import("react").Dispatch<import("react").SetStateAction<Highlight>>]>;
21
+ /**
22
+ * 为 ECharts 增加高亮同步能力。所有添加了该能力的 ECharts 的高亮位置都会同步。
23
+ * 还可以通过 {@linkcode useHighlight} 或者 {@linkcode HighlightConsumer}
24
+ * 将图的高亮与其它东西联动(例如使用 {@linkcode HighlightSyncedTable} 使图和表的高亮同步)。
25
+ *
26
+ * 请不要和 {@linkcode withConnector} 一同使用。
27
+ * 如果你只需要在图和图之间联动,不需要和图以外的东西联动,那么推荐使用 {@linkcode withConnector}。
28
+ *
29
+ * 必须包裹在 {@linkcode HighlightProvider} 内使用。
30
+ */
31
+ export declare const withHighlightSync: EChartsHOCType<{
32
+ highlightSeriesIndex?: number;
33
+ }>;
34
+ /**
35
+ * 预置了高亮同步和自适应容器尺寸能力的 ECharts。
36
+ * 可以通过 {@linkcode useHighlight} 或者 {@linkcode HighlightConsumer}
37
+ * 将图的高亮与其它东西联动(例如使用 {@linkcode HighlightSyncedTable} 使图和表的高亮同步)。
38
+ *
39
+ * 必须包裹在 {@linkcode HighlightProvider} 内使用。
40
+ *
41
+ * @see {@linkcode withHighlightSync}
42
+ * @see {@linkcode withAutoResize}
43
+ */
44
+ declare const HighlightSyncedECharts: import("../ECharts").EChartsComponentType<{
45
+ highlightSeriesIndex?: number;
46
+ }>;
47
+ export default HighlightSyncedECharts;
@@ -0,0 +1,260 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { createContext, use, useEffect, useEffectEvent, useId, useImperativeHandle, useRef, useState } from "react";
3
+ import { debugAssert } from "#src/utils/debug";
4
+ import AutoResizedECharts from "../AutoResizedECharts"; // oxlint-disable-line no-unused-vars
5
+ // oxlint-disable-line no-unused-vars
6
+
7
+ // oxlint-disable-line no-unused-vars
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ const HighlightContext = /*#__PURE__*/createContext([undefined, () => {}]);
10
+
11
+ /**
12
+ * 为 {@linkcode HighlightSyncedECharts}/{@linkcode withHighlightSync | withHighlightSync(ECharts)}
13
+ * 提供联动上下文,只有同一个上下文内的 ECharts 会联动。
14
+ */
15
+ export function HighlightProvider(t0) {
16
+ const $ = _c(3);
17
+ const {
18
+ children
19
+ } = t0;
20
+ const getterSetter = useState(undefined);
21
+ let t1;
22
+ if ($[0] !== children || $[1] !== getterSetter) {
23
+ t1 = /*#__PURE__*/_jsx(HighlightContext.Provider, {
24
+ value: getterSetter,
25
+ children: children
26
+ });
27
+ $[0] = children;
28
+ $[1] = getterSetter;
29
+ $[2] = t1;
30
+ } else {
31
+ t1 = $[2];
32
+ }
33
+ return t1;
34
+ }
35
+
36
+ /**
37
+ * 获取当前高亮同步上下文的高亮状态和更新函数。
38
+ */
39
+ export function useHighlight() {
40
+ return use(HighlightContext);
41
+ }
42
+
43
+ /**
44
+ * 在当前高亮同步上下文内消费高亮状态和更新函数。
45
+ */
46
+ export const HighlightConsumer = HighlightContext.Consumer;
47
+
48
+ /**
49
+ * 为 ECharts 增加高亮同步能力。所有添加了该能力的 ECharts 的高亮位置都会同步。
50
+ * 还可以通过 {@linkcode useHighlight} 或者 {@linkcode HighlightConsumer}
51
+ * 将图的高亮与其它东西联动(例如使用 {@linkcode HighlightSyncedTable} 使图和表的高亮同步)。
52
+ *
53
+ * 请不要和 {@linkcode withConnector} 一同使用。
54
+ * 如果你只需要在图和图之间联动,不需要和图以外的东西联动,那么推荐使用 {@linkcode withConnector}。
55
+ *
56
+ * 必须包裹在 {@linkcode HighlightProvider} 内使用。
57
+ */
58
+ export const withHighlightSync = ECharts => function HighlightSyncedECharts(props) {
59
+ "use memo";
60
+
61
+ const $ = _c(27);
62
+ let onInit;
63
+ let outerRef;
64
+ let rest;
65
+ let t0;
66
+ if ($[0] !== props) {
67
+ ({
68
+ ref: outerRef,
69
+ onInit,
70
+ highlightSeriesIndex: t0,
71
+ ...rest
72
+ } = props);
73
+ $[0] = props;
74
+ $[1] = onInit;
75
+ $[2] = outerRef;
76
+ $[3] = rest;
77
+ $[4] = t0;
78
+ } else {
79
+ onInit = $[1];
80
+ outerRef = $[2];
81
+ rest = $[3];
82
+ t0 = $[4];
83
+ }
84
+ const highlightSeriesIndex = t0 === undefined ? 0 : t0;
85
+ const id = useId();
86
+ const [highlight, setHighlight] = use(HighlightContext);
87
+ const ref = useRef(null);
88
+ let t1;
89
+ let t2;
90
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
91
+ t1 = () => {
92
+ debugAssert(ref.current, "ref should be connected");
93
+ return ref.current;
94
+ };
95
+ t2 = [];
96
+ $[5] = t1;
97
+ $[6] = t2;
98
+ } else {
99
+ t1 = $[5];
100
+ t2 = $[6];
101
+ }
102
+ useImperativeHandle(outerRef, t1, t2);
103
+ let t3;
104
+ if ($[7] !== highlightSeriesIndex || $[8] !== id) {
105
+ t3 = (instance, highlight_0) => {
106
+ if (highlight_0) {
107
+ if (highlight_0.source === id) {
108
+ return;
109
+ }
110
+ const option = instance.getOption();
111
+ const series = option.series;
112
+ const targetSeries = series[highlightSeriesIndex];
113
+ const dataLength = Array.isArray(targetSeries?.data) ? targetSeries.data.length : 0;
114
+ if (highlight_0.index < 0 || highlight_0.index >= dataLength) {
115
+ return;
116
+ }
117
+ instance.setOption({
118
+ xAxis: {
119
+ axisPointer: {
120
+ status: "show",
121
+ value: highlight_0.index
122
+ }
123
+ }
124
+ });
125
+ instance.dispatchAction({
126
+ type: "highlight",
127
+ seriesIndex: highlightSeriesIndex,
128
+ dataIndexInside: highlight_0.index
129
+ }, {
130
+ silent: true
131
+ });
132
+ instance.dispatchAction({
133
+ type: "showTip",
134
+ seriesIndex: highlightSeriesIndex,
135
+ dataIndex: highlight_0.index
136
+ }, {
137
+ silent: true
138
+ });
139
+ } else {
140
+ instance.setOption({
141
+ xAxis: {
142
+ axisPointer: {
143
+ status: "hide",
144
+ value: undefined
145
+ }
146
+ }
147
+ });
148
+ instance.dispatchAction({
149
+ type: "downplay",
150
+ seriesIndex: highlightSeriesIndex
151
+ }, {
152
+ silent: true
153
+ });
154
+ instance.dispatchAction({
155
+ type: "hideTip"
156
+ }, {
157
+ silent: true
158
+ });
159
+ }
160
+ };
161
+ $[7] = highlightSeriesIndex;
162
+ $[8] = id;
163
+ $[9] = t3;
164
+ } else {
165
+ t3 = $[9];
166
+ }
167
+ const onHighlightChange = useEffectEvent(t3);
168
+ let t4;
169
+ if ($[10] !== highlight || $[11] !== onHighlightChange) {
170
+ t4 = () => {
171
+ const instance_0 = ref.current?.instance;
172
+ if (!instance_0) {
173
+ return;
174
+ }
175
+ onHighlightChange(instance_0, highlight);
176
+ };
177
+ $[10] = highlight;
178
+ $[11] = onHighlightChange;
179
+ $[12] = t4;
180
+ } else {
181
+ t4 = $[12];
182
+ }
183
+ let t5;
184
+ if ($[13] !== highlight) {
185
+ t5 = [highlight];
186
+ $[13] = highlight;
187
+ $[14] = t5;
188
+ } else {
189
+ t5 = $[14];
190
+ }
191
+ useEffect(t4, t5);
192
+ let t6;
193
+ if ($[15] !== highlight || $[16] !== highlightSeriesIndex || $[17] !== id || $[18] !== setHighlight) {
194
+ t6 = event => {
195
+ if (!event.batch) {
196
+ return;
197
+ }
198
+ const elementEvent = event.batch.find(it => it.seriesIndex === highlightSeriesIndex);
199
+ if (!elementEvent) {
200
+ return;
201
+ }
202
+ if (highlight?.source === id && highlight.index === elementEvent.dataIndexInside) {
203
+ return;
204
+ }
205
+ setHighlight({
206
+ source: id,
207
+ index: elementEvent.dataIndexInside
208
+ });
209
+ };
210
+ $[15] = highlight;
211
+ $[16] = highlightSeriesIndex;
212
+ $[17] = id;
213
+ $[18] = setHighlight;
214
+ $[19] = t6;
215
+ } else {
216
+ t6 = $[19];
217
+ }
218
+ const onHighlight = useEffectEvent(t6);
219
+ let t7;
220
+ if ($[20] !== onHighlight || $[21] !== onInit || $[22] !== setHighlight) {
221
+ t7 = instance_1 => {
222
+ instance_1.on("highlight", event_0 => onHighlight(event_0));
223
+ instance_1.on("downplay", () => setHighlight(undefined));
224
+ return onInit?.(instance_1);
225
+ };
226
+ $[20] = onHighlight;
227
+ $[21] = onInit;
228
+ $[22] = setHighlight;
229
+ $[23] = t7;
230
+ } else {
231
+ t7 = $[23];
232
+ }
233
+ let t8;
234
+ if ($[24] !== rest || $[25] !== t7) {
235
+ t8 = /*#__PURE__*/_jsx(ECharts, {
236
+ ref: ref,
237
+ onInit: t7,
238
+ ...rest
239
+ });
240
+ $[24] = rest;
241
+ $[25] = t7;
242
+ $[26] = t8;
243
+ } else {
244
+ t8 = $[26];
245
+ }
246
+ return t8;
247
+ };
248
+
249
+ /**
250
+ * 预置了高亮同步和自适应容器尺寸能力的 ECharts。
251
+ * 可以通过 {@linkcode useHighlight} 或者 {@linkcode HighlightConsumer}
252
+ * 将图的高亮与其它东西联动(例如使用 {@linkcode HighlightSyncedTable} 使图和表的高亮同步)。
253
+ *
254
+ * 必须包裹在 {@linkcode HighlightProvider} 内使用。
255
+ *
256
+ * @see {@linkcode withHighlightSync}
257
+ * @see {@linkcode withAutoResize}
258
+ */
259
+ const HighlightSyncedECharts = withHighlightSync(AutoResizedECharts);
260
+ export default HighlightSyncedECharts;