@antv/gpt-vis 0.5.9 → 0.5.11
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/cjs/Area/index.d.ts +2 -1
- package/dist/cjs/Boxplot/index.d.ts +2 -4
- package/dist/cjs/Boxplot/index.js +2 -2
- package/dist/cjs/Column/index.d.ts +2 -1
- package/dist/cjs/DualAxes/index.d.ts +5 -0
- package/dist/cjs/DualAxes/index.js +3 -2
- package/dist/cjs/DualAxes/util.d.ts +1 -1
- package/dist/cjs/DualAxes/util.js +2 -1
- package/dist/cjs/Funnel/index.js +2 -2
- package/dist/cjs/Histogram/index.d.ts +1 -0
- package/dist/cjs/Line/index.d.ts +2 -1
- package/dist/cjs/Line/index.js +3 -2
- package/dist/cjs/Scatter/index.d.ts +4 -1
- package/dist/cjs/Violin/index.js +11 -6
- package/dist/cjs/Waterfall/index.d.ts +22 -0
- package/dist/cjs/Waterfall/index.js +194 -0
- package/dist/cjs/export.d.ts +41 -1
- package/dist/cjs/export.js +4 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/render.d.ts +2 -0
- package/dist/cjs/render.js +67 -0
- package/dist/cjs/types/chart.d.ts +2 -0
- package/dist/cjs/types/chart.js +1 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Area/index.d.ts +2 -1
- package/dist/esm/Boxplot/index.d.ts +2 -4
- package/dist/esm/Boxplot/index.js +5 -2
- package/dist/esm/Column/index.d.ts +2 -1
- package/dist/esm/DualAxes/index.d.ts +5 -0
- package/dist/esm/DualAxes/index.js +6 -2
- package/dist/esm/DualAxes/util.d.ts +1 -1
- package/dist/esm/DualAxes/util.js +7 -0
- package/dist/esm/Funnel/index.js +2 -2
- package/dist/esm/Histogram/index.d.ts +1 -0
- package/dist/esm/Line/index.d.ts +2 -1
- package/dist/esm/Line/index.js +5 -2
- package/dist/esm/Scatter/index.d.ts +4 -1
- package/dist/esm/Violin/index.js +13 -6
- package/dist/esm/Waterfall/index.d.ts +22 -0
- package/dist/esm/Waterfall/index.js +186 -0
- package/dist/esm/export.d.ts +41 -1
- package/dist/esm/export.js +8 -2
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/render.d.ts +2 -0
- package/dist/esm/render.js +32 -0
- package/dist/esm/types/chart.d.ts +2 -0
- package/dist/esm/types/chart.js +1 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/134.async.js +1 -0
- package/dist/umd/index.min.js +1 -1
- package/package.json +5 -2
- package/dist/cjs/Pie/index.text.d.ts +0 -0
- package/dist/cjs/Pie/index.text.js +0 -0
- package/dist/esm/Pie/index.text.d.ts +0 -0
- package/dist/esm/Pie/index.text.js +0 -0
- package/dist/umd/330.async.js +0 -1
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "0.5.
|
|
1
|
+
declare const _default: "0.5.11";
|
|
2
2
|
export default _default;
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/Area/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AreaConfig } from '@ant-design/plots';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import type { BasePlotProps, Style, Theme } from '../types';
|
|
3
4
|
type AreaDataItem = {
|
|
@@ -5,6 +6,6 @@ type AreaDataItem = {
|
|
|
5
6
|
value: number;
|
|
6
7
|
[key: string]: string | number;
|
|
7
8
|
};
|
|
8
|
-
export type AreaProps = BasePlotProps<AreaDataItem> & Theme & Style;
|
|
9
|
+
export type AreaProps = BasePlotProps<AreaDataItem> & Partial<AreaConfig> & Theme & Style;
|
|
9
10
|
declare const Area: (props: AreaProps) => React.JSX.Element;
|
|
10
11
|
export default Area;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BoxConfig } from '@ant-design/plots';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import type { BasePlotProps, Style, Theme } from '../types';
|
|
3
4
|
type BoxplotDatum = {
|
|
@@ -5,9 +6,6 @@ type BoxplotDatum = {
|
|
|
5
6
|
value: number;
|
|
6
7
|
group?: string;
|
|
7
8
|
};
|
|
8
|
-
export type BoxplotProps = BasePlotProps<BoxplotDatum> &
|
|
9
|
-
xField?: string;
|
|
10
|
-
yField?: string;
|
|
11
|
-
};
|
|
9
|
+
export type BoxplotProps = BasePlotProps<BoxplotDatum> & Partial<BoxConfig> & Theme & Style;
|
|
12
10
|
declare const Boxplot: (props: BoxplotProps) => React.JSX.Element;
|
|
13
11
|
export default Boxplot;
|
|
@@ -20,7 +20,9 @@ var defaultConfig = function defaultConfig(props) {
|
|
|
20
20
|
_props$yField = props.yField,
|
|
21
21
|
yField = _props$yField === void 0 ? 'value' : _props$yField;
|
|
22
22
|
var backgroundColor = style.backgroundColor,
|
|
23
|
-
palette = style.palette
|
|
23
|
+
palette = style.palette,
|
|
24
|
+
_style$startAtZero = style.startAtZero,
|
|
25
|
+
startAtZero = _style$startAtZero === void 0 ? false : _style$startAtZero;
|
|
24
26
|
var hasGroupField = ((_ = (data || [])[0]) === null || _ === void 0 ? void 0 : _.group) !== undefined;
|
|
25
27
|
var paletteConfig = {
|
|
26
28
|
color: undefined
|
|
@@ -60,7 +62,8 @@ var defaultConfig = function defaultConfig(props) {
|
|
|
60
62
|
paddingOuter: 0.1
|
|
61
63
|
},
|
|
62
64
|
y: {
|
|
63
|
-
nice: true
|
|
65
|
+
nice: true,
|
|
66
|
+
zero: startAtZero
|
|
64
67
|
}
|
|
65
68
|
}, paletteConfig),
|
|
66
69
|
style: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ColumnConfig } from '@ant-design/plots';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import type { BasePlotProps, Style, Theme } from '../types';
|
|
3
4
|
export type ColumnDataItem = {
|
|
@@ -5,7 +6,7 @@ export type ColumnDataItem = {
|
|
|
5
6
|
value: number;
|
|
6
7
|
[key: string]: string | number;
|
|
7
8
|
};
|
|
8
|
-
export type ColumnProps = BasePlotProps<ColumnDataItem> & Theme & Style & {
|
|
9
|
+
export type ColumnProps = BasePlotProps<ColumnDataItem> & Partial<ColumnConfig> & Theme & Style & {
|
|
9
10
|
group?: boolean;
|
|
10
11
|
stack?: boolean;
|
|
11
12
|
};
|
|
@@ -5,6 +5,11 @@ export type DualAxesProps = Partial<DualAxesConfig> & {
|
|
|
5
5
|
axisXTitle?: string;
|
|
6
6
|
series: DualAxesSeriesItem[];
|
|
7
7
|
legendTypeList?: string[];
|
|
8
|
+
style?: {
|
|
9
|
+
palette?: string[];
|
|
10
|
+
backgroundColor?: string;
|
|
11
|
+
startAtZero?: boolean;
|
|
12
|
+
};
|
|
8
13
|
};
|
|
9
14
|
export type DualAxesSeriesItem = {
|
|
10
15
|
type: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["categories", "series", "theme"];
|
|
1
|
+
var _excluded = ["categories", "series", "theme", "style"];
|
|
2
2
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
3
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
4
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
@@ -60,10 +60,14 @@ var DualAxes = function DualAxes(props) {
|
|
|
60
60
|
series = props.series,
|
|
61
61
|
_props$theme = props.theme,
|
|
62
62
|
theme = _props$theme === void 0 ? 'default' : _props$theme,
|
|
63
|
+
_props$style2 = props.style,
|
|
64
|
+
style = _props$style2 === void 0 ? {} : _props$style2,
|
|
63
65
|
others = _objectWithoutProperties(props, _excluded);
|
|
66
|
+
var _style$startAtZero = style.startAtZero,
|
|
67
|
+
startAtZero = _style$startAtZero === void 0 ? false : _style$startAtZero;
|
|
64
68
|
var themeConfig = THEME_MAP[theme];
|
|
65
69
|
var transformData = useMemo(function () {
|
|
66
|
-
return transform(series, categories);
|
|
70
|
+
return transform(series, categories, startAtZero);
|
|
67
71
|
}, [props]);
|
|
68
72
|
var config = usePlotConfig('DualAxes', defaultConfig, _objectSpread(_objectSpread(_objectSpread({}, others), transformData), {}, {
|
|
69
73
|
theme: themeConfig
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DualAxesSeriesItem } from '.';
|
|
2
|
-
export declare function transform(series: DualAxesSeriesItem[], categories: string[]): {
|
|
2
|
+
export declare function transform(series: DualAxesSeriesItem[], categories: string[], startAtZero?: boolean): {
|
|
3
3
|
children: any[];
|
|
4
4
|
data: {
|
|
5
5
|
[key: string]: any;
|
|
@@ -9,6 +9,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
9
9
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
10
|
import { ChartType } from "../types";
|
|
11
11
|
export function transform(series, categories) {
|
|
12
|
+
var startAtZero = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
12
13
|
var newChildren = series.sort(function (a, b) {
|
|
13
14
|
var ORDER = ['column', 'line'];
|
|
14
15
|
return ORDER.indexOf(a.type) - ORDER.indexOf(b.type);
|
|
@@ -24,6 +25,12 @@ export function transform(series, categories) {
|
|
|
24
25
|
title: axisYTitle
|
|
25
26
|
}
|
|
26
27
|
},
|
|
28
|
+
scale: {
|
|
29
|
+
y: {
|
|
30
|
+
nice: true,
|
|
31
|
+
zero: startAtZero
|
|
32
|
+
}
|
|
33
|
+
},
|
|
27
34
|
// data放在最外层
|
|
28
35
|
data: undefined
|
|
29
36
|
});
|
package/dist/esm/Funnel/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import type { BasePlotProps, Style, Theme } from '../types';
|
|
3
3
|
export type HistogramProps = BasePlotProps<number> & Theme & Style & {
|
|
4
4
|
binNumber: number;
|
|
5
|
+
binField?: (d: number) => number;
|
|
5
6
|
};
|
|
6
7
|
declare const Histogram: (props: HistogramProps) => React.JSX.Element;
|
|
7
8
|
export default Histogram;
|
package/dist/esm/Line/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LineConfig } from '@ant-design/plots';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import type { BasePlotProps, Style, Theme } from '../types';
|
|
3
4
|
export type LineDataItem = {
|
|
@@ -5,6 +6,6 @@ export type LineDataItem = {
|
|
|
5
6
|
value: number;
|
|
6
7
|
[key: string]: string | number;
|
|
7
8
|
};
|
|
8
|
-
export type LineProps = BasePlotProps<LineDataItem> & Theme & Style;
|
|
9
|
+
export type LineProps = BasePlotProps<LineDataItem> & Partial<LineConfig> & Theme & Style;
|
|
9
10
|
declare const Line: (props: LineProps) => React.JSX.Element;
|
|
10
11
|
export default Line;
|
package/dist/esm/Line/index.js
CHANGED
|
@@ -19,7 +19,9 @@ var defaultConfig = function defaultConfig(props) {
|
|
|
19
19
|
style = _props$style === void 0 ? {} : _props$style;
|
|
20
20
|
var palette = style.palette,
|
|
21
21
|
lineWidth = style.lineWidth,
|
|
22
|
-
backgroundColor = style.backgroundColor
|
|
22
|
+
backgroundColor = style.backgroundColor,
|
|
23
|
+
_style$startAtZero = style.startAtZero,
|
|
24
|
+
startAtZero = _style$startAtZero === void 0 ? false : _style$startAtZero;
|
|
23
25
|
var hasGroupField = get(data, '[0].group') !== undefined;
|
|
24
26
|
var axisYTitle = get(props, 'axis.y.title');
|
|
25
27
|
var hasPalette = !!(palette !== null && palette !== void 0 && palette[0]);
|
|
@@ -64,7 +66,8 @@ var defaultConfig = function defaultConfig(props) {
|
|
|
64
66
|
},
|
|
65
67
|
scale: _objectSpread({
|
|
66
68
|
y: {
|
|
67
|
-
nice: true
|
|
69
|
+
nice: true,
|
|
70
|
+
zero: startAtZero
|
|
68
71
|
}
|
|
69
72
|
}, paletteConfig),
|
|
70
73
|
style: {
|
|
@@ -5,6 +5,9 @@ type ScatterDataItem = {
|
|
|
5
5
|
y: number;
|
|
6
6
|
[key: string]: string | number;
|
|
7
7
|
};
|
|
8
|
-
export type ScatterProps = BasePlotProps<ScatterDataItem> & Theme & Style
|
|
8
|
+
export type ScatterProps = BasePlotProps<ScatterDataItem> & Theme & Style & {
|
|
9
|
+
xField?: string;
|
|
10
|
+
yField?: string;
|
|
11
|
+
};
|
|
9
12
|
declare const Scatter: (props: ScatterProps) => React.JSX.Element;
|
|
10
13
|
export default Scatter;
|
package/dist/esm/Violin/index.js
CHANGED
|
@@ -18,7 +18,9 @@ var defaultConfig = function defaultConfig(props) {
|
|
|
18
18
|
_props$style = props.style,
|
|
19
19
|
style = _props$style === void 0 ? {} : _props$style;
|
|
20
20
|
var backgroundColor = style.backgroundColor,
|
|
21
|
-
palette = style.palette
|
|
21
|
+
palette = style.palette,
|
|
22
|
+
_style$startAtZero = style.startAtZero,
|
|
23
|
+
startAtZero = _style$startAtZero === void 0 ? false : _style$startAtZero;
|
|
22
24
|
var hasGroupField = ((_ = (data || [])[0]) === null || _ === void 0 ? void 0 : _.group) !== undefined;
|
|
23
25
|
var encode = {};
|
|
24
26
|
var children = [];
|
|
@@ -42,7 +44,8 @@ var defaultConfig = function defaultConfig(props) {
|
|
|
42
44
|
encode: encode,
|
|
43
45
|
scale: _objectSpread({
|
|
44
46
|
y: {
|
|
45
|
-
nice: true
|
|
47
|
+
nice: true,
|
|
48
|
+
zero: startAtZero
|
|
46
49
|
}
|
|
47
50
|
}, palette !== null && palette !== void 0 && palette[0] ? {
|
|
48
51
|
color: {
|
|
@@ -74,7 +77,8 @@ var defaultConfig = function defaultConfig(props) {
|
|
|
74
77
|
} : {}), {}, {
|
|
75
78
|
scale: _objectSpread({
|
|
76
79
|
y: {
|
|
77
|
-
nice: true
|
|
80
|
+
nice: true,
|
|
81
|
+
zero: startAtZero
|
|
78
82
|
}
|
|
79
83
|
}, palette !== null && palette !== void 0 && palette[0] ? {
|
|
80
84
|
color: {
|
|
@@ -102,7 +106,8 @@ var defaultConfig = function defaultConfig(props) {
|
|
|
102
106
|
encode: encode,
|
|
103
107
|
scale: {
|
|
104
108
|
y: {
|
|
105
|
-
nice: true
|
|
109
|
+
nice: true,
|
|
110
|
+
zero: startAtZero
|
|
106
111
|
}
|
|
107
112
|
}
|
|
108
113
|
}, backgroundColor ? {
|
|
@@ -131,7 +136,8 @@ var defaultConfig = function defaultConfig(props) {
|
|
|
131
136
|
} : {}), {}, {
|
|
132
137
|
scale: _objectSpread({
|
|
133
138
|
y: {
|
|
134
|
-
nice: true
|
|
139
|
+
nice: true,
|
|
140
|
+
zero: startAtZero
|
|
135
141
|
}
|
|
136
142
|
}, palette !== null && palette !== void 0 && palette[0] ? {
|
|
137
143
|
color: {
|
|
@@ -157,7 +163,8 @@ var defaultConfig = function defaultConfig(props) {
|
|
|
157
163
|
children: children,
|
|
158
164
|
scale: {
|
|
159
165
|
y: {
|
|
160
|
-
nice: true
|
|
166
|
+
nice: true,
|
|
167
|
+
zero: startAtZero
|
|
161
168
|
}
|
|
162
169
|
}
|
|
163
170
|
}, backgroundColor ? {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { BasePlotProps, Style, Theme } from '../types';
|
|
3
|
+
type WaterfallDataItem = {
|
|
4
|
+
category: string;
|
|
5
|
+
value?: number;
|
|
6
|
+
isTotal?: boolean;
|
|
7
|
+
isIntermediateTotal?: boolean;
|
|
8
|
+
[key: string]: string | number | boolean | undefined;
|
|
9
|
+
};
|
|
10
|
+
type WaterfallStyle = {
|
|
11
|
+
backgroundColor?: string;
|
|
12
|
+
} & Style;
|
|
13
|
+
export type WaterfallProps = BasePlotProps<WaterfallDataItem> & Theme & {
|
|
14
|
+
style?: WaterfallStyle;
|
|
15
|
+
positiveColor?: string;
|
|
16
|
+
negativeColor?: string;
|
|
17
|
+
totalColor?: string;
|
|
18
|
+
axisXTitle?: string;
|
|
19
|
+
axisYTitle?: string;
|
|
20
|
+
};
|
|
21
|
+
declare const Waterfall: (props: WaterfallProps) => React.JSX.Element;
|
|
22
|
+
export default Waterfall;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { Chart } from '@antv/g2';
|
|
8
|
+
import React, { useEffect, useRef } from 'react';
|
|
9
|
+
import { THEME_MAP } from "../theme";
|
|
10
|
+
var DEFAULT_POSITIVE_COLOR = '#FF4D4F';
|
|
11
|
+
var DEFAULT_NEGATIVE_COLOR = '#2EBB59';
|
|
12
|
+
var DEFAULT_TOTAL_COLOR = '#1783FF';
|
|
13
|
+
/**
|
|
14
|
+
* Transform waterfall data to add __start__ and __end__ fields
|
|
15
|
+
* for proper rendering of stacked intervals
|
|
16
|
+
*/
|
|
17
|
+
function transformWaterfallData(data) {
|
|
18
|
+
var cumulative = 0; // 累计值(包含普通值)
|
|
19
|
+
var lastIntermediateTotalEnd = 0; // 上一个中间小计的 end 值
|
|
20
|
+
var totalSum = 0; // 总计值(不包含 isIntermediateTotal 的项)
|
|
21
|
+
|
|
22
|
+
return data.map(function (item) {
|
|
23
|
+
var value = item.value || 0;
|
|
24
|
+
var start;
|
|
25
|
+
var end;
|
|
26
|
+
if (item.isTotal) {
|
|
27
|
+
// 总计:
|
|
28
|
+
// start 为 0,end 为所有非 isIntermediateTotal 项的累计值
|
|
29
|
+
start = 0;
|
|
30
|
+
end = totalSum;
|
|
31
|
+
} else if (item.isIntermediateTotal) {
|
|
32
|
+
// 中间小计:
|
|
33
|
+
// start 为上一个 isIntermediateTotal 的 end(若不存在则为 0)
|
|
34
|
+
// end 为从上一个 isIntermediateTotal 后到当前位置的累计值
|
|
35
|
+
start = lastIntermediateTotalEnd;
|
|
36
|
+
end = cumulative;
|
|
37
|
+
// 更新上一个中间小计的 end 值
|
|
38
|
+
lastIntermediateTotalEnd = end;
|
|
39
|
+
} else {
|
|
40
|
+
start = cumulative;
|
|
41
|
+
end = cumulative + value;
|
|
42
|
+
cumulative = end;
|
|
43
|
+
totalSum += value;
|
|
44
|
+
}
|
|
45
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
46
|
+
__start__: start,
|
|
47
|
+
__end__: end,
|
|
48
|
+
__value__: item.isTotal ? totalSum : item.isIntermediateTotal ? end - start : value
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Generate link data for connecting waterfall bars
|
|
55
|
+
*/
|
|
56
|
+
function generateLinkData(data) {
|
|
57
|
+
return data.reduce(function (result, current, index) {
|
|
58
|
+
if (index > 0) {
|
|
59
|
+
var previous = data[index - 1];
|
|
60
|
+
result.push({
|
|
61
|
+
x: [previous.category, current.category],
|
|
62
|
+
y: current.isTotal || current.isIntermediateTotal ? current.__end__ : current.__start__
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}, []);
|
|
67
|
+
}
|
|
68
|
+
var defaultConfig = function defaultConfig(props) {
|
|
69
|
+
var _props$data = props.data,
|
|
70
|
+
data = _props$data === void 0 ? [] : _props$data,
|
|
71
|
+
title = props.title,
|
|
72
|
+
_props$style = props.style,
|
|
73
|
+
style = _props$style === void 0 ? {} : _props$style,
|
|
74
|
+
customPositiveColor = props.positiveColor,
|
|
75
|
+
customNegativeColor = props.negativeColor,
|
|
76
|
+
customTotalColor = props.totalColor,
|
|
77
|
+
axisXTitle = props.axisXTitle,
|
|
78
|
+
axisYTitle = props.axisYTitle,
|
|
79
|
+
_props$theme = props.theme,
|
|
80
|
+
theme = _props$theme === void 0 ? 'default' : _props$theme;
|
|
81
|
+
var backgroundColor = style.backgroundColor;
|
|
82
|
+
var positiveColor = customPositiveColor || DEFAULT_POSITIVE_COLOR;
|
|
83
|
+
var negativeColor = customNegativeColor || DEFAULT_NEGATIVE_COLOR;
|
|
84
|
+
var totalColor = customTotalColor || DEFAULT_TOTAL_COLOR;
|
|
85
|
+
var transformedData = transformWaterfallData(data);
|
|
86
|
+
var linkData = generateLinkData(transformedData);
|
|
87
|
+
return _objectSpread({
|
|
88
|
+
type: 'view',
|
|
89
|
+
theme: THEME_MAP[theme],
|
|
90
|
+
title: title,
|
|
91
|
+
data: transformedData,
|
|
92
|
+
axis: {
|
|
93
|
+
y: {
|
|
94
|
+
labelFormatter: '~s',
|
|
95
|
+
title: axisYTitle || false
|
|
96
|
+
},
|
|
97
|
+
x: {
|
|
98
|
+
title: axisXTitle || false
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
children: [{
|
|
102
|
+
type: 'interval',
|
|
103
|
+
data: transformedData,
|
|
104
|
+
encode: {
|
|
105
|
+
x: 'category',
|
|
106
|
+
y: ['__start__', '__end__'],
|
|
107
|
+
color: 'category'
|
|
108
|
+
},
|
|
109
|
+
style: {
|
|
110
|
+
maxWidth: 60,
|
|
111
|
+
stroke: '#666',
|
|
112
|
+
radius: 4,
|
|
113
|
+
fill: function fill(d) {
|
|
114
|
+
return d.isTotal || d.isIntermediateTotal ? totalColor : d.__value__ > 0 ? positiveColor : negativeColor;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
labels: [{
|
|
118
|
+
text: '__value__',
|
|
119
|
+
position: 'inside',
|
|
120
|
+
fontSize: 10,
|
|
121
|
+
transform: [{
|
|
122
|
+
type: 'overflowHide'
|
|
123
|
+
}],
|
|
124
|
+
formatter: '~s',
|
|
125
|
+
fill: '#000',
|
|
126
|
+
fontWeight: 600,
|
|
127
|
+
stroke: '#fff'
|
|
128
|
+
}],
|
|
129
|
+
tooltip: function tooltip(d) {
|
|
130
|
+
var tooltipName = axisYTitle || d['category'];
|
|
131
|
+
return {
|
|
132
|
+
name: tooltipName,
|
|
133
|
+
value: d['__value__']
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}, {
|
|
137
|
+
type: 'link',
|
|
138
|
+
data: linkData,
|
|
139
|
+
encode: {
|
|
140
|
+
x: 'x',
|
|
141
|
+
y: 'y'
|
|
142
|
+
},
|
|
143
|
+
zIndex: -1,
|
|
144
|
+
style: {
|
|
145
|
+
stroke: '#ccc',
|
|
146
|
+
lineDash: [4, 2],
|
|
147
|
+
lineWidth: 1
|
|
148
|
+
},
|
|
149
|
+
tooltip: false
|
|
150
|
+
}],
|
|
151
|
+
scale: {
|
|
152
|
+
y: {
|
|
153
|
+
nice: true
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
legend: false
|
|
157
|
+
}, backgroundColor ? {
|
|
158
|
+
viewStyle: {
|
|
159
|
+
viewFill: backgroundColor
|
|
160
|
+
}
|
|
161
|
+
} : {});
|
|
162
|
+
};
|
|
163
|
+
var Waterfall = function Waterfall(props) {
|
|
164
|
+
var containerRef = useRef(null);
|
|
165
|
+
var chartRef = useRef(null);
|
|
166
|
+
useEffect(function () {
|
|
167
|
+
if (!containerRef.current) return;
|
|
168
|
+
var chart = new Chart({
|
|
169
|
+
container: containerRef.current,
|
|
170
|
+
autoFit: true,
|
|
171
|
+
padding: 'auto'
|
|
172
|
+
});
|
|
173
|
+
var config = defaultConfig(props);
|
|
174
|
+
chart.options(config);
|
|
175
|
+
chart.render();
|
|
176
|
+
chartRef.current = chart;
|
|
177
|
+
return function () {
|
|
178
|
+
chart.destroy();
|
|
179
|
+
chartRef.current = null;
|
|
180
|
+
};
|
|
181
|
+
}, [props]);
|
|
182
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
183
|
+
ref: containerRef
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
export default Waterfall;
|
package/dist/esm/export.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { ChartType } from './types';
|
|
2
3
|
/********** plot chart **********/
|
|
3
4
|
import { default as Area, type AreaProps } from './Area';
|
|
4
5
|
import { default as Bar, type BarProps } from './Bar';
|
|
@@ -16,6 +17,7 @@ import { default as Scatter, type ScatterProps } from './Scatter';
|
|
|
16
17
|
import { default as Treemap, type TreemapProps } from './Treemap';
|
|
17
18
|
import { default as Venn, type VennProps } from './Venn';
|
|
18
19
|
import { default as Violin, type ViolinProps } from './Violin';
|
|
20
|
+
import { default as Waterfall, type WaterfallProps } from './Waterfall';
|
|
19
21
|
import { default as WordCloud, type WordCloudProps } from './WordCloud';
|
|
20
22
|
/********** graph chart **********/
|
|
21
23
|
import { default as FishboneDiagram, type FishboneDiagramProps } from './FishboneDiagram';
|
|
@@ -30,5 +32,43 @@ import { PinMap, type PinMapProps, HeatMap, type HeatMapProps, PathMap, type Pat
|
|
|
30
32
|
/********** NTV **********/
|
|
31
33
|
import { default as Table, type TableProps } from './Table';
|
|
32
34
|
export { VisText, type VisTextProps } from './Text';
|
|
33
|
-
export { Area, Bar, Boxplot, Column, DualAxes, FishboneDiagram, FlowDiagram, Funnel, HeatMap, Histogram, IndentedTree, Line, Liquid, MindMap, NetworkGraph, OrganizationChart, PathMap, Pie, PinMap, Radar, Sankey, Scatter, Treemap, Venn, Violin, Table, WordCloud, type AreaProps, type BarProps, type BoxplotProps, type ColumnProps, type DualAxesProps, type FishboneDiagramProps, type FlowDiagramProps, type FunnelProps, type HeatMapProps, type HistogramProps, type IndentedTreeProps, type LineProps, type LiquidProps, type MindMapProps, type NetworkGraphProps, type OrganizationChartProps, type PathMapProps, type PieProps, type PinMapProps, type RadarProps, type SankeyProps, type ScatterProps, type TreemapProps, type VennProps, type ViolinProps, type TableProps, type WordCloudProps, };
|
|
35
|
+
export { Area, Bar, Boxplot, Column, DualAxes, FishboneDiagram, FlowDiagram, Funnel, HeatMap, Histogram, IndentedTree, Line, Liquid, MindMap, NetworkGraph, OrganizationChart, PathMap, Pie, PinMap, Radar, Sankey, Scatter, Treemap, Venn, Violin, Waterfall, Table, WordCloud, type AreaProps, type BarProps, type BoxplotProps, type ColumnProps, type DualAxesProps, type FishboneDiagramProps, type FlowDiagramProps, type FunnelProps, type HeatMapProps, type HistogramProps, type IndentedTreeProps, type LineProps, type LiquidProps, type MindMapProps, type NetworkGraphProps, type OrganizationChartProps, type PathMapProps, type PieProps, type PinMapProps, type RadarProps, type SankeyProps, type ScatterProps, type TreemapProps, type VennProps, type ViolinProps, type WaterfallProps, type TableProps, type WordCloudProps, };
|
|
36
|
+
export type VisOptionMap = {
|
|
37
|
+
[ChartType.Area]: AreaProps;
|
|
38
|
+
[ChartType.Bar]: BarProps;
|
|
39
|
+
[ChartType.Boxplot]: BoxplotProps;
|
|
40
|
+
[ChartType.Column]: ColumnProps;
|
|
41
|
+
[ChartType.DualAxes]: DualAxesProps;
|
|
42
|
+
[ChartType.FishboneDiagram]: FishboneDiagramProps;
|
|
43
|
+
[ChartType.FlowDiagram]: FlowDiagramProps;
|
|
44
|
+
[ChartType.Funnel]: FunnelProps;
|
|
45
|
+
[ChartType.HeatMap]: HeatMapProps;
|
|
46
|
+
[ChartType.Histogram]: HistogramProps;
|
|
47
|
+
[ChartType.IndentedTree]: IndentedTreeProps;
|
|
48
|
+
[ChartType.Line]: LineProps;
|
|
49
|
+
[ChartType.Liquid]: LiquidProps;
|
|
50
|
+
[ChartType.MindMap]: MindMapProps;
|
|
51
|
+
[ChartType.NetworkGraph]: NetworkGraphProps;
|
|
52
|
+
[ChartType.OrganizationChart]: OrganizationChartProps;
|
|
53
|
+
[ChartType.PathMap]: PathMapProps;
|
|
54
|
+
[ChartType.Pie]: PieProps;
|
|
55
|
+
[ChartType.PinMap]: PinMapProps;
|
|
56
|
+
[ChartType.Radar]: RadarProps;
|
|
57
|
+
[ChartType.Sankey]: SankeyProps;
|
|
58
|
+
[ChartType.Scatter]: ScatterProps;
|
|
59
|
+
[ChartType.Table]: TableProps;
|
|
60
|
+
[ChartType.Treemap]: TreemapProps;
|
|
61
|
+
[ChartType.Venn]: VennProps;
|
|
62
|
+
[ChartType.Violin]: ViolinProps;
|
|
63
|
+
[ChartType.Waterfall]: WaterfallProps;
|
|
64
|
+
[ChartType.WordCloud]: WordCloudProps;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* 所有的 Vis 类型的类型定义
|
|
68
|
+
*/
|
|
69
|
+
export type Spec = {
|
|
70
|
+
[K in keyof VisOptionMap]: {
|
|
71
|
+
type: K;
|
|
72
|
+
} & VisOptionMap[K];
|
|
73
|
+
}[keyof VisOptionMap];
|
|
34
74
|
export declare const DEFAULT_CHART_COMPONENTS: Record<string, React.FC<any>>;
|
package/dist/esm/export.js
CHANGED
|
@@ -23,6 +23,7 @@ import { default as Scatter } from "./Scatter";
|
|
|
23
23
|
import { default as Treemap } from "./Treemap";
|
|
24
24
|
import { default as Venn } from "./Venn";
|
|
25
25
|
import { default as Violin } from "./Violin";
|
|
26
|
+
import { default as Waterfall } from "./Waterfall";
|
|
26
27
|
import { default as WordCloud } from "./WordCloud";
|
|
27
28
|
|
|
28
29
|
/********** graph chart **********/
|
|
@@ -40,5 +41,10 @@ import { PinMap, HeatMap, PathMap } from "./export-map";
|
|
|
40
41
|
/********** NTV **********/
|
|
41
42
|
import { default as Table } from "./Table";
|
|
42
43
|
export { VisText } from "./Text";
|
|
43
|
-
export { Area, Bar, Boxplot, Column, DualAxes, FishboneDiagram, FlowDiagram, Funnel, HeatMap, Histogram, IndentedTree, Line, Liquid, MindMap, NetworkGraph, OrganizationChart, PathMap, Pie, PinMap, Radar, Sankey, Scatter, Treemap, Venn, Violin, Table, WordCloud };
|
|
44
|
-
|
|
44
|
+
export { Area, Bar, Boxplot, Column, DualAxes, FishboneDiagram, FlowDiagram, Funnel, HeatMap, Histogram, IndentedTree, Line, Liquid, MindMap, NetworkGraph, OrganizationChart, PathMap, Pie, PinMap, Radar, Sankey, Scatter, Treemap, Venn, Violin, Waterfall, Table, WordCloud };
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 所有的 Vis 类型的类型定义
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
export var DEFAULT_CHART_COMPONENTS = (_DEFAULT_CHART_COMPON = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_DEFAULT_CHART_COMPON, ChartType.Area, Area), ChartType.Bar, Bar), ChartType.Boxplot, Boxplot), ChartType.Column, Column), ChartType.DualAxes, DualAxes), ChartType.FishboneDiagram, FishboneDiagram), ChartType.FlowDiagram, FlowDiagram), ChartType.Funnel, Funnel), ChartType.HeatMap, HeatMap), ChartType.Histogram, Histogram), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_DEFAULT_CHART_COMPON, ChartType.IndentedTree, IndentedTree), ChartType.Line, Line), ChartType.Liquid, Liquid), ChartType.MindMap, MindMap), ChartType.NetworkGraph, NetworkGraph), ChartType.Pie, Pie), ChartType.PinMap, PinMap), ChartType.Radar, Radar), ChartType.Sankey, Sankey), ChartType.Scatter, Scatter), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_DEFAULT_CHART_COMPON, ChartType.Treemap, Treemap), ChartType.Venn, Venn), ChartType.Violin, Violin), ChartType.Waterfall, Waterfall), ChartType.Table, Table), ChartType.WordCloud, WordCloud), ChartType.OrganizationChart, OrganizationChart));
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
export * from './export';
|
|
3
3
|
/********** export types **********/
|
|
4
4
|
export * from './types';
|
|
5
|
+
/********** export render **********/
|
|
6
|
+
export * from './render';
|
|
5
7
|
/********** export GPTVis **********/
|
|
6
8
|
export { withChartCode, withDefaultChartCode } from './ChartCodeRender';
|
|
7
9
|
export type { CodeBlockComponent, ErrorRender, WithChartCodeOptions } from './ChartCodeRender/type';
|
package/dist/esm/index.js
CHANGED
|
@@ -4,6 +4,9 @@ export * from "./export";
|
|
|
4
4
|
/********** export types **********/
|
|
5
5
|
export * from "./types";
|
|
6
6
|
|
|
7
|
+
/********** export render **********/
|
|
8
|
+
export * from "./render";
|
|
9
|
+
|
|
7
10
|
/********** export GPTVis **********/
|
|
8
11
|
export { withChartCode, withDefaultChartCode } from "./ChartCodeRender";
|
|
9
12
|
export { default as ConfigProvider } from "./ConfigProvider";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var _excluded = ["type"];
|
|
2
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
3
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import ReactDOM from 'react-dom';
|
|
6
|
+
import { DEFAULT_CHART_COMPONENTS } from "./export";
|
|
7
|
+
var roots = new Map();
|
|
8
|
+
function getRoot(container) {
|
|
9
|
+
if (roots.has(container)) {
|
|
10
|
+
return roots.get(container);
|
|
11
|
+
}
|
|
12
|
+
var root = ReactDOM.createRoot(container);
|
|
13
|
+
roots.set(container, root);
|
|
14
|
+
return root;
|
|
15
|
+
}
|
|
16
|
+
export function render(container, spec) {
|
|
17
|
+
var mount = typeof container === 'string' ? document.querySelector(container) : container;
|
|
18
|
+
if (!mount) throw new Error('Target container not found: ' + container);
|
|
19
|
+
var type = spec.type,
|
|
20
|
+
chartProps = _objectWithoutProperties(spec, _excluded);
|
|
21
|
+
var ChartComp = DEFAULT_CHART_COMPONENTS[type];
|
|
22
|
+
if (!ChartComp) {
|
|
23
|
+
throw new Error("Unknown chart type: ".concat(type));
|
|
24
|
+
}
|
|
25
|
+
var chartElement = /*#__PURE__*/React.createElement(ChartComp, chartProps);
|
|
26
|
+
if (ReactDOM.createRoot) {
|
|
27
|
+
var root = getRoot(mount);
|
|
28
|
+
root.render(chartElement);
|
|
29
|
+
} else {
|
|
30
|
+
ReactDOM.render(chartElement, mount);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -28,6 +28,7 @@ export declare enum ChartType {
|
|
|
28
28
|
Treemap = "treemap",
|
|
29
29
|
Venn = "venn",
|
|
30
30
|
Violin = "violin",
|
|
31
|
+
Waterfall = "waterfall",
|
|
31
32
|
Table = "table",
|
|
32
33
|
VisText = "vis-text",
|
|
33
34
|
WordCloud = "word-cloud"
|
|
@@ -81,5 +82,6 @@ export interface Style {
|
|
|
81
82
|
lineWidth?: number;
|
|
82
83
|
backgroundColor?: string;
|
|
83
84
|
palette?: string[];
|
|
85
|
+
startAtZero?: boolean;
|
|
84
86
|
};
|
|
85
87
|
}
|
package/dist/esm/types/chart.js
CHANGED
|
@@ -24,6 +24,7 @@ export var ChartType = /*#__PURE__*/function (ChartType) {
|
|
|
24
24
|
ChartType["Treemap"] = "treemap";
|
|
25
25
|
ChartType["Venn"] = "venn";
|
|
26
26
|
ChartType["Violin"] = "violin";
|
|
27
|
+
ChartType["Waterfall"] = "waterfall";
|
|
27
28
|
ChartType["Table"] = "table";
|
|
28
29
|
ChartType["VisText"] = "vis-text";
|
|
29
30
|
ChartType["WordCloud"] = "word-cloud";
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "0.5.
|
|
1
|
+
declare const _default: "0.5.11";
|
|
2
2
|
export default _default;
|