@ant-design/agentic-ui 2.16.0 → 2.16.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/dist/MarkdownEditor/editor/elements/Code.js +11 -6
- package/dist/MarkdownEditor/editor/elements/Table/ReadonlyTableComponent.js +15 -3
- package/dist/MarkdownEditor/editor/elements/Table/SimpleTable.js +17 -2
- package/dist/MarkdownEditor/editor/elements/Table/Table.js +131 -5
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.d.ts +100 -1
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +781 -240
- package/dist/MarkdownEditor/editor/types/Table.d.ts +1 -0
- package/dist/MarkdownEditor/editor/utils/findMatchingClose.d.ts +36 -0
- package/dist/MarkdownEditor/editor/utils/findMatchingClose.js +158 -0
- package/dist/MarkdownEditor/editor/utils/markdownToHtml.d.ts +41 -2
- package/dist/MarkdownEditor/editor/utils/markdownToHtml.js +159 -7
- package/dist/Plugins/chart/AreaChart/index.d.ts +12 -0
- package/dist/Plugins/chart/AreaChart/index.js +14 -188
- package/dist/Plugins/chart/BarChart/index.d.ts +2 -0
- package/dist/Plugins/chart/BarChart/index.js +3 -12
- package/dist/Plugins/chart/ChartMark/Container.js +5 -2
- package/dist/Plugins/chart/ChartRender.d.ts +1 -0
- package/dist/Plugins/chart/ChartRender.js +104 -43
- package/dist/Plugins/chart/DonutChart/index.js +4 -2
- package/dist/Plugins/chart/DonutChart/types.d.ts +2 -0
- package/dist/Plugins/chart/FunnelChart/index.d.ts +2 -0
- package/dist/Plugins/chart/FunnelChart/index.js +4 -2
- package/dist/Plugins/chart/LineChart/index.d.ts +2 -0
- package/dist/Plugins/chart/LineChart/index.js +17 -162
- package/dist/Plugins/chart/RadarChart/index.d.ts +2 -0
- package/dist/Plugins/chart/RadarChart/index.js +8 -4
- package/dist/Plugins/chart/ScatterChart/index.d.ts +2 -0
- package/dist/Plugins/chart/ScatterChart/index.js +8 -4
- package/dist/Plugins/chart/components/ChartContainer/ChartContainer.d.ts +1 -0
- package/dist/Plugins/chart/components/ChartFilter/ChartFilter.d.ts +1 -1
- package/dist/Plugins/chart/components/ChartFilter/ChartFilter.js +210 -16
- package/dist/Plugins/chart/components/ChartToolBar/ChartToolBar.d.ts +2 -0
- package/dist/Plugins/chart/components/ChartToolBar/ChartToolBar.js +9 -2
- package/dist/Plugins/chart/components/ChartToolBar/style.js +3 -1
- package/dist/Plugins/chart/hooks/index.d.ts +10 -0
- package/dist/Plugins/chart/hooks/index.js +8 -0
- package/dist/Plugins/chart/hooks/useChartDataFilter.d.ts +46 -0
- package/dist/Plugins/chart/hooks/useChartDataFilter.js +182 -0
- package/dist/Plugins/chart/hooks/useChartStatistics.d.ts +17 -0
- package/dist/Plugins/chart/hooks/useChartStatistics.js +25 -0
- package/dist/Plugins/chart/hooks/useChartTheme.d.ts +20 -0
- package/dist/Plugins/chart/hooks/useChartTheme.js +30 -0
- package/dist/Plugins/chart/hooks/useResponsiveSize.d.ts +23 -0
- package/dist/Plugins/chart/hooks/useResponsiveSize.js +94 -0
- package/dist/Plugins/chart/index.js +92 -8
- package/dist/Plugins/chart/utils/registerChart.d.ts +35 -0
- package/dist/Plugins/chart/utils/registerChart.js +54 -0
- package/dist/Plugins/chart/utils.d.ts +19 -0
- package/dist/Plugins/chart/utils.js +27 -0
- package/dist/Plugins/code/components/CodeRenderer.js +53 -2
- package/dist/Plugins/code/components/CodeToolbar.js +22 -3
- package/dist/Plugins/mermaid/Mermaid.js +66 -66
- package/package.json +1 -1
|
@@ -3,9 +3,6 @@ function _array_like_to_array(arr, len) {
|
|
|
3
3
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
4
|
return arr2;
|
|
5
5
|
}
|
|
6
|
-
function _array_with_holes(arr) {
|
|
7
|
-
if (Array.isArray(arr)) return arr;
|
|
8
|
-
}
|
|
9
6
|
function _array_without_holes(arr) {
|
|
10
7
|
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
11
8
|
}
|
|
@@ -25,33 +22,6 @@ function _define_property(obj, key, value) {
|
|
|
25
22
|
function _iterable_to_array(iter) {
|
|
26
23
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
27
24
|
}
|
|
28
|
-
function _iterable_to_array_limit(arr, i) {
|
|
29
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
30
|
-
if (_i == null) return;
|
|
31
|
-
var _arr = [];
|
|
32
|
-
var _n = true;
|
|
33
|
-
var _d = false;
|
|
34
|
-
var _s, _e;
|
|
35
|
-
try {
|
|
36
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
37
|
-
_arr.push(_s.value);
|
|
38
|
-
if (i && _arr.length === i) break;
|
|
39
|
-
}
|
|
40
|
-
} catch (err) {
|
|
41
|
-
_d = true;
|
|
42
|
-
_e = err;
|
|
43
|
-
} finally{
|
|
44
|
-
try {
|
|
45
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
46
|
-
} finally{
|
|
47
|
-
if (_d) throw _e;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return _arr;
|
|
51
|
-
}
|
|
52
|
-
function _non_iterable_rest() {
|
|
53
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
54
|
-
}
|
|
55
25
|
function _non_iterable_spread() {
|
|
56
26
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
57
27
|
}
|
|
@@ -94,9 +64,6 @@ function _object_spread_props(target, source) {
|
|
|
94
64
|
}
|
|
95
65
|
return target;
|
|
96
66
|
}
|
|
97
|
-
function _sliced_to_array(arr, i) {
|
|
98
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
99
|
-
}
|
|
100
67
|
function _to_consumable_array(arr) {
|
|
101
68
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
102
69
|
}
|
|
@@ -109,49 +76,14 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
109
76
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
110
77
|
}
|
|
111
78
|
import { ConfigProvider } from "antd";
|
|
112
|
-
import { CategoryScale, Chart as ChartJS, Filler, Legend, LinearScale, LineElement, PointElement, Tooltip } from "chart.js";
|
|
113
79
|
import classNames from "classnames";
|
|
114
|
-
import React, { useContext,
|
|
80
|
+
import React, { useContext, useMemo, useRef } from "react";
|
|
115
81
|
import { Line } from "react-chartjs-2";
|
|
116
82
|
import { ChartContainer, ChartFilter, ChartStatistic, ChartToolBar, downloadChart } from "../components";
|
|
117
83
|
import { defaultColorList } from "../const";
|
|
118
|
-
import {
|
|
84
|
+
import { useChartDataFilter, useChartStatistics, useChartTheme, useResponsiveSize } from "../hooks";
|
|
85
|
+
import { extractAndSortXValues, findDataPointByXValue, hexToRgba, registerLineChartComponents } from "../utils";
|
|
119
86
|
import { useStyle } from "./style";
|
|
120
|
-
/**
|
|
121
|
-
* @fileoverview 面积图组件文件
|
|
122
|
-
*
|
|
123
|
-
* 该文件提供了面积图组件的实现,基于 Chart.js 和 react-chartjs-2。
|
|
124
|
-
* 支持数据可视化、交互、配置、统计等功能。
|
|
125
|
-
*
|
|
126
|
-
* @author md-editor
|
|
127
|
-
* @version 1.0.0
|
|
128
|
-
* @since 2024
|
|
129
|
-
*/ var areaChartComponentsRegistered = false;
|
|
130
|
-
/**
|
|
131
|
-
* 将十六进制颜色转换为带透明度的 RGBA 字符串
|
|
132
|
-
*
|
|
133
|
-
* 支持3位和6位十六进制颜色格式,并添加透明度。
|
|
134
|
-
*
|
|
135
|
-
* @param {string} hex - 十六进制颜色值(如 '#ff0000' 或 '#f00')
|
|
136
|
-
* @param {number} alpha - 透明度值(0-1之间)
|
|
137
|
-
* @returns {string} RGBA 颜色字符串
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```typescript
|
|
141
|
-
* hexToRgba('#ff0000', 0.5); // 'rgba(255, 0, 0, 0.5)'
|
|
142
|
-
* hexToRgba('#f00', 0.8); // 'rgba(255, 0, 0, 0.8)'
|
|
143
|
-
* ```
|
|
144
|
-
*
|
|
145
|
-
* @since 1.0.0
|
|
146
|
-
*/ var hexToRgba = function(hex, alpha) {
|
|
147
|
-
var sanitized = hex.replace('#', '');
|
|
148
|
-
var isShort = sanitized.length === 3;
|
|
149
|
-
var r = parseInt(isShort ? sanitized[0] + sanitized[0] : sanitized.slice(0, 2), 16);
|
|
150
|
-
var g = parseInt(isShort ? sanitized[1] + sanitized[1] : sanitized.slice(2, 4), 16);
|
|
151
|
-
var b = parseInt(isShort ? sanitized[2] + sanitized[2] : sanitized.slice(4, 6), 16);
|
|
152
|
-
var a = Math.max(0, Math.min(1, alpha));
|
|
153
|
-
return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(a, ")");
|
|
154
|
-
};
|
|
155
87
|
/**
|
|
156
88
|
* 面积图组件
|
|
157
89
|
*
|
|
@@ -179,104 +111,22 @@ import { useStyle } from "./style";
|
|
|
179
111
|
*
|
|
180
112
|
* @since 1.0.0
|
|
181
113
|
*/ var AreaChart = function(param) {
|
|
182
|
-
var title = param.title, data = param.data, _param_width = param.width, width = _param_width === void 0 ? 600 : _param_width, _param_height = param.height, height = _param_height === void 0 ? 400 : _param_height, className = param.className, dataTime = param.dataTime, _param_theme = param.theme, theme = _param_theme === void 0 ? 'light' : _param_theme, color = param.color, _param_showLegend = param.showLegend, showLegend = _param_showLegend === void 0 ? true : _param_showLegend, _param_legendPosition = param.legendPosition, legendPosition = _param_legendPosition === void 0 ? 'bottom' : _param_legendPosition, _param_legendAlign = param.legendAlign, legendAlign = _param_legendAlign === void 0 ? 'start' : _param_legendAlign, _param_showGrid = param.showGrid, showGrid = _param_showGrid === void 0 ? true : _param_showGrid, _param_xPosition = param.xPosition, xPosition = _param_xPosition === void 0 ? 'bottom' : _param_xPosition, _param_yPosition = param.yPosition, yPosition = _param_yPosition === void 0 ? 'left' : _param_yPosition, _param_hiddenX = param.hiddenX, hiddenX = _param_hiddenX === void 0 ? false : _param_hiddenX, _param_hiddenY = param.hiddenY, hiddenY = _param_hiddenY === void 0 ? false : _param_hiddenY, toolbarExtra = param.toolbarExtra, _param_renderFilterInToolbar = param.renderFilterInToolbar, renderFilterInToolbar = _param_renderFilterInToolbar === void 0 ? false : _param_renderFilterInToolbar, statisticConfig = param.statistic, variant = param.variant;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (typeof window === 'undefined') {
|
|
188
|
-
return undefined;
|
|
189
|
-
}
|
|
190
|
-
ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Filler, Tooltip, Legend);
|
|
191
|
-
areaChartComponentsRegistered = true;
|
|
192
|
-
return undefined;
|
|
193
|
-
}, []);
|
|
194
|
-
var safeData = Array.isArray(data) ? data : [];
|
|
195
|
-
// 响应式尺寸计算
|
|
196
|
-
var _useState = _sliced_to_array(useState(typeof window !== 'undefined' ? window.innerWidth : 768), 2), windowWidth = _useState[0], setWindowWidth = _useState[1];
|
|
197
|
-
var isMobile = windowWidth <= 768;
|
|
198
|
-
var responsiveWidth = isMobile ? '100%' : width;
|
|
199
|
-
var responsiveHeight = isMobile ? Math.min(windowWidth * 0.8, 400) : height;
|
|
200
|
-
// 监听窗口大小变化
|
|
201
|
-
useEffect(function() {
|
|
202
|
-
var handleResize = function() {
|
|
203
|
-
setWindowWidth(window.innerWidth);
|
|
204
|
-
};
|
|
205
|
-
if (typeof window !== 'undefined') {
|
|
206
|
-
window.addEventListener('resize', handleResize);
|
|
207
|
-
return function() {
|
|
208
|
-
return window.removeEventListener('resize', handleResize);
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
}, []);
|
|
114
|
+
var title = param.title, data = param.data, _param_width = param.width, width = _param_width === void 0 ? 600 : _param_width, _param_height = param.height, height = _param_height === void 0 ? 400 : _param_height, className = param.className, dataTime = param.dataTime, _param_theme = param.theme, theme = _param_theme === void 0 ? 'light' : _param_theme, color = param.color, _param_showLegend = param.showLegend, showLegend = _param_showLegend === void 0 ? true : _param_showLegend, _param_legendPosition = param.legendPosition, legendPosition = _param_legendPosition === void 0 ? 'bottom' : _param_legendPosition, _param_legendAlign = param.legendAlign, legendAlign = _param_legendAlign === void 0 ? 'start' : _param_legendAlign, _param_showGrid = param.showGrid, showGrid = _param_showGrid === void 0 ? true : _param_showGrid, _param_xPosition = param.xPosition, xPosition = _param_xPosition === void 0 ? 'bottom' : _param_xPosition, _param_yPosition = param.yPosition, yPosition = _param_yPosition === void 0 ? 'left' : _param_yPosition, _param_hiddenX = param.hiddenX, hiddenX = _param_hiddenX === void 0 ? false : _param_hiddenX, _param_hiddenY = param.hiddenY, hiddenY = _param_hiddenY === void 0 ? false : _param_hiddenY, toolbarExtra = param.toolbarExtra, _param_renderFilterInToolbar = param.renderFilterInToolbar, renderFilterInToolbar = _param_renderFilterInToolbar === void 0 ? false : _param_renderFilterInToolbar, statisticConfig = param.statistic, variant = param.variant, _param_loading = param.loading, loading = _param_loading === void 0 ? false : _param_loading;
|
|
115
|
+
// 注册 Chart.js 组件
|
|
116
|
+
registerLineChartComponents();
|
|
117
|
+
// 响应式尺寸
|
|
118
|
+
var _useResponsiveSize = useResponsiveSize(width, height), responsiveWidth = _useResponsiveSize.responsiveWidth, responsiveHeight = _useResponsiveSize.responsiveHeight, isMobile = _useResponsiveSize.isMobile;
|
|
212
119
|
// 样式注册
|
|
213
120
|
var context = useContext(ConfigProvider.ConfigContext);
|
|
214
121
|
var baseClassName = context === null || context === void 0 ? void 0 : context.getPrefixCls('area-chart-container');
|
|
215
122
|
var _useStyle = useStyle(baseClassName), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
|
|
216
123
|
var chartRef = useRef(null);
|
|
217
124
|
// 处理 ChartStatistic 组件配置
|
|
218
|
-
var statistics =
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}, [
|
|
224
|
-
statisticConfig
|
|
225
|
-
]);
|
|
226
|
-
// 从数据中提取唯一的类别作为筛选选项
|
|
227
|
-
var categories = useMemo(function() {
|
|
228
|
-
var uniqueCategories = _to_consumable_array(new Set(safeData.map(function(item) {
|
|
229
|
-
return item.category;
|
|
230
|
-
}))).filter(Boolean);
|
|
231
|
-
return uniqueCategories;
|
|
232
|
-
}, [
|
|
233
|
-
safeData
|
|
234
|
-
]);
|
|
235
|
-
// 从数据中提取 filterLabel,过滤掉 undefined 值
|
|
236
|
-
var validFilterLabels = useMemo(function() {
|
|
237
|
-
return safeData.map(function(item) {
|
|
238
|
-
return item.filterLabel;
|
|
239
|
-
}).filter(function(filterLabel) {
|
|
240
|
-
return filterLabel !== undefined;
|
|
241
|
-
});
|
|
242
|
-
}, [
|
|
243
|
-
safeData
|
|
244
|
-
]);
|
|
245
|
-
var filterLabels = useMemo(function() {
|
|
246
|
-
return validFilterLabels.length > 0 ? _to_consumable_array(new Set(validFilterLabels)) : undefined;
|
|
247
|
-
}, [
|
|
248
|
-
validFilterLabels
|
|
249
|
-
]);
|
|
250
|
-
// 状态管理
|
|
251
|
-
var _useState1 = _sliced_to_array(useState(categories.find(Boolean) || ''), 2), selectedFilter = _useState1[0], setSelectedFilter = _useState1[1];
|
|
252
|
-
var _useState2 = _sliced_to_array(useState(filterLabels && filterLabels.length > 0 ? filterLabels[0] : undefined), 2), selectedFilterLabel = _useState2[0], setSelectedFilterLabel = _useState2[1];
|
|
253
|
-
// 当数据变化导致当前选中分类失效时,自动回退到首个有效分类或空(显示全部)
|
|
254
|
-
useEffect(function() {
|
|
255
|
-
if (selectedFilter && !categories.includes(selectedFilter)) {
|
|
256
|
-
setSelectedFilter(categories.find(Boolean) || '');
|
|
257
|
-
}
|
|
258
|
-
}, [
|
|
259
|
-
categories,
|
|
260
|
-
selectedFilter
|
|
261
|
-
]);
|
|
262
|
-
// 筛选数据
|
|
263
|
-
var filteredData = useMemo(function() {
|
|
264
|
-
var base = selectedFilter ? safeData.filter(function(item) {
|
|
265
|
-
return item.category === selectedFilter;
|
|
266
|
-
}) : safeData;
|
|
267
|
-
var withFilterLabel = !filterLabels || !selectedFilterLabel ? base : base.filter(function(item) {
|
|
268
|
-
return item.filterLabel === selectedFilterLabel;
|
|
269
|
-
});
|
|
270
|
-
// 统一过滤掉 x 为空(null/undefined)的数据,避免后续 toString 报错
|
|
271
|
-
return withFilterLabel.filter(function(item) {
|
|
272
|
-
return item.x !== null && item.x !== undefined;
|
|
273
|
-
});
|
|
274
|
-
}, [
|
|
275
|
-
safeData,
|
|
276
|
-
selectedFilter,
|
|
277
|
-
filterLabels,
|
|
278
|
-
selectedFilterLabel
|
|
279
|
-
]);
|
|
125
|
+
var statistics = useChartStatistics(statisticConfig);
|
|
126
|
+
// 数据筛选
|
|
127
|
+
var _useChartDataFilter = useChartDataFilter(data), filteredData = _useChartDataFilter.filteredData, filterOptions = _useChartDataFilter.filterOptions, filterLabels = _useChartDataFilter.filterLabels, selectedFilter = _useChartDataFilter.selectedFilter, setSelectedFilter = _useChartDataFilter.setSelectedFilter, selectedFilterLabel = _useChartDataFilter.selectedFilterLabel, setSelectedFilterLabel = _useChartDataFilter.setSelectedFilterLabel, filteredDataByFilterLabel = _useChartDataFilter.filteredDataByFilterLabel;
|
|
128
|
+
// 主题颜色
|
|
129
|
+
var _useChartTheme = useChartTheme(theme), axisTextColor = _useChartTheme.axisTextColor, gridColor = _useChartTheme.gridColor, isLight = _useChartTheme.isLight;
|
|
280
130
|
// 从数据中提取唯一的类型
|
|
281
131
|
var types = useMemo(function() {
|
|
282
132
|
return _to_consumable_array(new Set(filteredData.map(function(item) {
|
|
@@ -355,31 +205,6 @@ import { useStyle } from "./style";
|
|
|
355
205
|
types,
|
|
356
206
|
xValues
|
|
357
207
|
]);
|
|
358
|
-
// 筛选器选项
|
|
359
|
-
var filterOptions = useMemo(function() {
|
|
360
|
-
return categories.map(function(category) {
|
|
361
|
-
return {
|
|
362
|
-
label: category || '默认',
|
|
363
|
-
value: category || '默认'
|
|
364
|
-
};
|
|
365
|
-
});
|
|
366
|
-
}, [
|
|
367
|
-
categories
|
|
368
|
-
]);
|
|
369
|
-
// 根据 filterLabel 筛选数据 - 只有当 filterLabels 存在时才生成
|
|
370
|
-
var filteredDataByFilterLabel = useMemo(function() {
|
|
371
|
-
return filterLabels === null || filterLabels === void 0 ? void 0 : filterLabels.map(function(item) {
|
|
372
|
-
return {
|
|
373
|
-
key: item,
|
|
374
|
-
label: item
|
|
375
|
-
};
|
|
376
|
-
});
|
|
377
|
-
}, [
|
|
378
|
-
filterLabels
|
|
379
|
-
]);
|
|
380
|
-
var isLight = theme === 'light';
|
|
381
|
-
var axisTextColor = isLight ? 'rgba(0, 25, 61, 0.3255)' : 'rgba(255, 255, 255, 0.8)';
|
|
382
|
-
var gridColor = isLight ? 'rgba(0,0,0,0.08)' : 'rgba(255,255,255,0.2)';
|
|
383
208
|
var options = {
|
|
384
209
|
responsive: true,
|
|
385
210
|
maintainAspectRatio: false,
|
|
@@ -515,6 +340,7 @@ import { useStyle } from "./style";
|
|
|
515
340
|
onDownload: handleDownload,
|
|
516
341
|
extra: toolbarExtra,
|
|
517
342
|
dataTime: dataTime,
|
|
343
|
+
loading: loading,
|
|
518
344
|
filter: renderFilterInToolbar && filterOptions && filterOptions.length > 1 ? /*#__PURE__*/ React.createElement(ChartFilter, _object_spread_props(_object_spread({
|
|
519
345
|
filterOptions: filterOptions,
|
|
520
346
|
selectedFilter: selectedFilter,
|
|
@@ -134,6 +134,8 @@ export interface BarChartProps extends ChartContainerProps {
|
|
|
134
134
|
renderFilterInToolbar?: boolean;
|
|
135
135
|
/** ChartStatistic组件配置:object表示单个配置,array表示多个配置 */
|
|
136
136
|
statistic?: StatisticConfigType;
|
|
137
|
+
/** 是否显示加载状态(当图表未闭合时显示) */
|
|
138
|
+
loading?: boolean;
|
|
137
139
|
}
|
|
138
140
|
declare const BarChart: React.FC<BarChartProps>;
|
|
139
141
|
export default BarChart;
|
|
@@ -120,7 +120,7 @@ import React, { useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
|
120
120
|
import { Bar } from "react-chartjs-2";
|
|
121
121
|
import { ChartContainer, ChartFilter, ChartStatistic, ChartToolBar, downloadChart } from "../components";
|
|
122
122
|
import { defaultColorList } from "../const";
|
|
123
|
-
import { extractAndSortXValues, findDataPointByXValue } from "../utils";
|
|
123
|
+
import { extractAndSortXValues, findDataPointByXValue, hexToRgba } from "../utils";
|
|
124
124
|
import { useStyle } from "./style";
|
|
125
125
|
/**
|
|
126
126
|
* @fileoverview 柱状图组件文件
|
|
@@ -132,21 +132,11 @@ import { useStyle } from "./style";
|
|
|
132
132
|
* @version 1.0.0
|
|
133
133
|
* @since 2024
|
|
134
134
|
*/ var barChartComponentsRegistered = false;
|
|
135
|
-
// 将十六进制颜色转换为带透明度的 rgba 字符串
|
|
136
|
-
var hexToRgba = function(hex, alpha) {
|
|
137
|
-
var sanitized = hex.replace('#', '');
|
|
138
|
-
var isShort = sanitized.length === 3;
|
|
139
|
-
var r = parseInt(isShort ? sanitized[0] + sanitized[0] : sanitized.slice(0, 2), 16);
|
|
140
|
-
var g = parseInt(isShort ? sanitized[1] + sanitized[1] : sanitized.slice(2, 4), 16);
|
|
141
|
-
var b = parseInt(isShort ? sanitized[2] + sanitized[2] : sanitized.slice(4, 6), 16);
|
|
142
|
-
var a = Math.max(0, Math.min(1, alpha));
|
|
143
|
-
return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(a, ")");
|
|
144
|
-
};
|
|
145
135
|
// 正负柱状图颜色(与需求给定的 rgba 保持一致)
|
|
146
136
|
var POSITIVE_COLOR_HEX = '#388BFF'; // rgba(56, 139, 255, 1)
|
|
147
137
|
var NEGATIVE_COLOR_HEX = '#F78826'; // rgba(247, 136, 38, 1)
|
|
148
138
|
var BarChart = function(param) {
|
|
149
|
-
var title = param.title, data = param.data, _param_width = param.width, width = _param_width === void 0 ? 600 : _param_width, _param_height = param.height, height = _param_height === void 0 ? 400 : _param_height, className = param.className, dataTime = param.dataTime, _param_theme = param.theme, theme = _param_theme === void 0 ? 'light' : _param_theme, color = param.color, _param_showLegend = param.showLegend, showLegend = _param_showLegend === void 0 ? true : _param_showLegend, _param_legendPosition = param.legendPosition, legendPosition = _param_legendPosition === void 0 ? 'bottom' : _param_legendPosition, _param_legendAlign = param.legendAlign, legendAlign = _param_legendAlign === void 0 ? 'start' : _param_legendAlign, _param_showGrid = param.showGrid, showGrid = _param_showGrid === void 0 ? true : _param_showGrid, _param_xPosition = param.xPosition, xPosition = _param_xPosition === void 0 ? 'bottom' : _param_xPosition, _param_yPosition = param.yPosition, yPosition = _param_yPosition === void 0 ? 'left' : _param_yPosition, _param_hiddenX = param.hiddenX, hiddenX = _param_hiddenX === void 0 ? false : _param_hiddenX, _param_hiddenY = param.hiddenY, hiddenY = _param_hiddenY === void 0 ? false : _param_hiddenY, _param_stacked = param.stacked, stacked = _param_stacked === void 0 ? false : _param_stacked, _param_indexAxis = param.indexAxis, indexAxis = _param_indexAxis === void 0 ? 'x' : _param_indexAxis, maxBarThickness = param.maxBarThickness, toolbarExtra = param.toolbarExtra, _param_renderFilterInToolbar = param.renderFilterInToolbar, renderFilterInToolbar = _param_renderFilterInToolbar === void 0 ? false : _param_renderFilterInToolbar, statisticConfig = param.statistic, variant = param.variant, _param_showDataLabels = param.showDataLabels, showDataLabels = _param_showDataLabels === void 0 ? false : _param_showDataLabels, dataLabelFormatter = param.dataLabelFormatter, chartOptions = param.chartOptions;
|
|
139
|
+
var title = param.title, data = param.data, _param_width = param.width, width = _param_width === void 0 ? 600 : _param_width, _param_height = param.height, height = _param_height === void 0 ? 400 : _param_height, className = param.className, dataTime = param.dataTime, _param_theme = param.theme, theme = _param_theme === void 0 ? 'light' : _param_theme, color = param.color, _param_showLegend = param.showLegend, showLegend = _param_showLegend === void 0 ? true : _param_showLegend, _param_legendPosition = param.legendPosition, legendPosition = _param_legendPosition === void 0 ? 'bottom' : _param_legendPosition, _param_legendAlign = param.legendAlign, legendAlign = _param_legendAlign === void 0 ? 'start' : _param_legendAlign, _param_showGrid = param.showGrid, showGrid = _param_showGrid === void 0 ? true : _param_showGrid, _param_xPosition = param.xPosition, xPosition = _param_xPosition === void 0 ? 'bottom' : _param_xPosition, _param_yPosition = param.yPosition, yPosition = _param_yPosition === void 0 ? 'left' : _param_yPosition, _param_hiddenX = param.hiddenX, hiddenX = _param_hiddenX === void 0 ? false : _param_hiddenX, _param_hiddenY = param.hiddenY, hiddenY = _param_hiddenY === void 0 ? false : _param_hiddenY, _param_stacked = param.stacked, stacked = _param_stacked === void 0 ? false : _param_stacked, _param_indexAxis = param.indexAxis, indexAxis = _param_indexAxis === void 0 ? 'x' : _param_indexAxis, maxBarThickness = param.maxBarThickness, toolbarExtra = param.toolbarExtra, _param_renderFilterInToolbar = param.renderFilterInToolbar, renderFilterInToolbar = _param_renderFilterInToolbar === void 0 ? false : _param_renderFilterInToolbar, statisticConfig = param.statistic, variant = param.variant, _param_showDataLabels = param.showDataLabels, showDataLabels = _param_showDataLabels === void 0 ? false : _param_showDataLabels, dataLabelFormatter = param.dataLabelFormatter, chartOptions = param.chartOptions, _param_loading = param.loading, loading = _param_loading === void 0 ? false : _param_loading;
|
|
150
140
|
useMemo(function() {
|
|
151
141
|
if (barChartComponentsRegistered) {
|
|
152
142
|
return undefined;
|
|
@@ -840,6 +830,7 @@ var BarChart = function(param) {
|
|
|
840
830
|
onDownload: handleDownload,
|
|
841
831
|
extra: toolbarExtra,
|
|
842
832
|
dataTime: dataTime,
|
|
833
|
+
loading: loading,
|
|
843
834
|
filter: renderFilterInToolbar && filterOptions && filterOptions.length > 1 ? /*#__PURE__*/ React.createElement(ChartFilter, _object_spread_props(_object_spread({
|
|
844
835
|
filterOptions: filterOptions,
|
|
845
836
|
selectedFilter: selectedFilter,
|
|
@@ -69,12 +69,15 @@ export var Container = function(props) {
|
|
|
69
69
|
width: containerWidth,
|
|
70
70
|
height: naturalHeight
|
|
71
71
|
};
|
|
72
|
-
|
|
72
|
+
// 增加阈值,减少频繁调整导致的抖动
|
|
73
|
+
if (Math.abs(preSize.width - newSize.width) > 30 || // 从 20 增加到 30
|
|
74
|
+
Math.abs(preSize.height - newSize.height) > 30 // 从 20 增加到 30
|
|
75
|
+
) {
|
|
73
76
|
chart.resize(newSize.width, newSize.height);
|
|
74
77
|
sizeRef.current = newSize;
|
|
75
78
|
return;
|
|
76
79
|
}
|
|
77
|
-
},
|
|
80
|
+
}, 300 + props.index * 20);
|
|
78
81
|
useEffect(function() {
|
|
79
82
|
if (inView) {
|
|
80
83
|
onSize();
|