create-yoya-ui 0.2.0 → 0.2.1
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
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { svg, vCard, vChart } from '@yoyaflow/yoya-ui';
|
|
2
|
-
|
|
3
|
-
/* global document */
|
|
1
|
+
import { div, svg, vCard, vChart } from '@yoyaflow/yoya-ui';
|
|
4
2
|
|
|
5
3
|
const VIEW_BOX = { height: 260, width: 640 };
|
|
6
4
|
const PAD = { bottom: 34, left: 44, right: 16, top: 14 };
|
|
@@ -52,28 +50,37 @@ function createSvgAdapter() {
|
|
|
52
50
|
function renderChart(instance, context) {
|
|
53
51
|
const root = buildChartSvg(context.data, context.options);
|
|
54
52
|
const legend = buildLegend(context.data?.series ?? []);
|
|
55
|
-
instance.host.replaceChildren(legend, root.renderDom());
|
|
53
|
+
instance.host.replaceChildren(legend.renderDom(), root.renderDom());
|
|
56
54
|
}
|
|
57
55
|
|
|
58
56
|
function buildLegend(series) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
57
|
+
return div((legend) => {
|
|
58
|
+
legend.style({
|
|
59
|
+
color: 'var(--yoya-color-text-muted, #64748b)',
|
|
60
|
+
display: 'flex',
|
|
61
|
+
flexWrap: 'wrap',
|
|
62
|
+
fontSize: '12px',
|
|
63
|
+
gap: '14px',
|
|
64
|
+
marginBottom: '8px'
|
|
65
|
+
});
|
|
66
|
+
series.forEach((entry, index) => {
|
|
67
|
+
const color = entry.color ?? SERIES_COLORS[index % SERIES_COLORS.length];
|
|
68
|
+
legend.span((item) => {
|
|
69
|
+
item.style({ alignItems: 'center', display: 'inline-flex' });
|
|
70
|
+
item.span((dot) => {
|
|
71
|
+
dot.style({
|
|
72
|
+
background: color,
|
|
73
|
+
borderRadius: '2px',
|
|
74
|
+
display: 'inline-block',
|
|
75
|
+
height: '8px',
|
|
76
|
+
marginRight: '5px',
|
|
77
|
+
width: '8px'
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
item.span((text) => text.child(entry.name ?? `系列 ${index + 1}`));
|
|
81
|
+
});
|
|
82
|
+
});
|
|
75
83
|
});
|
|
76
|
-
return legend;
|
|
77
84
|
}
|
|
78
85
|
|
|
79
86
|
function buildChartSvg(data, options) {
|