@bitblit/ratchet-echarts 6.0.146-alpha → 6.0.148-alpha
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/package.json +4 -3
- package/src/build/ratchet-echarts-info.ts +19 -0
- package/src/common/echart-canvas-config.ts +4 -0
- package/src/common/echart-ratchet.ts +58 -0
- package/src/examples/area.spec.ts +113 -0
- package/src/examples/bar.spec.ts +77 -0
- package/src/examples/bubble.spec.ts +172 -0
- package/src/examples/pie.spec.ts +78 -0
- package/src/examples/simple-bar.spec.ts +37 -0
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitblit/ratchet-echarts",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.148-alpha",
|
|
4
4
|
"description": "Library for using echarts on Node",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
|
+
"src/**",
|
|
7
8
|
"lib/**",
|
|
8
9
|
"bin/**"
|
|
9
10
|
],
|
|
@@ -34,12 +35,12 @@
|
|
|
34
35
|
"config": {},
|
|
35
36
|
"license": "Apache-2.0",
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@bitblit/ratchet-common": "6.0.
|
|
38
|
+
"@bitblit/ratchet-common": "6.0.148-alpha",
|
|
38
39
|
"canvas": "3.2.0",
|
|
39
40
|
"echarts": "6.0.0"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
|
-
"@bitblit/ratchet-common": "6.0.
|
|
43
|
+
"@bitblit/ratchet-common": "6.0.148-alpha",
|
|
43
44
|
"canvas": "^3.2.0 ",
|
|
44
45
|
"echarts": "^6.0.0"
|
|
45
46
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BuildInformation } from '@bitblit/ratchet-common/build/build-information';
|
|
2
|
+
|
|
3
|
+
export class RatchetEchartsInfo {
|
|
4
|
+
// Empty constructor prevents instantiation
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
6
|
+
private constructor() {}
|
|
7
|
+
|
|
8
|
+
public static buildInformation(): BuildInformation {
|
|
9
|
+
const val: BuildInformation = {
|
|
10
|
+
version: 'LOCAL-SNAPSHOT',
|
|
11
|
+
hash: 'LOCAL-HASH',
|
|
12
|
+
branch: 'LOCAL-BRANCH',
|
|
13
|
+
tag: 'LOCAL-TAG',
|
|
14
|
+
timeBuiltISO: 'LOCAL-TIME-ISO',
|
|
15
|
+
notes: 'LOCAL-NOTES',
|
|
16
|
+
};
|
|
17
|
+
return val;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as echarts from 'echarts';
|
|
2
|
+
import { ECharts, EChartsOption } from 'echarts';
|
|
3
|
+
import { Canvas } from 'canvas';
|
|
4
|
+
import { EChartCanvasConfig } from './echart-canvas-config.js';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
|
|
7
|
+
export class EChartRatchet {
|
|
8
|
+
public static async renderChartUsingProvidedCanvas(opt: EChartsOption, canvas: Canvas): Promise<Buffer> {
|
|
9
|
+
if (!opt) {
|
|
10
|
+
throw new Error('You must supply an opts parameter');
|
|
11
|
+
}
|
|
12
|
+
if (!canvas) {
|
|
13
|
+
throw new Error('You must supply an canvas parameter');
|
|
14
|
+
}
|
|
15
|
+
let rval: Buffer = null;
|
|
16
|
+
|
|
17
|
+
opt.animation = false; // Always do not animate given its is a static image
|
|
18
|
+
const canvasHtml: HTMLElement = canvas as unknown as HTMLElement;
|
|
19
|
+
// This is deprecated, and unneeded so far as I can tell
|
|
20
|
+
//echarts.setCanvasCreator(()=>{return canvasHtml;});
|
|
21
|
+
const chart: ECharts = echarts.init(canvasHtml);
|
|
22
|
+
chart.setOption(opt);
|
|
23
|
+
rval = canvas.toBuffer();
|
|
24
|
+
return rval;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public static async renderChart(opts: EChartsOption, config: EChartCanvasConfig): Promise<Buffer> {
|
|
28
|
+
if (!opts) {
|
|
29
|
+
throw new Error('You must supply an opts parameter');
|
|
30
|
+
}
|
|
31
|
+
if (!config) {
|
|
32
|
+
throw new Error('You must supply an config parameter');
|
|
33
|
+
}
|
|
34
|
+
const canvas: Canvas = new Canvas(config.width, config.height);
|
|
35
|
+
const rval: Buffer = await this.renderChartUsingProvidedCanvas(opts, canvas);
|
|
36
|
+
|
|
37
|
+
return rval;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public static async renderChartToPngFile(filename: string, opts: EChartsOption, config: EChartCanvasConfig): Promise<Buffer> {
|
|
41
|
+
if (!opts) {
|
|
42
|
+
throw new Error('You must supply an opts parameter');
|
|
43
|
+
}
|
|
44
|
+
if (!config) {
|
|
45
|
+
throw new Error('You must supply an config parameter');
|
|
46
|
+
}
|
|
47
|
+
if (!filename || filename.trim().length === 0) {
|
|
48
|
+
throw new Error('You must supply a non-empty filename parameter');
|
|
49
|
+
}
|
|
50
|
+
if (!filename.toLowerCase().endsWith('.png')) {
|
|
51
|
+
throw new Error('Your filename should end with .png - this generates a png file');
|
|
52
|
+
}
|
|
53
|
+
const rval: Buffer = await this.renderChart(opts, config);
|
|
54
|
+
fs.writeFileSync(filename, rval);
|
|
55
|
+
|
|
56
|
+
return rval;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { EChartsOption } from 'echarts';
|
|
2
|
+
import { EChartRatchet } from '../common/echart-ratchet.js';
|
|
3
|
+
import { describe, expect, test } from 'vitest';
|
|
4
|
+
|
|
5
|
+
const options: EChartsOption = {
|
|
6
|
+
title: {
|
|
7
|
+
text: 'Stacked Area Chart',
|
|
8
|
+
},
|
|
9
|
+
tooltip: {
|
|
10
|
+
trigger: 'axis',
|
|
11
|
+
axisPointer: {
|
|
12
|
+
type: 'cross',
|
|
13
|
+
label: {
|
|
14
|
+
backgroundColor: '#6a7985',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
legend: {
|
|
19
|
+
data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine'],
|
|
20
|
+
},
|
|
21
|
+
toolbox: {
|
|
22
|
+
feature: {
|
|
23
|
+
saveAsImage: {},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
grid: {
|
|
27
|
+
left: '3%',
|
|
28
|
+
right: '4%',
|
|
29
|
+
bottom: '3%',
|
|
30
|
+
containLabel: true,
|
|
31
|
+
},
|
|
32
|
+
xAxis: [
|
|
33
|
+
{
|
|
34
|
+
type: 'category',
|
|
35
|
+
boundaryGap: false,
|
|
36
|
+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
yAxis: [
|
|
40
|
+
{
|
|
41
|
+
type: 'value',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
series: [
|
|
45
|
+
{
|
|
46
|
+
name: 'Email',
|
|
47
|
+
type: 'line',
|
|
48
|
+
stack: 'Total',
|
|
49
|
+
areaStyle: {},
|
|
50
|
+
emphasis: {
|
|
51
|
+
focus: 'series',
|
|
52
|
+
},
|
|
53
|
+
data: [120, 132, 101, 134, 90, 230, 210],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'Union Ads',
|
|
57
|
+
type: 'line',
|
|
58
|
+
stack: 'Total',
|
|
59
|
+
areaStyle: {},
|
|
60
|
+
emphasis: {
|
|
61
|
+
focus: 'series',
|
|
62
|
+
},
|
|
63
|
+
data: [220, 182, 191, 234, 290, 330, 310],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'Video Ads',
|
|
67
|
+
type: 'line',
|
|
68
|
+
stack: 'Total',
|
|
69
|
+
areaStyle: {},
|
|
70
|
+
emphasis: {
|
|
71
|
+
focus: 'series',
|
|
72
|
+
},
|
|
73
|
+
data: [150, 232, 201, 154, 190, 330, 410],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'Direct',
|
|
77
|
+
type: 'line',
|
|
78
|
+
stack: 'Total',
|
|
79
|
+
areaStyle: {},
|
|
80
|
+
emphasis: {
|
|
81
|
+
focus: 'series',
|
|
82
|
+
},
|
|
83
|
+
data: [320, 332, 301, 334, 390, 330, 320],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: 'Search Engine',
|
|
87
|
+
type: 'line',
|
|
88
|
+
stack: 'Total',
|
|
89
|
+
label: {
|
|
90
|
+
show: true,
|
|
91
|
+
position: 'top',
|
|
92
|
+
},
|
|
93
|
+
areaStyle: {},
|
|
94
|
+
emphasis: {
|
|
95
|
+
focus: 'series',
|
|
96
|
+
},
|
|
97
|
+
data: [820, 932, 901, 934, 1290, 1330, 1320],
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
describe('#areaChart', function () {
|
|
103
|
+
test('should generate the chart', {timeout: 10_000},async () => {
|
|
104
|
+
const data: Buffer = await EChartRatchet.renderChart(options, {
|
|
105
|
+
width: 1000,
|
|
106
|
+
height: 500,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// As of 2025-08-24 this is 60589... there must be a better test than this...
|
|
110
|
+
expect(data.length).toBeGreaterThan(55_000);
|
|
111
|
+
expect(data.length).toBeLessThan(65_000);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { EChartsOption } from 'echarts';
|
|
2
|
+
import { EChartRatchet } from '../common/echart-ratchet.js';
|
|
3
|
+
import { LabelOption } from 'echarts/types/src/util/types.js';
|
|
4
|
+
import { describe, expect, test } from 'vitest';
|
|
5
|
+
|
|
6
|
+
const labelRight: LabelOption = {
|
|
7
|
+
position: 'right',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const options: EChartsOption = {
|
|
11
|
+
title: {
|
|
12
|
+
text: 'Bar Chart with Negative Value',
|
|
13
|
+
},
|
|
14
|
+
tooltip: {
|
|
15
|
+
trigger: 'axis',
|
|
16
|
+
axisPointer: {
|
|
17
|
+
type: 'shadow',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
grid: {
|
|
21
|
+
top: 80,
|
|
22
|
+
bottom: 30,
|
|
23
|
+
},
|
|
24
|
+
xAxis: {
|
|
25
|
+
type: 'value',
|
|
26
|
+
position: 'top',
|
|
27
|
+
splitLine: {
|
|
28
|
+
lineStyle: {
|
|
29
|
+
type: 'dashed',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
yAxis: {
|
|
34
|
+
type: 'category',
|
|
35
|
+
axisLine: { show: false },
|
|
36
|
+
axisLabel: { show: false },
|
|
37
|
+
axisTick: { show: false },
|
|
38
|
+
splitLine: { show: false },
|
|
39
|
+
data: ['ten', 'nine', 'eight', 'seven', 'six', 'five', 'four', 'three', 'two', 'one'],
|
|
40
|
+
},
|
|
41
|
+
series: [
|
|
42
|
+
{
|
|
43
|
+
name: 'Cost',
|
|
44
|
+
type: 'bar',
|
|
45
|
+
stack: 'Total',
|
|
46
|
+
label: {
|
|
47
|
+
show: true,
|
|
48
|
+
formatter: '{b}',
|
|
49
|
+
},
|
|
50
|
+
data: [
|
|
51
|
+
{ value: -0.07, label: labelRight },
|
|
52
|
+
{ value: -0.09, label: labelRight },
|
|
53
|
+
0.2,
|
|
54
|
+
0.44,
|
|
55
|
+
{ value: -0.23, label: labelRight },
|
|
56
|
+
0.08,
|
|
57
|
+
{ value: -0.17, label: labelRight },
|
|
58
|
+
0.47,
|
|
59
|
+
{ value: -0.36, label: labelRight },
|
|
60
|
+
0.18,
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
describe('#simpleBarChart', function () {
|
|
67
|
+
test('should generate the chart', {timeout: 10_000}, async () => {
|
|
68
|
+
const data: Buffer = await EChartRatchet.renderChartToPngFile('test.png', options, {
|
|
69
|
+
width: 1000,
|
|
70
|
+
height: 500,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// As of 2022-08-06 this is 15569... there must be a better test than this..
|
|
74
|
+
expect(data.length).toBeGreaterThan(15_000);
|
|
75
|
+
expect(data.length).toBeLessThan(20_000);
|
|
76
|
+
} );
|
|
77
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import * as echarts from 'echarts';
|
|
2
|
+
import { EChartsOption } from 'echarts';
|
|
3
|
+
import { EChartRatchet } from '../common/echart-ratchet.js';
|
|
4
|
+
import { describe, expect, test } from 'vitest';
|
|
5
|
+
|
|
6
|
+
const data = [
|
|
7
|
+
[
|
|
8
|
+
[28604, 77, 17096869, 'Australia', 1990],
|
|
9
|
+
[31163, 77.4, 27662440, 'Canada', 1990],
|
|
10
|
+
[1516, 68, 1154605773, 'China', 1990],
|
|
11
|
+
[13670, 74.7, 10582082, 'Cuba', 1990],
|
|
12
|
+
[28599, 75, 4986705, 'Finland', 1990],
|
|
13
|
+
[29476, 77.1, 56943299, 'France', 1990],
|
|
14
|
+
[31476, 75.4, 78958237, 'Germany', 1990],
|
|
15
|
+
[28666, 78.1, 254830, 'Iceland', 1990],
|
|
16
|
+
[1777, 57.7, 870601776, 'India', 1990],
|
|
17
|
+
[29550, 79.1, 122249285, 'Japan', 1990],
|
|
18
|
+
[2076, 67.9, 20194354, 'North Korea', 1990],
|
|
19
|
+
[12087, 72, 42972254, 'South Korea', 1990],
|
|
20
|
+
[24021, 75.4, 3397534, 'New Zealand', 1990],
|
|
21
|
+
[43296, 76.8, 4240375, 'Norway', 1990],
|
|
22
|
+
[10088, 70.8, 38195258, 'Poland', 1990],
|
|
23
|
+
[19349, 69.6, 147568552, 'Russia', 1990],
|
|
24
|
+
[10670, 67.3, 53994605, 'Turkey', 1990],
|
|
25
|
+
[26424, 75.7, 57110117, 'United Kingdom', 1990],
|
|
26
|
+
[37062, 75.4, 252847810, 'United States', 1990],
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
[44056, 81.8, 23968973, 'Australia', 2015],
|
|
30
|
+
[43294, 81.7, 35939927, 'Canada', 2015],
|
|
31
|
+
[13334, 76.9, 1376048943, 'China', 2015],
|
|
32
|
+
[21291, 78.5, 11389562, 'Cuba', 2015],
|
|
33
|
+
[38923, 80.8, 5503457, 'Finland', 2015],
|
|
34
|
+
[37599, 81.9, 64395345, 'France', 2015],
|
|
35
|
+
[44053, 81.1, 80688545, 'Germany', 2015],
|
|
36
|
+
[42182, 82.8, 329425, 'Iceland', 2015],
|
|
37
|
+
[5903, 66.8, 1311050527, 'India', 2015],
|
|
38
|
+
[36162, 83.5, 126573481, 'Japan', 2015],
|
|
39
|
+
[1390, 71.4, 25155317, 'North Korea', 2015],
|
|
40
|
+
[34644, 80.7, 50293439, 'South Korea', 2015],
|
|
41
|
+
[34186, 80.6, 4528526, 'New Zealand', 2015],
|
|
42
|
+
[64304, 81.6, 5210967, 'Norway', 2015],
|
|
43
|
+
[24787, 77.3, 38611794, 'Poland', 2015],
|
|
44
|
+
[23038, 73.13, 143456918, 'Russia', 2015],
|
|
45
|
+
[19360, 76.5, 78665830, 'Turkey', 2015],
|
|
46
|
+
[38225, 81.4, 64715810, 'United Kingdom', 2015],
|
|
47
|
+
[53354, 79.1, 321773631, 'United States', 2015],
|
|
48
|
+
],
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const options: EChartsOption = {
|
|
52
|
+
backgroundColor: new echarts.graphic.RadialGradient(0.3, 0.3, 0.8, [
|
|
53
|
+
{
|
|
54
|
+
offset: 0,
|
|
55
|
+
color: '#f7f8fa',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
offset: 1,
|
|
59
|
+
color: '#cdd0d5',
|
|
60
|
+
},
|
|
61
|
+
]),
|
|
62
|
+
title: {
|
|
63
|
+
text: 'Life Expectancy and GDP by Country',
|
|
64
|
+
left: '5%',
|
|
65
|
+
top: '3%',
|
|
66
|
+
},
|
|
67
|
+
legend: {
|
|
68
|
+
right: '10%',
|
|
69
|
+
top: '3%',
|
|
70
|
+
data: ['1990', '2015'],
|
|
71
|
+
},
|
|
72
|
+
grid: {
|
|
73
|
+
left: '8%',
|
|
74
|
+
top: '10%',
|
|
75
|
+
},
|
|
76
|
+
xAxis: {
|
|
77
|
+
splitLine: {
|
|
78
|
+
lineStyle: {
|
|
79
|
+
type: 'dashed',
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
yAxis: {
|
|
84
|
+
splitLine: {
|
|
85
|
+
lineStyle: {
|
|
86
|
+
type: 'dashed',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
scale: true,
|
|
90
|
+
},
|
|
91
|
+
series: [
|
|
92
|
+
{
|
|
93
|
+
name: '1990',
|
|
94
|
+
data: data[0],
|
|
95
|
+
type: 'scatter',
|
|
96
|
+
symbolSize: function (data) {
|
|
97
|
+
return Math.sqrt(data[2]) / 5e2;
|
|
98
|
+
},
|
|
99
|
+
emphasis: {
|
|
100
|
+
focus: 'series',
|
|
101
|
+
label: {
|
|
102
|
+
show: true,
|
|
103
|
+
formatter: function (param) {
|
|
104
|
+
return param.data[3];
|
|
105
|
+
},
|
|
106
|
+
position: 'top',
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
itemStyle: {
|
|
110
|
+
shadowBlur: 10,
|
|
111
|
+
shadowColor: 'rgba(120, 36, 50, 0.5)',
|
|
112
|
+
shadowOffsetY: 5,
|
|
113
|
+
color: new echarts.graphic.RadialGradient(0.4, 0.3, 1, [
|
|
114
|
+
{
|
|
115
|
+
offset: 0,
|
|
116
|
+
color: 'rgb(251, 118, 123)',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
offset: 1,
|
|
120
|
+
color: 'rgb(204, 46, 72)',
|
|
121
|
+
},
|
|
122
|
+
]),
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: '2015',
|
|
127
|
+
data: data[1],
|
|
128
|
+
type: 'scatter',
|
|
129
|
+
symbolSize: function (data) {
|
|
130
|
+
return Math.sqrt(data[2]) / 5e2;
|
|
131
|
+
},
|
|
132
|
+
emphasis: {
|
|
133
|
+
focus: 'series',
|
|
134
|
+
label: {
|
|
135
|
+
show: true,
|
|
136
|
+
formatter: function (param) {
|
|
137
|
+
return param.data[3];
|
|
138
|
+
},
|
|
139
|
+
position: 'top',
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
itemStyle: {
|
|
143
|
+
shadowBlur: 10,
|
|
144
|
+
shadowColor: 'rgba(25, 100, 150, 0.5)',
|
|
145
|
+
shadowOffsetY: 5,
|
|
146
|
+
color: new echarts.graphic.RadialGradient(0.4, 0.3, 1, [
|
|
147
|
+
{
|
|
148
|
+
offset: 0,
|
|
149
|
+
color: 'rgb(129, 227, 238)',
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
offset: 1,
|
|
153
|
+
color: 'rgb(25, 183, 207)',
|
|
154
|
+
},
|
|
155
|
+
]),
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
describe('#bubbleChart', function () {
|
|
162
|
+
test('should generate the chart', {timeout: 10_000},async () => {
|
|
163
|
+
const data: Buffer = await EChartRatchet.renderChart(options, {
|
|
164
|
+
width: 1000,
|
|
165
|
+
height: 500,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// As of 2022-08-06 this is 140641... there must be a better test than this..
|
|
169
|
+
expect(data.length).toBeGreaterThan(140_000);
|
|
170
|
+
expect(data.length).toBeLessThan(150_000);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { EChartsOption } from 'echarts';
|
|
2
|
+
import { EChartRatchet } from '../common/echart-ratchet.js';
|
|
3
|
+
import { describe, expect, test } from 'vitest';
|
|
4
|
+
|
|
5
|
+
const options: EChartsOption = {
|
|
6
|
+
backgroundColor: '#2c343c',
|
|
7
|
+
title: {
|
|
8
|
+
text: 'Customized Pie',
|
|
9
|
+
left: 'center',
|
|
10
|
+
top: 20,
|
|
11
|
+
textStyle: {
|
|
12
|
+
color: '#ccc',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
tooltip: {
|
|
16
|
+
trigger: 'item',
|
|
17
|
+
},
|
|
18
|
+
visualMap: {
|
|
19
|
+
show: false,
|
|
20
|
+
min: 80,
|
|
21
|
+
max: 600,
|
|
22
|
+
inRange: {
|
|
23
|
+
colorLightness: [0, 1],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
series: [
|
|
27
|
+
{
|
|
28
|
+
name: 'Access From',
|
|
29
|
+
type: 'pie',
|
|
30
|
+
radius: '55%',
|
|
31
|
+
center: ['50%', '50%'],
|
|
32
|
+
data: [
|
|
33
|
+
{ value: 335, name: 'Direct' },
|
|
34
|
+
{ value: 310, name: 'Email' },
|
|
35
|
+
{ value: 274, name: 'Union Ads' },
|
|
36
|
+
{ value: 235, name: 'Video Ads' },
|
|
37
|
+
{ value: 400, name: 'Search Engine' },
|
|
38
|
+
].sort(function (a, b) {
|
|
39
|
+
return a.value - b.value;
|
|
40
|
+
}),
|
|
41
|
+
roseType: 'radius',
|
|
42
|
+
label: {
|
|
43
|
+
color: 'rgba(255, 255, 255, 0.3)',
|
|
44
|
+
},
|
|
45
|
+
labelLine: {
|
|
46
|
+
lineStyle: {
|
|
47
|
+
color: 'rgba(255, 255, 255, 0.3)',
|
|
48
|
+
},
|
|
49
|
+
smooth: 0.2,
|
|
50
|
+
length: 10,
|
|
51
|
+
length2: 20,
|
|
52
|
+
},
|
|
53
|
+
itemStyle: {
|
|
54
|
+
color: '#c23531',
|
|
55
|
+
shadowBlur: 200,
|
|
56
|
+
shadowColor: 'rgba(0, 0, 0, 0.5)',
|
|
57
|
+
},
|
|
58
|
+
animationType: 'scale',
|
|
59
|
+
animationEasing: 'elasticOut',
|
|
60
|
+
animationDelay: function (_idx) {
|
|
61
|
+
return Math.random() * 200;
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
describe('#pieChart', function () {
|
|
68
|
+
test('should generate the chart', {timeout: 10_000},async () => {
|
|
69
|
+
const data: Buffer = await EChartRatchet.renderChartToPngFile('test.png', options, {
|
|
70
|
+
width: 1000,
|
|
71
|
+
height: 500,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// As of 2022-08-06 this is 32175... there must be a better test than this..
|
|
75
|
+
expect(data.length).toBeGreaterThan(30_000);
|
|
76
|
+
expect(data.length).toBeLessThan(40_000);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EChartRatchet } from '../common/echart-ratchet.js';
|
|
2
|
+
import { EChartsOption } from 'echarts';
|
|
3
|
+
import { describe, expect, test } from 'vitest';
|
|
4
|
+
|
|
5
|
+
const options: EChartsOption = {
|
|
6
|
+
title: {
|
|
7
|
+
text: 'test',
|
|
8
|
+
},
|
|
9
|
+
tooltip: {},
|
|
10
|
+
legend: {
|
|
11
|
+
data: ['test'],
|
|
12
|
+
},
|
|
13
|
+
xAxis: {
|
|
14
|
+
data: ['a', 'b', 'c', 'd', 'f', 'g'],
|
|
15
|
+
},
|
|
16
|
+
yAxis: {},
|
|
17
|
+
series: [
|
|
18
|
+
{
|
|
19
|
+
name: 'test',
|
|
20
|
+
type: 'bar',
|
|
21
|
+
data: [5, 20, 36, 10, 10, 20],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('#simpleBarChart', function () {
|
|
27
|
+
test('should generate the chart', {timeout: 10_000},async () => {
|
|
28
|
+
const data: Buffer = await EChartRatchet.renderChart(options, {
|
|
29
|
+
width: 1000,
|
|
30
|
+
height: 500,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// As of 2022-08-06 this is 7606... there must be a better test than this..
|
|
34
|
+
expect(data.length).toBeGreaterThan(5_000);
|
|
35
|
+
expect(data.length).toBeLessThan(10_000);
|
|
36
|
+
});
|
|
37
|
+
});
|