leafer-echarts 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/dist/index.d.mts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +138 -0
- package/dist/index.mjs +113 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sergei Malygin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# leafer-echarts
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/leafer-echarts)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
A custom Leafer UI element that renders **[ECharts](https://echarts.apache.org/)** charts as **SVG** inside a Leafer canvas.
|
|
7
|
+
Perfect for adding interactive data visualizations to your Leafer applications.
|
|
8
|
+
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
- Render any ECharts option as a scalable SVG image
|
|
12
|
+
- Fully reactive – update chart data with `updateOption()`
|
|
13
|
+
- Supports all ECharts features (tooltips, legends, animations – though animations are disabled in SSR mode)
|
|
14
|
+
- Integrates seamlessly with Leafer UI's event system (draggable, editable, etc.)
|
|
15
|
+
- Easy to use – just import and instantiate
|
|
16
|
+
|
|
17
|
+
## 📦 Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install leafer-echarts
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Example
|
|
24
|
+
```ts
|
|
25
|
+
import { Leafer } from 'leafer-ui';
|
|
26
|
+
import { LeaferECharts, defaultBarChartOption } from 'leafer-echarts';
|
|
27
|
+
|
|
28
|
+
const leafer = new Leafer({ view: 'canvas' });
|
|
29
|
+
|
|
30
|
+
const chart = new LeaferECharts({
|
|
31
|
+
option: defaultBarChartOption,
|
|
32
|
+
width: 600,
|
|
33
|
+
height: 400,
|
|
34
|
+
draggable: true,
|
|
35
|
+
editable: false,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
leafer.add(chart);
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Image } from 'leafer-ui';
|
|
2
|
+
import { EChartsOption } from 'echarts';
|
|
3
|
+
|
|
4
|
+
type LeaferEChartOptions = {
|
|
5
|
+
option?: EChartsOption;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
draggable?: boolean;
|
|
9
|
+
editable?: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare class LeaferECharts extends Image {
|
|
12
|
+
get __tag(): string;
|
|
13
|
+
option: EChartsOption;
|
|
14
|
+
constructor(options?: LeaferEChartOptions);
|
|
15
|
+
static renderSVG(option: EChartsOption, width: number, height: number): string;
|
|
16
|
+
updateOption(newOption: EChartsOption): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Mock bar chart (ECharts example) */
|
|
20
|
+
declare const defaultBarChartOption: EChartsOption;
|
|
21
|
+
|
|
22
|
+
export { type LeaferEChartOptions, LeaferECharts, defaultBarChartOption };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Image } from 'leafer-ui';
|
|
2
|
+
import { EChartsOption } from 'echarts';
|
|
3
|
+
|
|
4
|
+
type LeaferEChartOptions = {
|
|
5
|
+
option?: EChartsOption;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
draggable?: boolean;
|
|
9
|
+
editable?: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare class LeaferECharts extends Image {
|
|
12
|
+
get __tag(): string;
|
|
13
|
+
option: EChartsOption;
|
|
14
|
+
constructor(options?: LeaferEChartOptions);
|
|
15
|
+
static renderSVG(option: EChartsOption, width: number, height: number): string;
|
|
16
|
+
updateOption(newOption: EChartsOption): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Mock bar chart (ECharts example) */
|
|
20
|
+
declare const defaultBarChartOption: EChartsOption;
|
|
21
|
+
|
|
22
|
+
export { type LeaferEChartOptions, LeaferECharts, defaultBarChartOption };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
+
if (decorator = decorators[i])
|
|
23
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
+
if (kind && result) __defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/index.ts
|
|
29
|
+
var index_exports = {};
|
|
30
|
+
__export(index_exports, {
|
|
31
|
+
LeaferECharts: () => LeaferECharts_default,
|
|
32
|
+
defaultBarChartOption: () => defaultBarChartOption
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
|
|
36
|
+
// src/LeaferECharts.ts
|
|
37
|
+
var import_leafer_ui = require("leafer-ui");
|
|
38
|
+
var import_echarts = require("echarts");
|
|
39
|
+
var LeaferECharts = class extends import_leafer_ui.Image {
|
|
40
|
+
get __tag() {
|
|
41
|
+
return "LeaferECharts";
|
|
42
|
+
}
|
|
43
|
+
constructor(options = {}) {
|
|
44
|
+
const {
|
|
45
|
+
option = {},
|
|
46
|
+
width = 400,
|
|
47
|
+
height = 400,
|
|
48
|
+
draggable = true,
|
|
49
|
+
editable = false
|
|
50
|
+
} = options;
|
|
51
|
+
const svgString = LeaferECharts.renderSVG(option, width, height);
|
|
52
|
+
const url = import_leafer_ui.Platform.toURL(svgString, "svg");
|
|
53
|
+
super({
|
|
54
|
+
width,
|
|
55
|
+
height,
|
|
56
|
+
draggable,
|
|
57
|
+
editable,
|
|
58
|
+
url
|
|
59
|
+
});
|
|
60
|
+
this.option = option;
|
|
61
|
+
}
|
|
62
|
+
static renderSVG(option, width, height) {
|
|
63
|
+
const chart = (0, import_echarts.init)(null, null, {
|
|
64
|
+
renderer: "svg",
|
|
65
|
+
ssr: true,
|
|
66
|
+
width,
|
|
67
|
+
height
|
|
68
|
+
});
|
|
69
|
+
chart.setOption({
|
|
70
|
+
animation: false,
|
|
71
|
+
animationDuration: 0,
|
|
72
|
+
animationDurationUpdate: 0,
|
|
73
|
+
animationEasing: "linear",
|
|
74
|
+
...option
|
|
75
|
+
});
|
|
76
|
+
const svg = chart.renderToSVGString();
|
|
77
|
+
chart.dispose();
|
|
78
|
+
return svg;
|
|
79
|
+
}
|
|
80
|
+
updateOption(newOption) {
|
|
81
|
+
this.option = newOption;
|
|
82
|
+
const w = this.width ?? 400;
|
|
83
|
+
const h = this.height ?? 400;
|
|
84
|
+
const svgString = LeaferECharts.renderSVG(newOption, w, h);
|
|
85
|
+
this.url = import_leafer_ui.Platform.toURL(svgString, "svg");
|
|
86
|
+
this.forceRender();
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
__decorateClass([
|
|
90
|
+
(0, import_leafer_ui.boundsType)({})
|
|
91
|
+
], LeaferECharts.prototype, "option", 2);
|
|
92
|
+
LeaferECharts = __decorateClass([
|
|
93
|
+
(0, import_leafer_ui.registerUI)()
|
|
94
|
+
], LeaferECharts);
|
|
95
|
+
var LeaferECharts_default = LeaferECharts;
|
|
96
|
+
|
|
97
|
+
// src/mockChartOption.ts
|
|
98
|
+
var defaultBarChartOption = {
|
|
99
|
+
tooltip: {
|
|
100
|
+
trigger: "axis",
|
|
101
|
+
axisPointer: {
|
|
102
|
+
type: "shadow"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
grid: {
|
|
106
|
+
left: "3%",
|
|
107
|
+
right: "4%",
|
|
108
|
+
bottom: "3%",
|
|
109
|
+
containLabel: true
|
|
110
|
+
},
|
|
111
|
+
xAxis: [
|
|
112
|
+
{
|
|
113
|
+
type: "category",
|
|
114
|
+
data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
|
|
115
|
+
axisTick: {
|
|
116
|
+
alignWithLabel: true
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
],
|
|
120
|
+
yAxis: [
|
|
121
|
+
{
|
|
122
|
+
type: "value"
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
series: [
|
|
126
|
+
{
|
|
127
|
+
name: "Direct",
|
|
128
|
+
type: "bar",
|
|
129
|
+
barWidth: "60%",
|
|
130
|
+
data: [10, 52, 200, 334, 390, 330, 220]
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
};
|
|
134
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
135
|
+
0 && (module.exports = {
|
|
136
|
+
LeaferECharts,
|
|
137
|
+
defaultBarChartOption
|
|
138
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/LeaferECharts.ts
|
|
13
|
+
import { Image, Platform, boundsType, registerUI } from "leafer-ui";
|
|
14
|
+
import { init as initEChart } from "echarts";
|
|
15
|
+
var LeaferECharts = class extends Image {
|
|
16
|
+
get __tag() {
|
|
17
|
+
return "LeaferECharts";
|
|
18
|
+
}
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
const {
|
|
21
|
+
option = {},
|
|
22
|
+
width = 400,
|
|
23
|
+
height = 400,
|
|
24
|
+
draggable = true,
|
|
25
|
+
editable = false
|
|
26
|
+
} = options;
|
|
27
|
+
const svgString = LeaferECharts.renderSVG(option, width, height);
|
|
28
|
+
const url = Platform.toURL(svgString, "svg");
|
|
29
|
+
super({
|
|
30
|
+
width,
|
|
31
|
+
height,
|
|
32
|
+
draggable,
|
|
33
|
+
editable,
|
|
34
|
+
url
|
|
35
|
+
});
|
|
36
|
+
this.option = option;
|
|
37
|
+
}
|
|
38
|
+
static renderSVG(option, width, height) {
|
|
39
|
+
const chart = initEChart(null, null, {
|
|
40
|
+
renderer: "svg",
|
|
41
|
+
ssr: true,
|
|
42
|
+
width,
|
|
43
|
+
height
|
|
44
|
+
});
|
|
45
|
+
chart.setOption({
|
|
46
|
+
animation: false,
|
|
47
|
+
animationDuration: 0,
|
|
48
|
+
animationDurationUpdate: 0,
|
|
49
|
+
animationEasing: "linear",
|
|
50
|
+
...option
|
|
51
|
+
});
|
|
52
|
+
const svg = chart.renderToSVGString();
|
|
53
|
+
chart.dispose();
|
|
54
|
+
return svg;
|
|
55
|
+
}
|
|
56
|
+
updateOption(newOption) {
|
|
57
|
+
this.option = newOption;
|
|
58
|
+
const w = this.width ?? 400;
|
|
59
|
+
const h = this.height ?? 400;
|
|
60
|
+
const svgString = LeaferECharts.renderSVG(newOption, w, h);
|
|
61
|
+
this.url = Platform.toURL(svgString, "svg");
|
|
62
|
+
this.forceRender();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
__decorateClass([
|
|
66
|
+
boundsType({})
|
|
67
|
+
], LeaferECharts.prototype, "option", 2);
|
|
68
|
+
LeaferECharts = __decorateClass([
|
|
69
|
+
registerUI()
|
|
70
|
+
], LeaferECharts);
|
|
71
|
+
var LeaferECharts_default = LeaferECharts;
|
|
72
|
+
|
|
73
|
+
// src/mockChartOption.ts
|
|
74
|
+
var defaultBarChartOption = {
|
|
75
|
+
tooltip: {
|
|
76
|
+
trigger: "axis",
|
|
77
|
+
axisPointer: {
|
|
78
|
+
type: "shadow"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
grid: {
|
|
82
|
+
left: "3%",
|
|
83
|
+
right: "4%",
|
|
84
|
+
bottom: "3%",
|
|
85
|
+
containLabel: true
|
|
86
|
+
},
|
|
87
|
+
xAxis: [
|
|
88
|
+
{
|
|
89
|
+
type: "category",
|
|
90
|
+
data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
|
|
91
|
+
axisTick: {
|
|
92
|
+
alignWithLabel: true
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
],
|
|
96
|
+
yAxis: [
|
|
97
|
+
{
|
|
98
|
+
type: "value"
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
series: [
|
|
102
|
+
{
|
|
103
|
+
name: "Direct",
|
|
104
|
+
type: "bar",
|
|
105
|
+
barWidth: "60%",
|
|
106
|
+
data: [10, 52, 200, 334, 390, 330, 220]
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
};
|
|
110
|
+
export {
|
|
111
|
+
LeaferECharts_default as LeaferECharts,
|
|
112
|
+
defaultBarChartOption
|
|
113
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "leafer-echarts",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ECharts component for Leafer UI – render interactive charts as SVG inside Leafer canvas",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
20
|
+
"prepublishOnly": "npm run build"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"echarts": ">=5.0.0 <6.0.0",
|
|
24
|
+
"leafer-ui": ">=2.0.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"echarts": "^5.6.0",
|
|
28
|
+
"leafer-ui": "^2.0.8",
|
|
29
|
+
"tsup": "^8.5.1",
|
|
30
|
+
"typescript": "^5.9.3"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"leafer",
|
|
34
|
+
"leafer-ui",
|
|
35
|
+
"echarts",
|
|
36
|
+
"chart",
|
|
37
|
+
"svg",
|
|
38
|
+
"canvas"
|
|
39
|
+
],
|
|
40
|
+
"author": "Sergei Malygin",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/sedrew/leafer-echarts"
|
|
45
|
+
}
|
|
46
|
+
}
|