jmchart 1.2.12 → 1.2.15
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/README.md +370 -37
- package/build.js +6 -3
- package/dist/jmchart.amd.js +4459 -772
- package/dist/jmchart.cjs.js +4459 -772
- package/dist/jmchart.esm.js +4459 -772
- package/dist/jmchart.iife.js +4460 -773
- package/dist/jmchart.system.js +4459 -772
- package/package.json +7 -4
- package/server.js +64 -32
- package/src/common/style.js +294 -0
- package/src/component/vchart.js +24 -3
- package/src/core/axis/axis.js +6 -3
- package/src/core/markLine/manager.js +14 -8
- package/src/jmChart.js +72 -29
- package/src/series/areaSeries.js +50 -0
- package/src/series/barSeries.js +3 -6
- package/src/series/boxPlotSeries.js +254 -0
- package/src/series/bubbleSeries.js +131 -0
- package/src/series/candlestickSeries.js +44 -29
- package/src/series/funnelSeries.js +190 -0
- package/src/series/gaugeSeries.js +255 -0
- package/src/series/heatmapSeries.js +184 -0
- package/src/series/lineSeries.js +47 -33
- package/src/series/pieSeries.js +5 -3
- package/src/series/radarSeries.js +18 -11
- package/src/series/rangeSeries.js +149 -0
- package/src/series/ringProgressSeries.js +191 -0
- package/src/series/scatterSeries.js +125 -0
- package/src/series/series.js +149 -49
- package/src/series/stackBarSeries.js +48 -30
- package/src/series/stackLineSeries.js +7 -131
- package/src/series/sunburstSeries.js +240 -0
- package/src/series/waterfallSeries.js +179 -0
- package/src/series/wordCloudSeries.js +234 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import jmSeries, { ANIMATION_DATA_THRESHOLD, DEFAULT_ANIMATION_COUNT } from './series.js';
|
|
2
|
+
|
|
3
|
+
export default class jmWaterfallSeries extends jmSeries {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
options.style = options.style || options.graph.style.waterfall;
|
|
6
|
+
super(options);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
init() {
|
|
10
|
+
const {
|
|
11
|
+
points,
|
|
12
|
+
dataChanged
|
|
13
|
+
} = this.initDataPoint();
|
|
14
|
+
|
|
15
|
+
const len = points.length;
|
|
16
|
+
if(!len) return;
|
|
17
|
+
|
|
18
|
+
this.pointsLen = len;
|
|
19
|
+
this.style.stroke = this.style.color;
|
|
20
|
+
|
|
21
|
+
let cumulativeValue = 0;
|
|
22
|
+
const processedPoints = [];
|
|
23
|
+
|
|
24
|
+
for(let i = 0; i < len; i++) {
|
|
25
|
+
const p = points[i];
|
|
26
|
+
if(typeof p.y === 'undefined' || p.y === null) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
p.originalValue = p.yValue;
|
|
31
|
+
p.startValue = cumulativeValue;
|
|
32
|
+
p.endValue = cumulativeValue + p.yValue;
|
|
33
|
+
cumulativeValue = p.endValue;
|
|
34
|
+
|
|
35
|
+
processedPoints.push(p);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let minValue = Infinity;
|
|
39
|
+
let maxValue = -Infinity;
|
|
40
|
+
|
|
41
|
+
for(const p of processedPoints) {
|
|
42
|
+
minValue = Math.min(minValue, p.startValue, p.endValue);
|
|
43
|
+
maxValue = Math.max(maxValue, p.startValue, p.endValue);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if(this.yAxis) {
|
|
47
|
+
this.yAxis.min(minValue);
|
|
48
|
+
this.yAxis.max(maxValue);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const minY = this.yAxis ? this.yAxis.min() : 0;
|
|
52
|
+
const ystep = this.yAxis ? this.yAxis.step() : 1;
|
|
53
|
+
const chartHeight = this.graph.chartArea.height;
|
|
54
|
+
|
|
55
|
+
const isRunningAni = this.enableAnimate && (dataChanged || this.___animateCounter > 0) && len < ANIMATION_DATA_THRESHOLD;
|
|
56
|
+
|
|
57
|
+
const aniCount = (this.style.aniCount || DEFAULT_ANIMATION_COUNT);
|
|
58
|
+
const aniStep = Math.floor(len / aniCount) || 1;
|
|
59
|
+
|
|
60
|
+
for(let i = 0; i < processedPoints.length; i++) {
|
|
61
|
+
const p = processedPoints[i];
|
|
62
|
+
|
|
63
|
+
if(isRunningAni && i > this.___animateCounter) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const startY = chartHeight - (p.startValue - minY) * ystep;
|
|
68
|
+
const endY = chartHeight - (p.endValue - minY) * ystep;
|
|
69
|
+
const height = Math.abs(endY - startY);
|
|
70
|
+
|
|
71
|
+
let barColor = this.style.color;
|
|
72
|
+
if(p.yValue > 0) {
|
|
73
|
+
barColor = this.style.increaseColor || '#52c41a';
|
|
74
|
+
} else if(p.yValue < 0) {
|
|
75
|
+
barColor = this.style.decreaseColor || '#f5222d';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this.createWaterfallBar(p, startY, endY, height, barColor);
|
|
79
|
+
|
|
80
|
+
if(i < processedPoints.length - 1) {
|
|
81
|
+
this.createConnectorLine(p, processedPoints[i + 1], chartHeight, minY, ystep);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.createItemLabel(p);
|
|
85
|
+
|
|
86
|
+
this.emit('onPointCreated', p);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if(this.___animateCounter >= len - 1) {
|
|
90
|
+
this.___animateCounter = 0;
|
|
91
|
+
} else if(isRunningAni) {
|
|
92
|
+
this.___animateCounter += aniStep;
|
|
93
|
+
this.graph.utils.requestAnimationFrame(() => {
|
|
94
|
+
this.needUpdate = true;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
createWaterfallBar(p, startY, endY, height, color) {
|
|
100
|
+
const barWidth = this.style.perWidth || 0.5;
|
|
101
|
+
const chartWidth = this.graph.chartArea.width;
|
|
102
|
+
const barX = p.x - (chartWidth * barWidth / this.pointsLen) / 2;
|
|
103
|
+
const barHeight = height;
|
|
104
|
+
|
|
105
|
+
const barStyle = {
|
|
106
|
+
stroke: color,
|
|
107
|
+
fill: color,
|
|
108
|
+
zIndex: 1
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const barShape = this.graph.createShape('rect', {
|
|
112
|
+
style: barStyle,
|
|
113
|
+
position: {
|
|
114
|
+
x: barX,
|
|
115
|
+
y: Math.min(startY, endY)
|
|
116
|
+
},
|
|
117
|
+
width: chartWidth * barWidth / this.pointsLen,
|
|
118
|
+
height: barHeight
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
this.addShape(barShape);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
createConnectorLine(currentPoint, nextPoint, chartHeight, minY, ystep) {
|
|
125
|
+
const startY = chartHeight - (currentPoint.endValue - minY) * ystep;
|
|
126
|
+
const chartWidth = this.graph.chartArea.width;
|
|
127
|
+
const barWidth = this.style.perWidth || 0.5;
|
|
128
|
+
const nextX = nextPoint.x - (chartWidth * barWidth / this.pointsLen) / 2;
|
|
129
|
+
|
|
130
|
+
const horizontalLine = this.graph.createShape('line', {
|
|
131
|
+
style: {
|
|
132
|
+
stroke: this.style.connectorColor || '#999',
|
|
133
|
+
lineWidth: 1,
|
|
134
|
+
lineType: 'dotted',
|
|
135
|
+
zIndex: 0
|
|
136
|
+
},
|
|
137
|
+
start: { x: currentPoint.x, y: startY },
|
|
138
|
+
end: { x: nextX, y: startY }
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
this.addShape(horizontalLine);
|
|
142
|
+
|
|
143
|
+
const nextStartY = chartHeight - (nextPoint.startValue - minY) * ystep;
|
|
144
|
+
|
|
145
|
+
const verticalLine = this.graph.createShape('line', {
|
|
146
|
+
style: {
|
|
147
|
+
stroke: this.style.connectorColor || '#999',
|
|
148
|
+
lineWidth: 1,
|
|
149
|
+
zIndex: 0
|
|
150
|
+
},
|
|
151
|
+
start: { x: nextX, y: startY },
|
|
152
|
+
end: { x: nextX, y: nextStartY }
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
this.addShape(verticalLine);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
createLegend() {
|
|
159
|
+
const style = this.graph.utils.clone(this.style);
|
|
160
|
+
style.stroke = this.style.color;
|
|
161
|
+
style.fill = this.style.color;
|
|
162
|
+
|
|
163
|
+
const shape = this.graph.createShape('rect', {
|
|
164
|
+
style: style,
|
|
165
|
+
position: {
|
|
166
|
+
x: 0,
|
|
167
|
+
y: 0
|
|
168
|
+
},
|
|
169
|
+
width: this.graph.style.legend.item.shape.width,
|
|
170
|
+
height: this.graph.style.legend.item.shape.height
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
this.graph.legend.append(this, shape);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export {
|
|
178
|
+
jmWaterfallSeries
|
|
179
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import jmSeries from './series.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 词云图
|
|
5
|
+
*
|
|
6
|
+
* 词云图用于展示文本数据中词语的频率或重要性,词语大小与其权重成正比。
|
|
7
|
+
* 常用于文本分析、舆情监控等场景。
|
|
8
|
+
*
|
|
9
|
+
* 数据格式要求:
|
|
10
|
+
* - field: 'weight' - 权重字段
|
|
11
|
+
* - xField: 'word' - 词语字段
|
|
12
|
+
*
|
|
13
|
+
* 样式配置:
|
|
14
|
+
* - minFontSize: 最小字体大小,默认 12
|
|
15
|
+
* - maxFontSize: 最大字体大小,默认 60
|
|
16
|
+
* - colors: 颜色数组
|
|
17
|
+
* - spiral: 是否使用螺旋布局,默认 true
|
|
18
|
+
*
|
|
19
|
+
* @class jmWordCloudSeries
|
|
20
|
+
* @module jmChart
|
|
21
|
+
* @extends jmSeries
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* chart.createSeries('wordCloud', {
|
|
25
|
+
* field: 'weight',
|
|
26
|
+
* xField: 'word',
|
|
27
|
+
* style: {
|
|
28
|
+
* minFontSize: 14,
|
|
29
|
+
* maxFontSize: 48
|
|
30
|
+
* }
|
|
31
|
+
* });
|
|
32
|
+
*/
|
|
33
|
+
export default class jmWordCloudSeries extends jmSeries {
|
|
34
|
+
constructor(options) {
|
|
35
|
+
options.style = options.style || options.graph.style.wordCloud;
|
|
36
|
+
super(options);
|
|
37
|
+
this.placedWords = [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 初始化词云图
|
|
42
|
+
*/
|
|
43
|
+
init() {
|
|
44
|
+
const data = this.data;
|
|
45
|
+
if(!data || !data.length) return;
|
|
46
|
+
|
|
47
|
+
this.placedWords = [];
|
|
48
|
+
|
|
49
|
+
const chartWidth = this.graph.chartArea.width;
|
|
50
|
+
const chartHeight = this.graph.chartArea.height;
|
|
51
|
+
const centerX = chartWidth / 2;
|
|
52
|
+
const centerY = chartHeight / 2;
|
|
53
|
+
|
|
54
|
+
const field = this.field || 'weight';
|
|
55
|
+
const xField = this.option.xField || 'word';
|
|
56
|
+
|
|
57
|
+
const weights = data.map(item => Math.abs(item[field] || 0));
|
|
58
|
+
const maxWeight = Math.max(...weights);
|
|
59
|
+
const minWeight = Math.min(...weights);
|
|
60
|
+
|
|
61
|
+
if(maxWeight === 0) return;
|
|
62
|
+
|
|
63
|
+
const minFontSize = this.style.minFontSize || 12;
|
|
64
|
+
const maxFontSize = this.style.maxFontSize || 60;
|
|
65
|
+
|
|
66
|
+
const sortedData = [...data].sort((a, b) => (b[field] || 0) - (a[field] || 0));
|
|
67
|
+
|
|
68
|
+
for(let i = 0; i < sortedData.length; i++) {
|
|
69
|
+
const item = sortedData[i];
|
|
70
|
+
const weight = item[field] || 0;
|
|
71
|
+
|
|
72
|
+
let fontSize;
|
|
73
|
+
if(maxWeight === minWeight) {
|
|
74
|
+
fontSize = (minFontSize + maxFontSize) / 2;
|
|
75
|
+
} else {
|
|
76
|
+
fontSize = minFontSize + (weight - minWeight) / (maxWeight - minWeight) * (maxFontSize - minFontSize);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const color = this.getColor(item, i);
|
|
80
|
+
const text = item[xField] || '';
|
|
81
|
+
|
|
82
|
+
if(!text) continue;
|
|
83
|
+
|
|
84
|
+
const position = this.findPosition(centerX, centerY, text, fontSize, chartWidth, chartHeight);
|
|
85
|
+
|
|
86
|
+
if(position) {
|
|
87
|
+
this.createWordLabel(text, position.x, position.y, fontSize, color, item);
|
|
88
|
+
|
|
89
|
+
this.placedWords.push({
|
|
90
|
+
x: position.x,
|
|
91
|
+
y: position.y,
|
|
92
|
+
width: position.width,
|
|
93
|
+
height: position.height
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 查找词语位置
|
|
101
|
+
*/
|
|
102
|
+
findPosition(centerX, centerY, text, fontSize, chartWidth, chartHeight) {
|
|
103
|
+
const estimatedWidth = text.length * fontSize * 0.6;
|
|
104
|
+
const estimatedHeight = fontSize * 1.2;
|
|
105
|
+
|
|
106
|
+
if(this.style.spiral !== false) {
|
|
107
|
+
return this.findSpiralPosition(centerX, centerY, estimatedWidth, estimatedHeight, chartWidth, chartHeight);
|
|
108
|
+
} else {
|
|
109
|
+
return this.findGridPosition(centerX, centerY, estimatedWidth, estimatedHeight, chartWidth, chartHeight);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 螺旋布局查找位置
|
|
115
|
+
*/
|
|
116
|
+
findSpiralPosition(centerX, centerY, width, height, chartWidth, chartHeight) {
|
|
117
|
+
const spiralStep = 5;
|
|
118
|
+
const maxRadius = Math.max(chartWidth, chartHeight);
|
|
119
|
+
let angle = 0;
|
|
120
|
+
let radius = 0;
|
|
121
|
+
|
|
122
|
+
for(let i = 0; i < 1000; i++) {
|
|
123
|
+
const x = centerX + radius * Math.cos(angle) - width / 2;
|
|
124
|
+
const y = centerY + radius * Math.sin(angle) - height / 2;
|
|
125
|
+
|
|
126
|
+
if(this.canPlace(x, y, width, height, chartWidth, chartHeight)) {
|
|
127
|
+
return { x, y, width, height };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
angle += 0.5;
|
|
131
|
+
radius += spiralStep * 0.02;
|
|
132
|
+
|
|
133
|
+
if(radius > maxRadius) break;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 网格布局查找位置
|
|
141
|
+
*/
|
|
142
|
+
findGridPosition(centerX, centerY, width, height, chartWidth, chartHeight) {
|
|
143
|
+
const gridSize = 20;
|
|
144
|
+
const halfWidth = chartWidth / 2;
|
|
145
|
+
const halfHeight = chartHeight / 2;
|
|
146
|
+
|
|
147
|
+
for(let r = 0; r < Math.max(halfWidth, halfHeight); r += gridSize) {
|
|
148
|
+
for(let dx = -r; dx <= r; dx += gridSize) {
|
|
149
|
+
for(let dy = -r; dy <= r; dy += gridSize) {
|
|
150
|
+
if(Math.abs(dx) !== r && Math.abs(dy) !== r) continue;
|
|
151
|
+
|
|
152
|
+
const x = centerX + dx - width / 2;
|
|
153
|
+
const y = centerY + dy - height / 2;
|
|
154
|
+
|
|
155
|
+
if(this.canPlace(x, y, width, height, chartWidth, chartHeight)) {
|
|
156
|
+
return { x, y, width, height };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 检查位置是否可用
|
|
167
|
+
*/
|
|
168
|
+
canPlace(x, y, width, height, chartWidth, chartHeight) {
|
|
169
|
+
if(x < 0 || y < 0 || x + width > chartWidth || y + height > chartHeight) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
for(const placed of this.placedWords) {
|
|
174
|
+
if(!(x + width < placed.x || x > placed.x + placed.width ||
|
|
175
|
+
y + height < placed.y || y > placed.y + placed.height)) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 创建词语标签
|
|
185
|
+
*/
|
|
186
|
+
createWordLabel(text, x, y, fontSize, color, item) {
|
|
187
|
+
const label = this.graph.createShape('label', {
|
|
188
|
+
style: {
|
|
189
|
+
fill: color,
|
|
190
|
+
font: `${fontSize}px Arial`,
|
|
191
|
+
textAlign: 'left',
|
|
192
|
+
textBaseline: 'top',
|
|
193
|
+
zIndex: 1
|
|
194
|
+
},
|
|
195
|
+
text: text,
|
|
196
|
+
position: { x, y },
|
|
197
|
+
data: item
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
this.addShape(label);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 获取颜色
|
|
205
|
+
*/
|
|
206
|
+
getColor(item, index) {
|
|
207
|
+
if(this.style.colors && this.style.colors.length > 0) {
|
|
208
|
+
return this.style.colors[index % this.style.colors.length];
|
|
209
|
+
}
|
|
210
|
+
if(typeof this.style.color === 'function') {
|
|
211
|
+
return this.style.color.call(this, item, index);
|
|
212
|
+
}
|
|
213
|
+
return this.graph.getColor(index);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* 生成图例
|
|
218
|
+
*/
|
|
219
|
+
createLegend() {
|
|
220
|
+
const style = this.graph.utils.clone(this.style);
|
|
221
|
+
style.fill = this.style.color || this.graph.getColor(0);
|
|
222
|
+
style.stroke = style.fill;
|
|
223
|
+
|
|
224
|
+
const shape = this.graph.createShape('label', {
|
|
225
|
+
style: style,
|
|
226
|
+
text: 'Aa',
|
|
227
|
+
position: { x: 0, y: 0 }
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
this.graph.legend.append(this, shape);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export { jmWordCloudSeries };
|