@mce/chart 0.24.4
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/index.css +173 -0
- package/dist/index.js +441 -0
- package/package.json +66 -0
package/dist/index.css
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
.m-chart-editor {
|
|
2
|
+
flex: 1;
|
|
3
|
+
min-height: 0;
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
}
|
|
7
|
+
.m-chart-editor__header {
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: 8px;
|
|
11
|
+
padding: 18px 20px;
|
|
12
|
+
font-size: 18px;
|
|
13
|
+
font-weight: 700;
|
|
14
|
+
}
|
|
15
|
+
.m-chart-editor__header svg {
|
|
16
|
+
width: 22px;
|
|
17
|
+
height: 22px;
|
|
18
|
+
}
|
|
19
|
+
.m-chart-editor__title {
|
|
20
|
+
flex: 1;
|
|
21
|
+
}
|
|
22
|
+
.m-chart-editor__close {
|
|
23
|
+
border: none;
|
|
24
|
+
background: none;
|
|
25
|
+
cursor: pointer;
|
|
26
|
+
color: rgba(var(--m-theme-on-surface, 30 30 30), 0.5);
|
|
27
|
+
display: flex;
|
|
28
|
+
padding: 4px;
|
|
29
|
+
border-radius: 6px;
|
|
30
|
+
}
|
|
31
|
+
.m-chart-editor__close:hover {
|
|
32
|
+
background: rgba(var(--m-theme-on-surface, 30 30 30), 0.08);
|
|
33
|
+
}
|
|
34
|
+
.m-chart-editor__close svg {
|
|
35
|
+
width: 20px;
|
|
36
|
+
height: 20px;
|
|
37
|
+
}
|
|
38
|
+
.m-chart-editor__body {
|
|
39
|
+
flex: 1;
|
|
40
|
+
display: flex;
|
|
41
|
+
gap: 24px;
|
|
42
|
+
padding: 0 20px 8px;
|
|
43
|
+
min-height: 0;
|
|
44
|
+
overflow: auto;
|
|
45
|
+
}
|
|
46
|
+
.m-chart-editor__grid-wrap {
|
|
47
|
+
flex: 1;
|
|
48
|
+
overflow: auto;
|
|
49
|
+
border: 1px solid rgba(var(--m-theme-on-surface, 30 30 30), 0.08);
|
|
50
|
+
border-radius: 8px;
|
|
51
|
+
}
|
|
52
|
+
.m-chart-editor__grid {
|
|
53
|
+
border-collapse: collapse;
|
|
54
|
+
width: 100%;
|
|
55
|
+
font-size: 14px;
|
|
56
|
+
}
|
|
57
|
+
.m-chart-editor__grid th, .m-chart-editor__grid td {
|
|
58
|
+
border: 1px solid rgba(var(--m-theme-on-surface, 30 30 30), 0.08);
|
|
59
|
+
text-align: center;
|
|
60
|
+
padding: 0;
|
|
61
|
+
min-width: 96px;
|
|
62
|
+
height: 38px;
|
|
63
|
+
}
|
|
64
|
+
.m-chart-editor__grid thead th {
|
|
65
|
+
background: rgba(var(--m-theme-on-surface, 30 30 30), 0.03);
|
|
66
|
+
font-weight: 600;
|
|
67
|
+
color: rgba(var(--m-theme-on-surface, 30 30 30), 0.55);
|
|
68
|
+
}
|
|
69
|
+
.m-chart-editor__grid__corner {
|
|
70
|
+
min-width: 44px !important;
|
|
71
|
+
width: 44px;
|
|
72
|
+
}
|
|
73
|
+
.m-chart-editor__rownum {
|
|
74
|
+
min-width: 44px !important;
|
|
75
|
+
width: 44px;
|
|
76
|
+
background: rgba(var(--m-theme-on-surface, 30 30 30), 0.03);
|
|
77
|
+
color: rgba(var(--m-theme-on-surface, 30 30 30), 0.55);
|
|
78
|
+
font-weight: 600;
|
|
79
|
+
}
|
|
80
|
+
.m-chart-editor__grid input {
|
|
81
|
+
width: 100%;
|
|
82
|
+
height: 100%;
|
|
83
|
+
border: none;
|
|
84
|
+
outline: none;
|
|
85
|
+
background: none;
|
|
86
|
+
text-align: center;
|
|
87
|
+
font: inherit;
|
|
88
|
+
color: inherit;
|
|
89
|
+
padding: 0 8px;
|
|
90
|
+
box-sizing: border-box;
|
|
91
|
+
}
|
|
92
|
+
.m-chart-editor__grid input:focus {
|
|
93
|
+
box-shadow: inset 0 0 0 2px rgb(var(--m-theme-primary, 30 200 230));
|
|
94
|
+
}
|
|
95
|
+
.m-chart-editor__grid input.is-header {
|
|
96
|
+
font-weight: 600;
|
|
97
|
+
}
|
|
98
|
+
.m-chart-editor__side {
|
|
99
|
+
width: 380px;
|
|
100
|
+
flex-shrink: 0;
|
|
101
|
+
display: flex;
|
|
102
|
+
flex-direction: column;
|
|
103
|
+
gap: 12px;
|
|
104
|
+
padding-top: 4px;
|
|
105
|
+
}
|
|
106
|
+
.m-chart-editor__field {
|
|
107
|
+
display: flex;
|
|
108
|
+
align-items: center;
|
|
109
|
+
gap: 10px;
|
|
110
|
+
border: 1px solid rgba(var(--m-theme-on-surface, 30 30 30), 0.12);
|
|
111
|
+
border-radius: 8px;
|
|
112
|
+
padding: 0 12px;
|
|
113
|
+
height: 44px;
|
|
114
|
+
}
|
|
115
|
+
.m-chart-editor__field > span {
|
|
116
|
+
flex-shrink: 0;
|
|
117
|
+
color: rgba(var(--m-theme-on-surface, 30 30 30), 0.55);
|
|
118
|
+
font-size: 14px;
|
|
119
|
+
}
|
|
120
|
+
.m-chart-editor__field input {
|
|
121
|
+
flex: 1;
|
|
122
|
+
border: none;
|
|
123
|
+
outline: none;
|
|
124
|
+
background: none;
|
|
125
|
+
font: inherit;
|
|
126
|
+
color: inherit;
|
|
127
|
+
height: 100%;
|
|
128
|
+
}
|
|
129
|
+
.m-chart-editor__preview {
|
|
130
|
+
flex: 1;
|
|
131
|
+
min-height: 280px;
|
|
132
|
+
border: 1px solid rgba(var(--m-theme-on-surface, 30 30 30), 0.08);
|
|
133
|
+
border-radius: 8px;
|
|
134
|
+
padding: 8px;
|
|
135
|
+
}
|
|
136
|
+
.m-chart-editor__canvas {
|
|
137
|
+
width: 100%;
|
|
138
|
+
height: 100%;
|
|
139
|
+
min-height: 264px;
|
|
140
|
+
}
|
|
141
|
+
.m-chart-editor__preview-empty {
|
|
142
|
+
display: flex;
|
|
143
|
+
align-items: center;
|
|
144
|
+
justify-content: center;
|
|
145
|
+
height: 100%;
|
|
146
|
+
color: rgba(var(--m-theme-on-surface, 30 30 30), 0.4);
|
|
147
|
+
font-size: 13px;
|
|
148
|
+
}
|
|
149
|
+
.m-chart-editor__footer {
|
|
150
|
+
display: flex;
|
|
151
|
+
justify-content: flex-end;
|
|
152
|
+
gap: 12px;
|
|
153
|
+
padding: 16px 20px;
|
|
154
|
+
}
|
|
155
|
+
.m-chart-editor__btn {
|
|
156
|
+
border: 1px solid rgba(var(--m-theme-on-surface, 30 30 30), 0.15);
|
|
157
|
+
background: rgb(var(--m-theme-surface, 255 255 255));
|
|
158
|
+
color: inherit;
|
|
159
|
+
border-radius: 8px;
|
|
160
|
+
padding: 0 20px;
|
|
161
|
+
height: 40px;
|
|
162
|
+
font-size: 14px;
|
|
163
|
+
cursor: pointer;
|
|
164
|
+
}
|
|
165
|
+
.m-chart-editor__btn:hover {
|
|
166
|
+
background: rgba(var(--m-theme-on-surface, 30 30 30), 0.04);
|
|
167
|
+
}
|
|
168
|
+
.m-chart-editor__btn--primary {
|
|
169
|
+
border: none;
|
|
170
|
+
background: rgb(var(--m-theme-primary, 30 200 230));
|
|
171
|
+
color: rgb(var(--m-theme-on-primary, 255 255 255));
|
|
172
|
+
font-weight: 600;
|
|
173
|
+
}/*$vite$:1*/
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import { Dialog, Icon, definePlugin, useEditor } from "mce";
|
|
2
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, nextTick, normalizeClass, onBeforeUnmount, openBlock, ref, renderList, toDisplayString, unref, vModelText, vShow, watch, withCtx, withDirectives } from "vue";
|
|
3
|
+
//#region src/ChartEditor.vue?vue&type=script&setup=true&lang.ts
|
|
4
|
+
var _hoisted_1 = { class: "m-chart-editor" };
|
|
5
|
+
var _hoisted_2 = { class: "m-chart-editor__header" };
|
|
6
|
+
var _hoisted_3 = { class: "m-chart-editor__body" };
|
|
7
|
+
var _hoisted_4 = { class: "m-chart-editor__grid-wrap" };
|
|
8
|
+
var _hoisted_5 = { class: "m-chart-editor__grid" };
|
|
9
|
+
var _hoisted_6 = { class: "m-chart-editor__rownum" };
|
|
10
|
+
var _hoisted_7 = ["value", "onInput"];
|
|
11
|
+
var _hoisted_8 = { class: "m-chart-editor__side" };
|
|
12
|
+
var _hoisted_9 = { class: "m-chart-editor__field" };
|
|
13
|
+
var _hoisted_10 = { class: "m-chart-editor__field" };
|
|
14
|
+
var _hoisted_11 = { class: "m-chart-editor__field" };
|
|
15
|
+
var _hoisted_12 = { class: "m-chart-editor__preview" };
|
|
16
|
+
var _hoisted_13 = {
|
|
17
|
+
key: 0,
|
|
18
|
+
class: "m-chart-editor__preview-empty"
|
|
19
|
+
};
|
|
20
|
+
var MIN_ROWS = 9;
|
|
21
|
+
var MIN_COLS = 3;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/ChartEditor.vue
|
|
24
|
+
var ChartEditor_default = /* @__PURE__ */ defineComponent({
|
|
25
|
+
__name: "ChartEditor",
|
|
26
|
+
setup(__props) {
|
|
27
|
+
const { state, elementSelection } = useEditor();
|
|
28
|
+
const COL_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
|
|
29
|
+
const el = computed(() => elementSelection.value[0]);
|
|
30
|
+
const active = computed(() => state.value === "chartEditing" && Boolean(el.value?.chart?.isValid?.()));
|
|
31
|
+
const chartType = ref("column");
|
|
32
|
+
const title = ref("");
|
|
33
|
+
const xAxisTitle = ref("");
|
|
34
|
+
const yAxisTitle = ref("");
|
|
35
|
+
const grid = ref([]);
|
|
36
|
+
function emptyGrid(rows = MIN_ROWS, cols = MIN_COLS) {
|
|
37
|
+
return Array.from({ length: rows }, () => Array.from({ length: cols }, () => ""));
|
|
38
|
+
}
|
|
39
|
+
function load() {
|
|
40
|
+
const c = el.value?.chart?.toJSON?.() ?? {};
|
|
41
|
+
chartType.value = c.type ?? "column";
|
|
42
|
+
title.value = c.title ?? "";
|
|
43
|
+
xAxisTitle.value = c.categoryAxis?.title ?? "";
|
|
44
|
+
yAxisTitle.value = c.valueAxis?.title ?? "";
|
|
45
|
+
const cats = c.categories ?? [];
|
|
46
|
+
const series = c.series ?? [];
|
|
47
|
+
const g = emptyGrid(Math.max(cats.length + 2, MIN_ROWS), Math.max(series.length + 2, MIN_COLS));
|
|
48
|
+
g[0][0] = "类别";
|
|
49
|
+
series.forEach((s, i) => {
|
|
50
|
+
g[0][i + 1] = s.name ?? `系列 ${i + 1}`;
|
|
51
|
+
});
|
|
52
|
+
cats.forEach((cat, r) => {
|
|
53
|
+
g[r + 1][0] = String(cat);
|
|
54
|
+
});
|
|
55
|
+
series.forEach((s, ci) => {
|
|
56
|
+
(s.values ?? []).forEach((v, r) => {
|
|
57
|
+
g[r + 1][ci + 1] = String(v);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
grid.value = g;
|
|
61
|
+
}
|
|
62
|
+
watch(active, (on) => {
|
|
63
|
+
if (on) {
|
|
64
|
+
load();
|
|
65
|
+
nextTick(renderPreview);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
function ensureSpare() {
|
|
69
|
+
const g = grid.value;
|
|
70
|
+
if (g.some((row) => row[row.length - 1].trim() !== "")) g.forEach((row) => row.push(""));
|
|
71
|
+
if (g[g.length - 1].some((c) => c.trim() !== "")) g.push(Array.from({ length: g[0].length }, () => ""));
|
|
72
|
+
}
|
|
73
|
+
function onCell(r, c, value) {
|
|
74
|
+
grid.value[r][c] = value;
|
|
75
|
+
ensureSpare();
|
|
76
|
+
renderPreview();
|
|
77
|
+
}
|
|
78
|
+
function clearData() {
|
|
79
|
+
const g = grid.value;
|
|
80
|
+
for (let r = 1; r < g.length; r++) for (let c = 0; c < g[r].length; c++) g[r][c] = "";
|
|
81
|
+
renderPreview();
|
|
82
|
+
}
|
|
83
|
+
function close() {
|
|
84
|
+
state.value = void 0;
|
|
85
|
+
}
|
|
86
|
+
function parseGrid() {
|
|
87
|
+
const g = grid.value;
|
|
88
|
+
const categories = [];
|
|
89
|
+
const rowIdx = [];
|
|
90
|
+
for (let r = 1; r < g.length; r++) {
|
|
91
|
+
const v = (g[r][0] ?? "").trim();
|
|
92
|
+
if (v) {
|
|
93
|
+
categories.push(v);
|
|
94
|
+
rowIdx.push(r);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const series = [];
|
|
98
|
+
for (let c = 1; c < g[0].length; c++) {
|
|
99
|
+
const name = (g[0][c] ?? "").trim();
|
|
100
|
+
const values = rowIdx.map((r) => {
|
|
101
|
+
const n = Number((g[r][c] ?? "").trim());
|
|
102
|
+
return Number.isFinite(n) ? n : 0;
|
|
103
|
+
});
|
|
104
|
+
if (name || values.some((v) => v !== 0)) series.push({
|
|
105
|
+
name: name || `系列 ${c}`,
|
|
106
|
+
values
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
categories,
|
|
111
|
+
series
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function apply() {
|
|
115
|
+
const node = el.value;
|
|
116
|
+
if (!node) return;
|
|
117
|
+
const { categories, series } = parseGrid();
|
|
118
|
+
const base = node.chart?.toJSON?.() ?? {};
|
|
119
|
+
node.chart = {
|
|
120
|
+
...base,
|
|
121
|
+
type: chartType.value,
|
|
122
|
+
categories,
|
|
123
|
+
series,
|
|
124
|
+
title: title.value || void 0,
|
|
125
|
+
categoryAxis: {
|
|
126
|
+
...base.categoryAxis,
|
|
127
|
+
title: xAxisTitle.value || void 0
|
|
128
|
+
},
|
|
129
|
+
valueAxis: {
|
|
130
|
+
...base.valueAxis,
|
|
131
|
+
title: yAxisTitle.value || void 0
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
node.requestDraw?.();
|
|
135
|
+
close();
|
|
136
|
+
}
|
|
137
|
+
const previewEl = ref();
|
|
138
|
+
const previewError = ref(false);
|
|
139
|
+
let echartsLib;
|
|
140
|
+
let chartInstance;
|
|
141
|
+
function buildOption() {
|
|
142
|
+
const { categories, series } = parseGrid();
|
|
143
|
+
const t = chartType.value;
|
|
144
|
+
if (t === "pie" || t === "doughnut") return {
|
|
145
|
+
title: {
|
|
146
|
+
text: title.value,
|
|
147
|
+
textStyle: { fontSize: 13 }
|
|
148
|
+
},
|
|
149
|
+
tooltip: { trigger: "item" },
|
|
150
|
+
series: [{
|
|
151
|
+
type: "pie",
|
|
152
|
+
radius: t === "doughnut" ? ["40%", "70%"] : "70%",
|
|
153
|
+
data: categories.map((c, i) => ({
|
|
154
|
+
name: c,
|
|
155
|
+
value: series[0]?.values[i] ?? 0
|
|
156
|
+
}))
|
|
157
|
+
}]
|
|
158
|
+
};
|
|
159
|
+
const horizontal = t === "bar";
|
|
160
|
+
const isArea = t === "area";
|
|
161
|
+
const etype = t === "line" || isArea ? "line" : "bar";
|
|
162
|
+
const catAxis = {
|
|
163
|
+
type: "category",
|
|
164
|
+
data: categories,
|
|
165
|
+
name: xAxisTitle.value || void 0
|
|
166
|
+
};
|
|
167
|
+
const valAxis = {
|
|
168
|
+
type: "value",
|
|
169
|
+
name: yAxisTitle.value || void 0
|
|
170
|
+
};
|
|
171
|
+
return {
|
|
172
|
+
title: {
|
|
173
|
+
text: title.value,
|
|
174
|
+
textStyle: { fontSize: 13 }
|
|
175
|
+
},
|
|
176
|
+
tooltip: { trigger: "axis" },
|
|
177
|
+
legend: series.length > 1 ? { bottom: 0 } : void 0,
|
|
178
|
+
grid: {
|
|
179
|
+
left: 48,
|
|
180
|
+
right: 16,
|
|
181
|
+
top: 36,
|
|
182
|
+
bottom: 32
|
|
183
|
+
},
|
|
184
|
+
xAxis: horizontal ? valAxis : catAxis,
|
|
185
|
+
yAxis: horizontal ? catAxis : valAxis,
|
|
186
|
+
series: series.map((s) => ({
|
|
187
|
+
name: s.name,
|
|
188
|
+
type: etype,
|
|
189
|
+
data: s.values,
|
|
190
|
+
areaStyle: isArea ? {} : void 0
|
|
191
|
+
}))
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
async function renderPreview() {
|
|
195
|
+
if (!active.value || !previewEl.value) return;
|
|
196
|
+
try {
|
|
197
|
+
if (!echartsLib) echartsLib = await import("echarts");
|
|
198
|
+
if (!chartInstance) chartInstance = echartsLib.init(previewEl.value);
|
|
199
|
+
chartInstance.setOption(buildOption(), true);
|
|
200
|
+
previewError.value = false;
|
|
201
|
+
} catch {
|
|
202
|
+
previewError.value = true;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
watch([
|
|
206
|
+
title,
|
|
207
|
+
xAxisTitle,
|
|
208
|
+
yAxisTitle,
|
|
209
|
+
chartType
|
|
210
|
+
], renderPreview);
|
|
211
|
+
function disposePreview() {
|
|
212
|
+
chartInstance?.dispose?.();
|
|
213
|
+
chartInstance = void 0;
|
|
214
|
+
}
|
|
215
|
+
watch(active, (on) => {
|
|
216
|
+
if (!on) disposePreview();
|
|
217
|
+
});
|
|
218
|
+
onBeforeUnmount(disposePreview);
|
|
219
|
+
return (_ctx, _cache) => {
|
|
220
|
+
return openBlock(), createBlock(unref(Dialog), {
|
|
221
|
+
"model-value": active.value,
|
|
222
|
+
width: "min(1040px, 92vw)",
|
|
223
|
+
"onUpdate:modelValue": _cache[3] || (_cache[3] = (v) => {
|
|
224
|
+
if (!v) close();
|
|
225
|
+
})
|
|
226
|
+
}, {
|
|
227
|
+
default: withCtx(() => [createElementVNode("div", _hoisted_1, [
|
|
228
|
+
createElementVNode("header", _hoisted_2, [
|
|
229
|
+
createVNode(unref(Icon), { icon: "$chartBar" }),
|
|
230
|
+
_cache[4] || (_cache[4] = createElementVNode("span", { class: "m-chart-editor__title" }, "图表数据", -1)),
|
|
231
|
+
createElementVNode("button", {
|
|
232
|
+
class: "m-chart-editor__close",
|
|
233
|
+
type: "button",
|
|
234
|
+
onClick: close
|
|
235
|
+
}, [createVNode(unref(Icon), { icon: "$close" })])
|
|
236
|
+
]),
|
|
237
|
+
createElementVNode("div", _hoisted_3, [createElementVNode("div", _hoisted_4, [createElementVNode("table", _hoisted_5, [createElementVNode("thead", null, [createElementVNode("tr", null, [_cache[5] || (_cache[5] = createElementVNode("th", { class: "m-chart-editor__corner" }, null, -1)), (openBlock(true), createElementBlock(Fragment, null, renderList(grid.value[0], (_, c) => {
|
|
238
|
+
return openBlock(), createElementBlock("th", { key: c }, toDisplayString(unref(COL_LETTERS)[c]), 1);
|
|
239
|
+
}), 128))])]), createElementVNode("tbody", null, [(openBlock(true), createElementBlock(Fragment, null, renderList(grid.value, (row, r) => {
|
|
240
|
+
return openBlock(), createElementBlock("tr", { key: r }, [createElementVNode("td", _hoisted_6, toDisplayString(r + 1), 1), (openBlock(true), createElementBlock(Fragment, null, renderList(row, (cell, c) => {
|
|
241
|
+
return openBlock(), createElementBlock("td", { key: c }, [createElementVNode("input", {
|
|
242
|
+
value: cell,
|
|
243
|
+
class: normalizeClass({ "is-header": r === 0 }),
|
|
244
|
+
onInput: ($event) => onCell(r, c, $event.target.value)
|
|
245
|
+
}, null, 42, _hoisted_7)]);
|
|
246
|
+
}), 128))]);
|
|
247
|
+
}), 128))])])]), createElementVNode("div", _hoisted_8, [
|
|
248
|
+
createElementVNode("label", _hoisted_9, [_cache[6] || (_cache[6] = createElementVNode("span", null, "主标题", -1)), withDirectives(createElementVNode("input", {
|
|
249
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => title.value = $event),
|
|
250
|
+
placeholder: "请输入主标题"
|
|
251
|
+
}, null, 512), [[vModelText, title.value]])]),
|
|
252
|
+
createElementVNode("label", _hoisted_10, [_cache[7] || (_cache[7] = createElementVNode("span", null, "X轴标题", -1)), withDirectives(createElementVNode("input", {
|
|
253
|
+
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => xAxisTitle.value = $event),
|
|
254
|
+
placeholder: "请输入X轴标题"
|
|
255
|
+
}, null, 512), [[vModelText, xAxisTitle.value]])]),
|
|
256
|
+
createElementVNode("label", _hoisted_11, [_cache[8] || (_cache[8] = createElementVNode("span", null, "Y轴标题", -1)), withDirectives(createElementVNode("input", {
|
|
257
|
+
"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => yAxisTitle.value = $event),
|
|
258
|
+
placeholder: "请输入Y轴标题"
|
|
259
|
+
}, null, 512), [[vModelText, yAxisTitle.value]])]),
|
|
260
|
+
createElementVNode("div", _hoisted_12, [withDirectives(createElementVNode("div", {
|
|
261
|
+
ref_key: "previewEl",
|
|
262
|
+
ref: previewEl,
|
|
263
|
+
class: "m-chart-editor__canvas"
|
|
264
|
+
}, null, 512), [[vShow, !previewError.value]]), previewError.value ? (openBlock(), createElementBlock("div", _hoisted_13, " 预览不可用(未安装 echarts) ")) : createCommentVNode("", true)])
|
|
265
|
+
])]),
|
|
266
|
+
createElementVNode("footer", { class: "m-chart-editor__footer" }, [createElementVNode("button", {
|
|
267
|
+
class: "m-chart-editor__btn",
|
|
268
|
+
type: "button",
|
|
269
|
+
onClick: clearData
|
|
270
|
+
}, " 清空数据 "), createElementVNode("button", {
|
|
271
|
+
class: "m-chart-editor__btn m-chart-editor__btn--primary",
|
|
272
|
+
type: "button",
|
|
273
|
+
onClick: apply
|
|
274
|
+
}, " 确认修改 ")])
|
|
275
|
+
])]),
|
|
276
|
+
_: 1
|
|
277
|
+
}, 8, ["model-value"]);
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/create.ts
|
|
283
|
+
/** A chart backed by the native `chart` element property (column/line/pie/…). */
|
|
284
|
+
function createChartElement(type = "column", options = {}) {
|
|
285
|
+
const { width = 360, height = 240, categories = [
|
|
286
|
+
"一月",
|
|
287
|
+
"二月",
|
|
288
|
+
"三月",
|
|
289
|
+
"四月",
|
|
290
|
+
"五月"
|
|
291
|
+
], series = [{
|
|
292
|
+
name: "系列 1",
|
|
293
|
+
values: [
|
|
294
|
+
40,
|
|
295
|
+
70,
|
|
296
|
+
55,
|
|
297
|
+
90,
|
|
298
|
+
60
|
|
299
|
+
]
|
|
300
|
+
}] } = options;
|
|
301
|
+
return {
|
|
302
|
+
style: {
|
|
303
|
+
width,
|
|
304
|
+
height
|
|
305
|
+
},
|
|
306
|
+
chart: {
|
|
307
|
+
type,
|
|
308
|
+
categories,
|
|
309
|
+
series,
|
|
310
|
+
legend: "bottom"
|
|
311
|
+
},
|
|
312
|
+
meta: {
|
|
313
|
+
inPptIs: "Shape",
|
|
314
|
+
inCanvasIs: "Element2D",
|
|
315
|
+
inEditorIs: "Chart"
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/plugin.ts
|
|
321
|
+
function plugin() {
|
|
322
|
+
return definePlugin((editor) => {
|
|
323
|
+
const { elementSelection, addElement, activateTool, registerToolbeltShapeItem, registerIcon, registerEnterHandler, registerEditingState } = editor;
|
|
324
|
+
registerIcon("chartBar", "M22,21H2V3H4V19H6V10H10V19H12V6H16V19H18V14H22V21Z");
|
|
325
|
+
registerIcon("chartLine", "M3.5,18.49L9.5,12.48L13.5,16.48L22,6.92L20.59,5.51L13.5,13.47L9.5,9.47L2,16.99L3.5,18.49Z");
|
|
326
|
+
registerIcon("chartPie", "M11,2V22C5.9,21.5 2,17.2 2,12C2,6.8 5.9,2.5 11,2M13,2V11H22C21.5,6.2 17.8,2.5 13,2M13,13V22C17.7,21.5 21.5,17.8 22,13H13Z");
|
|
327
|
+
registerToolbeltShapeItem("chartBar");
|
|
328
|
+
registerToolbeltShapeItem("chartLine");
|
|
329
|
+
registerToolbeltShapeItem("chartPie");
|
|
330
|
+
registerEnterHandler((el, ed) => {
|
|
331
|
+
if (el.chart?.isValid?.()) {
|
|
332
|
+
ed.state.value = "chartEditing";
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
return false;
|
|
336
|
+
});
|
|
337
|
+
registerEditingState("chartEditing");
|
|
338
|
+
function getChart(node) {
|
|
339
|
+
const el = node ?? elementSelection.value[0];
|
|
340
|
+
return el?.chart?.toJSON?.() ?? el?.chart;
|
|
341
|
+
}
|
|
342
|
+
function patch(patchData, node) {
|
|
343
|
+
const el = node ?? elementSelection.value[0];
|
|
344
|
+
if (!el?.chart) return;
|
|
345
|
+
el.chart = {
|
|
346
|
+
...el.chart.toJSON?.() ?? {},
|
|
347
|
+
...patchData
|
|
348
|
+
};
|
|
349
|
+
el.requestDraw?.();
|
|
350
|
+
}
|
|
351
|
+
function setChartType(type, node) {
|
|
352
|
+
patch({ type }, node);
|
|
353
|
+
}
|
|
354
|
+
function setChartData(data, node) {
|
|
355
|
+
const next = {};
|
|
356
|
+
if (data.categories !== void 0) next.categories = data.categories;
|
|
357
|
+
if (data.series !== void 0) next.series = data.series;
|
|
358
|
+
patch(next, node);
|
|
359
|
+
}
|
|
360
|
+
function setChartOptions(options, node) {
|
|
361
|
+
const next = {};
|
|
362
|
+
if (options.legend !== void 0) next.legend = options.legend;
|
|
363
|
+
if (options.title !== void 0) next.title = options.title;
|
|
364
|
+
patch(next, node);
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
name: "mce:chart",
|
|
368
|
+
commands: [
|
|
369
|
+
{
|
|
370
|
+
command: "getChart",
|
|
371
|
+
handle: getChart
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
command: "setChartType",
|
|
375
|
+
handle: setChartType
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
command: "setChartData",
|
|
379
|
+
handle: setChartData
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
command: "setChartOptions",
|
|
383
|
+
handle: setChartOptions
|
|
384
|
+
}
|
|
385
|
+
],
|
|
386
|
+
tools: [
|
|
387
|
+
{
|
|
388
|
+
name: "chartBar",
|
|
389
|
+
handle: (start) => {
|
|
390
|
+
addElement(createChartElement("column"), {
|
|
391
|
+
position: start,
|
|
392
|
+
active: true
|
|
393
|
+
});
|
|
394
|
+
return { end: () => activateTool(void 0) };
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
name: "chartLine",
|
|
399
|
+
handle: (start) => {
|
|
400
|
+
addElement(createChartElement("line"), {
|
|
401
|
+
position: start,
|
|
402
|
+
active: true
|
|
403
|
+
});
|
|
404
|
+
return { end: () => activateTool(void 0) };
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
name: "chartPie",
|
|
409
|
+
handle: (start) => {
|
|
410
|
+
addElement(createChartElement("pie"), {
|
|
411
|
+
position: start,
|
|
412
|
+
active: true
|
|
413
|
+
});
|
|
414
|
+
return { end: () => activateTool(void 0) };
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
],
|
|
418
|
+
components: [{
|
|
419
|
+
type: "overlay",
|
|
420
|
+
component: ChartEditor_default
|
|
421
|
+
}],
|
|
422
|
+
messages: {
|
|
423
|
+
en: {
|
|
424
|
+
chartBar: "Bar Chart",
|
|
425
|
+
chartLine: "Line Chart",
|
|
426
|
+
chartPie: "Pie Chart"
|
|
427
|
+
},
|
|
428
|
+
zhHans: {
|
|
429
|
+
chartBar: "柱状图",
|
|
430
|
+
chartLine: "折线图",
|
|
431
|
+
chartPie: "饼图"
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
//#endregion
|
|
438
|
+
//#region src/index.ts
|
|
439
|
+
var src_default = plugin;
|
|
440
|
+
//#endregion
|
|
441
|
+
export { createChartElement, src_default as default, plugin };
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mce/chart",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.24.4",
|
|
5
|
+
"description": "Chart plugin for mce",
|
|
6
|
+
"author": "wxm",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/qq15725/mce",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/qq15725/mce.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/qq15725/mce/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"mce",
|
|
18
|
+
"chart",
|
|
19
|
+
"plugin"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": true,
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"require": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./*.mjs": "./*.js",
|
|
29
|
+
"./*": "./*"
|
|
30
|
+
},
|
|
31
|
+
"main": "./dist/index.js",
|
|
32
|
+
"module": "./dist/index.js",
|
|
33
|
+
"browser": "./dist/index.js",
|
|
34
|
+
"typings": "dist/index.d.ts",
|
|
35
|
+
"types": "dist/index.d.ts",
|
|
36
|
+
"typesVersions": {
|
|
37
|
+
"*": {
|
|
38
|
+
"*": [
|
|
39
|
+
"*",
|
|
40
|
+
"dist/*",
|
|
41
|
+
"dist/*.d.ts"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"files": [
|
|
46
|
+
"dist"
|
|
47
|
+
],
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"echarts": "^6.1.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@vitejs/plugin-vue": "^6.0.7",
|
|
53
|
+
"mce": "0.24.4"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"mce": "^0",
|
|
57
|
+
"vue": "^3.5.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build:code": "vite build",
|
|
61
|
+
"build:tsc": "NODE_ENV=production vue-tsc --emitDeclarationOnly --project tsconfig.json",
|
|
62
|
+
"build": "pnpm build:code && pnpm build:tsc",
|
|
63
|
+
"lint": "eslint src",
|
|
64
|
+
"typecheck": "vue-tsc --noEmit --project tsconfig.json"
|
|
65
|
+
}
|
|
66
|
+
}
|