@sentropic/design-system-vue 0.36.36 → 0.36.39
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/DecompositionTreeChart.d.ts +81 -0
- package/dist/DecompositionTreeChart.d.ts.map +1 -0
- package/dist/DecompositionTreeChart.js +206 -0
- package/dist/DecompositionTreeChart.js.map +1 -0
- package/dist/Density2DChart.d.ts +85 -0
- package/dist/Density2DChart.d.ts.map +1 -0
- package/dist/Density2DChart.js +254 -0
- package/dist/Density2DChart.js.map +1 -0
- package/dist/EventFeedPanel.d.ts +70 -0
- package/dist/EventFeedPanel.d.ts.map +1 -0
- package/dist/EventFeedPanel.js +73 -0
- package/dist/EventFeedPanel.js.map +1 -0
- package/dist/FlamegraphChart.d.ts +73 -0
- package/dist/FlamegraphChart.d.ts.map +1 -0
- package/dist/FlamegraphChart.js +146 -0
- package/dist/FlamegraphChart.js.map +1 -0
- package/dist/TraceWaterfallChart.d.ts +88 -0
- package/dist/TraceWaterfallChart.d.ts.map +1 -0
- package/dist/TraceWaterfallChart.js +278 -0
- package/dist/TraceWaterfallChart.js.map +1 -0
- package/dist/VectorFieldChart.d.ts +78 -0
- package/dist/VectorFieldChart.d.ts.map +1 -0
- package/dist/VectorFieldChart.js +159 -0
- package/dist/VectorFieldChart.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/styles.css +585 -0
- package/package.json +1 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export type DecompositionTreeNode = {
|
|
2
|
+
label: string;
|
|
3
|
+
value: number;
|
|
4
|
+
parent?: string;
|
|
5
|
+
};
|
|
6
|
+
export type DecompositionTreeLevel = {
|
|
7
|
+
dimension: string;
|
|
8
|
+
nodes: DecompositionTreeNode[];
|
|
9
|
+
};
|
|
10
|
+
export type DecompositionTreeData = {
|
|
11
|
+
measure: string;
|
|
12
|
+
levels: DecompositionTreeLevel[];
|
|
13
|
+
};
|
|
14
|
+
export type DecompositionTreeChartProps = {
|
|
15
|
+
data: DecompositionTreeData;
|
|
16
|
+
label?: string;
|
|
17
|
+
width?: number;
|
|
18
|
+
height?: number;
|
|
19
|
+
size?: number;
|
|
20
|
+
class?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const DecompositionTreeChart: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
23
|
+
data: {
|
|
24
|
+
type: () => DecompositionTreeData;
|
|
25
|
+
required: true;
|
|
26
|
+
};
|
|
27
|
+
label: {
|
|
28
|
+
type: StringConstructor;
|
|
29
|
+
default: undefined;
|
|
30
|
+
};
|
|
31
|
+
width: {
|
|
32
|
+
type: NumberConstructor;
|
|
33
|
+
default: undefined;
|
|
34
|
+
};
|
|
35
|
+
height: {
|
|
36
|
+
type: NumberConstructor;
|
|
37
|
+
default: number;
|
|
38
|
+
};
|
|
39
|
+
size: {
|
|
40
|
+
type: NumberConstructor;
|
|
41
|
+
default: undefined;
|
|
42
|
+
};
|
|
43
|
+
class: {
|
|
44
|
+
type: StringConstructor;
|
|
45
|
+
default: undefined;
|
|
46
|
+
};
|
|
47
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
50
|
+
data: {
|
|
51
|
+
type: () => DecompositionTreeData;
|
|
52
|
+
required: true;
|
|
53
|
+
};
|
|
54
|
+
label: {
|
|
55
|
+
type: StringConstructor;
|
|
56
|
+
default: undefined;
|
|
57
|
+
};
|
|
58
|
+
width: {
|
|
59
|
+
type: NumberConstructor;
|
|
60
|
+
default: undefined;
|
|
61
|
+
};
|
|
62
|
+
height: {
|
|
63
|
+
type: NumberConstructor;
|
|
64
|
+
default: number;
|
|
65
|
+
};
|
|
66
|
+
size: {
|
|
67
|
+
type: NumberConstructor;
|
|
68
|
+
default: undefined;
|
|
69
|
+
};
|
|
70
|
+
class: {
|
|
71
|
+
type: StringConstructor;
|
|
72
|
+
default: undefined;
|
|
73
|
+
};
|
|
74
|
+
}>> & Readonly<{}>, {
|
|
75
|
+
size: number;
|
|
76
|
+
class: string;
|
|
77
|
+
label: string;
|
|
78
|
+
height: number;
|
|
79
|
+
width: number;
|
|
80
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
81
|
+
//# sourceMappingURL=DecompositionTreeChart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecompositionTreeChart.d.ts","sourceRoot":"","sources":["../src/DecompositionTreeChart.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,qBAAqB,EAAE,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,sBAAsB,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,qBAAqB,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAuDF,eAAO,MAAM,sBAAsB;;cAGP,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;cAA3B,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4EAiPrD,CAAC"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { defineComponent, h, ref } from "vue";
|
|
2
|
+
import { classNames } from "./classNames.js";
|
|
3
|
+
import { chartDataList } from "./chartScale.js";
|
|
4
|
+
const MARGIN = { top: 16, right: 16, bottom: 16, left: 16 };
|
|
5
|
+
const BAR_H = 22;
|
|
6
|
+
const BAR_GAP = 10;
|
|
7
|
+
const COL_GAP = 36;
|
|
8
|
+
const BAR_W = 110;
|
|
9
|
+
const toneForLevel = (level) => `category${(level % 8) + 1}`;
|
|
10
|
+
// Truncate a label to the bar width (approx. by char count).
|
|
11
|
+
function ellipsize(text, maxChars) {
|
|
12
|
+
if (text.length <= maxChars)
|
|
13
|
+
return text;
|
|
14
|
+
if (maxChars <= 1)
|
|
15
|
+
return "…";
|
|
16
|
+
return `${text.slice(0, maxChars - 1)}…`;
|
|
17
|
+
}
|
|
18
|
+
function formatValue(v) {
|
|
19
|
+
if (Math.abs(v) >= 1000)
|
|
20
|
+
return `${(v / 1000).toFixed(v % 1000 === 0 ? 0 : 1)}k`;
|
|
21
|
+
if (Number.isInteger(v))
|
|
22
|
+
return String(v);
|
|
23
|
+
return v.toFixed(1);
|
|
24
|
+
}
|
|
25
|
+
const charsFor = (w) => Math.max(0, Math.floor((w - 8) / 6.6));
|
|
26
|
+
function linkPath(link) {
|
|
27
|
+
const x1 = link.from.x + link.from.barWidth;
|
|
28
|
+
const y1 = link.from.cy;
|
|
29
|
+
const x2 = link.to.x;
|
|
30
|
+
const y2 = link.to.cy;
|
|
31
|
+
const mid = (x1 + x2) / 2;
|
|
32
|
+
return `M ${x1} ${y1} C ${mid} ${y1}, ${mid} ${y2}, ${x2} ${y2}`;
|
|
33
|
+
}
|
|
34
|
+
export const DecompositionTreeChart = defineComponent({
|
|
35
|
+
name: "DecompositionTreeChart",
|
|
36
|
+
props: {
|
|
37
|
+
data: { type: Object, required: true },
|
|
38
|
+
label: { type: String, default: undefined },
|
|
39
|
+
width: { type: Number, default: undefined },
|
|
40
|
+
height: { type: Number, default: 320 },
|
|
41
|
+
size: { type: Number, default: undefined },
|
|
42
|
+
class: { type: String, default: undefined },
|
|
43
|
+
},
|
|
44
|
+
setup(props, { attrs }) {
|
|
45
|
+
const hoveredKey = ref(null);
|
|
46
|
+
function handleLeave() {
|
|
47
|
+
hoveredKey.value = null;
|
|
48
|
+
}
|
|
49
|
+
function handlePointerMove(event) {
|
|
50
|
+
const target = event.target;
|
|
51
|
+
if (!(target instanceof Element)) {
|
|
52
|
+
hoveredKey.value = null;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
hoveredKey.value = target.getAttribute("data-chart-key");
|
|
56
|
+
}
|
|
57
|
+
return () => {
|
|
58
|
+
const data = props.data;
|
|
59
|
+
const label = props.label;
|
|
60
|
+
const height = props.height ?? 320;
|
|
61
|
+
const resolvedWidth = props.width ?? props.size ?? 640;
|
|
62
|
+
const colX = (level) => MARGIN.left + level * (BAR_W + COL_GAP);
|
|
63
|
+
// Build the columns: root (column 0 = total measure), then one column per
|
|
64
|
+
// level; a bar width is ∝ value relative to its level max.
|
|
65
|
+
const cells = [];
|
|
66
|
+
const links = [];
|
|
67
|
+
if (data && typeof data.measure === "string") {
|
|
68
|
+
const plotTop = MARGIN.top;
|
|
69
|
+
const levels = (data.levels ?? []).filter((lvl) => lvl && typeof lvl.dimension === "string");
|
|
70
|
+
const firstLevelTotal = levels[0]
|
|
71
|
+
? levels[0].nodes
|
|
72
|
+
.filter((n) => n && Number.isFinite(n.value))
|
|
73
|
+
.reduce((s, n) => s + Math.max(n.value, 0), 0)
|
|
74
|
+
: 0;
|
|
75
|
+
const rootValue = firstLevelTotal > 0 ? firstLevelTotal : 1;
|
|
76
|
+
const rootCell = {
|
|
77
|
+
key: "root",
|
|
78
|
+
label: data.measure,
|
|
79
|
+
dimension: data.measure,
|
|
80
|
+
value: rootValue,
|
|
81
|
+
level: 0,
|
|
82
|
+
x: colX(0),
|
|
83
|
+
y: plotTop,
|
|
84
|
+
barWidth: BAR_W,
|
|
85
|
+
tone: toneForLevel(0),
|
|
86
|
+
cx: colX(0) + BAR_W / 2,
|
|
87
|
+
cy: plotTop + BAR_H / 2,
|
|
88
|
+
parentKey: null,
|
|
89
|
+
};
|
|
90
|
+
cells.push(rootCell);
|
|
91
|
+
let prevColumn = [rootCell];
|
|
92
|
+
levels.forEach((lvl, li) => {
|
|
93
|
+
const level = li + 1;
|
|
94
|
+
const nodes = (lvl.nodes ?? []).filter((n) => n && typeof n.label === "string" && Number.isFinite(n.value));
|
|
95
|
+
const levelMax = nodes.reduce((m, n) => Math.max(m, Math.max(n.value, 0)), 0) || 1;
|
|
96
|
+
const x = colX(level);
|
|
97
|
+
const column = [];
|
|
98
|
+
nodes.forEach((n, ni) => {
|
|
99
|
+
const y = plotTop + ni * (BAR_H + BAR_GAP);
|
|
100
|
+
const barWidth = Math.max((Math.max(n.value, 0) / levelMax) * BAR_W, 2);
|
|
101
|
+
const parentCell = (n.parent !== undefined && prevColumn.find((p) => p.label === n.parent)) ||
|
|
102
|
+
prevColumn[0] ||
|
|
103
|
+
null;
|
|
104
|
+
const cell = {
|
|
105
|
+
key: `${level}-${ni}`,
|
|
106
|
+
label: n.label,
|
|
107
|
+
dimension: lvl.dimension,
|
|
108
|
+
value: n.value,
|
|
109
|
+
level,
|
|
110
|
+
x,
|
|
111
|
+
y,
|
|
112
|
+
barWidth,
|
|
113
|
+
tone: toneForLevel(level),
|
|
114
|
+
cx: x + barWidth / 2,
|
|
115
|
+
cy: y + BAR_H / 2,
|
|
116
|
+
parentKey: parentCell ? parentCell.key : null,
|
|
117
|
+
};
|
|
118
|
+
cells.push(cell);
|
|
119
|
+
column.push(cell);
|
|
120
|
+
if (parentCell) {
|
|
121
|
+
links.push({ key: `${parentCell.key}>${cell.key}`, from: parentCell, to: cell });
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
if (column.length > 0)
|
|
125
|
+
prevColumn = column;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const computedHeight = cells.length === 0
|
|
129
|
+
? height
|
|
130
|
+
: Math.max(height, cells.reduce((m, c) => Math.max(m, c.y + BAR_H), MARGIN.top) + MARGIN.bottom);
|
|
131
|
+
const computedWidth = cells.length === 0
|
|
132
|
+
? resolvedWidth
|
|
133
|
+
: Math.max(resolvedWidth, cells.reduce((m, c) => Math.max(m, c.x + BAR_W), MARGIN.left) + MARGIN.right);
|
|
134
|
+
const dataValueItems = cells.map((c) => `${"·".repeat(c.level)}${c.label}: ${c.value}`);
|
|
135
|
+
const svgChildren = [];
|
|
136
|
+
// smoothed parent→child links
|
|
137
|
+
for (const link of links) {
|
|
138
|
+
const isDim = hoveredKey.value !== null &&
|
|
139
|
+
hoveredKey.value !== link.from.key &&
|
|
140
|
+
hoveredKey.value !== link.to.key;
|
|
141
|
+
svgChildren.push(h("path", {
|
|
142
|
+
key: link.key,
|
|
143
|
+
class: classNames("st-decompositionTreeChart__link", isDim ? "st-decompositionTreeChart__link--dim" : undefined),
|
|
144
|
+
d: linkPath(link),
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
// one column per level: horizontal bar whose width ∝ value
|
|
148
|
+
for (const cell of cells) {
|
|
149
|
+
const chars = charsFor(cell.barWidth);
|
|
150
|
+
const isDim = hoveredKey.value !== null && hoveredKey.value !== cell.key;
|
|
151
|
+
const nodeChildren = [
|
|
152
|
+
h("rect", {
|
|
153
|
+
class: classNames("st-decompositionTreeChart__bar", `st-decompositionTreeChart__bar--${cell.tone}`, isDim ? "st-decompositionTreeChart__bar--dim" : undefined),
|
|
154
|
+
x: cell.x,
|
|
155
|
+
y: cell.y,
|
|
156
|
+
width: Math.max(cell.barWidth, 2),
|
|
157
|
+
height: BAR_H,
|
|
158
|
+
rx: 2,
|
|
159
|
+
"data-chart-key": cell.key,
|
|
160
|
+
}),
|
|
161
|
+
];
|
|
162
|
+
if (chars >= 2) {
|
|
163
|
+
nodeChildren.push(h("text", {
|
|
164
|
+
class: "st-decompositionTreeChart__label",
|
|
165
|
+
x: cell.x + 4,
|
|
166
|
+
y: cell.y + BAR_H / 2,
|
|
167
|
+
"dominant-baseline": "central",
|
|
168
|
+
}, ellipsize(cell.label, chars)));
|
|
169
|
+
}
|
|
170
|
+
svgChildren.push(h("g", { key: cell.key, class: "st-decompositionTreeChart__node" }, nodeChildren));
|
|
171
|
+
}
|
|
172
|
+
const hoveredCell = hoveredKey.value !== null ? cells.find((c) => c.key === hoveredKey.value) ?? null : null;
|
|
173
|
+
const children = [
|
|
174
|
+
h("div", {
|
|
175
|
+
class: "st-decompositionTreeChart__visual",
|
|
176
|
+
role: "img",
|
|
177
|
+
"aria-label": label,
|
|
178
|
+
onPointermove: handlePointerMove,
|
|
179
|
+
onPointerleave: handleLeave,
|
|
180
|
+
}, [
|
|
181
|
+
h("svg", {
|
|
182
|
+
viewBox: `0 0 ${computedWidth} ${computedHeight}`,
|
|
183
|
+
preserveAspectRatio: "xMidYMid meet",
|
|
184
|
+
width: "100%",
|
|
185
|
+
height: "100%",
|
|
186
|
+
focusable: "false",
|
|
187
|
+
"aria-hidden": "true",
|
|
188
|
+
}, svgChildren),
|
|
189
|
+
]),
|
|
190
|
+
chartDataList(label ?? "decomposition tree", dataValueItems),
|
|
191
|
+
];
|
|
192
|
+
if (hoveredCell) {
|
|
193
|
+
children.push(h("div", {
|
|
194
|
+
class: "st-decompositionTreeChart__tooltip",
|
|
195
|
+
role: "presentation",
|
|
196
|
+
style: `left:${(hoveredCell.cx / computedWidth) * 100}%;top:${(hoveredCell.cy / computedHeight) * 100}%`,
|
|
197
|
+
}, [
|
|
198
|
+
h("span", { class: "st-decompositionTreeChart__tooltipLabel" }, `${hoveredCell.dimension} · ${hoveredCell.label}`),
|
|
199
|
+
h("span", { class: "st-decompositionTreeChart__tooltipValue" }, formatValue(hoveredCell.value)),
|
|
200
|
+
]));
|
|
201
|
+
}
|
|
202
|
+
return h("div", { ...attrs, class: classNames("st-decompositionTreeChart", props.class) }, children);
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
//# sourceMappingURL=DecompositionTreeChart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecompositionTreeChart.js","sourceRoot":"","sources":["../src/DecompositionTreeChart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA2BhD,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AAC5D,MAAM,KAAK,GAAG,EAAE,CAAC;AACjB,MAAM,OAAO,GAAG,EAAE,CAAC;AACnB,MAAM,OAAO,GAAG,EAAE,CAAC;AACnB,MAAM,KAAK,GAAG,GAAG,CAAC;AAElB,MAAM,YAAY,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,WAAW,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;AAE7E,6DAA6D;AAC7D,SAAS,SAAS,CAAC,IAAY,EAAE,QAAgB;IAC/C,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,IAAI,CAAC;IACzC,IAAI,QAAQ,IAAI,CAAC;QAAE,OAAO,GAAG,CAAC;IAC9B,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC;AAC3C,CAAC;AAED,SAAS,WAAW,CAAC,CAAS;IAC5B,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI;QAAE,OAAO,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,OAAO,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,CAAC,KAAK,CAAC,CAC/B;iBACF,CACF,CACF,CAAC;YACJ,CAAC;YAED,OAAO,CAAC,CACN,KAAK,EACL,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,2BAA2B,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,EACzE,QAAQ,CACT,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export type Density2DTone = "category1" | "category2" | "category3" | "category4" | "category5" | "category6" | "category7" | "category8";
|
|
2
|
+
export type Density2DPoint = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
weight?: number;
|
|
6
|
+
};
|
|
7
|
+
export type Density2DChartProps = {
|
|
8
|
+
data: Density2DPoint[];
|
|
9
|
+
bins?: number;
|
|
10
|
+
label?: string;
|
|
11
|
+
width?: number;
|
|
12
|
+
height?: number;
|
|
13
|
+
size?: number;
|
|
14
|
+
class?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const Density2DChart: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
17
|
+
data: {
|
|
18
|
+
type: () => Density2DPoint[];
|
|
19
|
+
default: () => never[];
|
|
20
|
+
};
|
|
21
|
+
bins: {
|
|
22
|
+
type: NumberConstructor;
|
|
23
|
+
default: number;
|
|
24
|
+
};
|
|
25
|
+
label: {
|
|
26
|
+
type: StringConstructor;
|
|
27
|
+
default: undefined;
|
|
28
|
+
};
|
|
29
|
+
width: {
|
|
30
|
+
type: NumberConstructor;
|
|
31
|
+
default: undefined;
|
|
32
|
+
};
|
|
33
|
+
height: {
|
|
34
|
+
type: NumberConstructor;
|
|
35
|
+
default: number;
|
|
36
|
+
};
|
|
37
|
+
size: {
|
|
38
|
+
type: NumberConstructor;
|
|
39
|
+
default: undefined;
|
|
40
|
+
};
|
|
41
|
+
class: {
|
|
42
|
+
type: StringConstructor;
|
|
43
|
+
default: undefined;
|
|
44
|
+
};
|
|
45
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
48
|
+
data: {
|
|
49
|
+
type: () => Density2DPoint[];
|
|
50
|
+
default: () => never[];
|
|
51
|
+
};
|
|
52
|
+
bins: {
|
|
53
|
+
type: NumberConstructor;
|
|
54
|
+
default: number;
|
|
55
|
+
};
|
|
56
|
+
label: {
|
|
57
|
+
type: StringConstructor;
|
|
58
|
+
default: undefined;
|
|
59
|
+
};
|
|
60
|
+
width: {
|
|
61
|
+
type: NumberConstructor;
|
|
62
|
+
default: undefined;
|
|
63
|
+
};
|
|
64
|
+
height: {
|
|
65
|
+
type: NumberConstructor;
|
|
66
|
+
default: number;
|
|
67
|
+
};
|
|
68
|
+
size: {
|
|
69
|
+
type: NumberConstructor;
|
|
70
|
+
default: undefined;
|
|
71
|
+
};
|
|
72
|
+
class: {
|
|
73
|
+
type: StringConstructor;
|
|
74
|
+
default: undefined;
|
|
75
|
+
};
|
|
76
|
+
}>> & Readonly<{}>, {
|
|
77
|
+
size: number;
|
|
78
|
+
class: string;
|
|
79
|
+
data: Density2DPoint[];
|
|
80
|
+
label: string;
|
|
81
|
+
height: number;
|
|
82
|
+
width: number;
|
|
83
|
+
bins: number;
|
|
84
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
85
|
+
//# sourceMappingURL=Density2DChart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Density2DChart.d.ts","sourceRoot":"","sources":["../src/Density2DChart.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GACrB,WAAW,GACX,WAAW,GACX,WAAW,GACX,WAAW,GACX,WAAW,GACX,WAAW,GACX,WAAW,GACX,WAAW,CAAC;AAEhB,MAAM,MAAM,cAAc,GAAG;IAC3B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,cAAc,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAuEF,eAAO,MAAM,cAAc;;cAGA,MAAM,cAAc,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAtB,MAAM,cAAc,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4EAgR/C,CAAC"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { defineComponent, h, ref } from "vue";
|
|
2
|
+
import { classNames } from "./classNames.js";
|
|
3
|
+
import { chartDataList } from "./chartScale.js";
|
|
4
|
+
const MARGIN = { top: 16, right: 18, bottom: 36, left: 48 };
|
|
5
|
+
const TONES = [
|
|
6
|
+
"category1",
|
|
7
|
+
"category2",
|
|
8
|
+
"category3",
|
|
9
|
+
"category4",
|
|
10
|
+
"category5",
|
|
11
|
+
"category6",
|
|
12
|
+
"category7",
|
|
13
|
+
"category8",
|
|
14
|
+
];
|
|
15
|
+
// Continuous scale: density normalised 0..max → category1..8 (shared with
|
|
16
|
+
// HeatmapChart). max ≤ 0 or non-finite density → category1 (floor intensity).
|
|
17
|
+
function toneForDensity(density, densityMax) {
|
|
18
|
+
if (!Number.isFinite(density) || densityMax <= 0)
|
|
19
|
+
return "category1";
|
|
20
|
+
const ratio = Math.max(0, Math.min(1, density / densityMax));
|
|
21
|
+
const index = Math.max(0, Math.min(TONES.length - 1, Math.floor(ratio * TONES.length)));
|
|
22
|
+
return TONES[index];
|
|
23
|
+
}
|
|
24
|
+
function niceTicks(min, max, target = 5) {
|
|
25
|
+
if (!Number.isFinite(min) || !Number.isFinite(max) || min === max) {
|
|
26
|
+
return [Number.isFinite(max) ? max : 0];
|
|
27
|
+
}
|
|
28
|
+
const range = max - min;
|
|
29
|
+
const rough = range / Math.max(target - 1, 1);
|
|
30
|
+
const pow = Math.pow(10, Math.floor(Math.log10(rough)));
|
|
31
|
+
const norm = rough / pow;
|
|
32
|
+
let step;
|
|
33
|
+
if (norm < 1.5)
|
|
34
|
+
step = pow;
|
|
35
|
+
else if (norm < 3)
|
|
36
|
+
step = 2 * pow;
|
|
37
|
+
else if (norm < 7)
|
|
38
|
+
step = 5 * pow;
|
|
39
|
+
else
|
|
40
|
+
step = 10 * pow;
|
|
41
|
+
const start = Math.floor(min / step) * step;
|
|
42
|
+
const end = Math.ceil(max / step) * step;
|
|
43
|
+
const ticks = [];
|
|
44
|
+
for (let v = start; v <= end + step / 2; v += step)
|
|
45
|
+
ticks.push(Number(v.toFixed(10)));
|
|
46
|
+
return ticks;
|
|
47
|
+
}
|
|
48
|
+
function scaleLinear(v, d0, d1, r0, r1) {
|
|
49
|
+
if (d1 === d0)
|
|
50
|
+
return r0;
|
|
51
|
+
return r0 + ((v - d0) * (r1 - r0)) / (d1 - d0);
|
|
52
|
+
}
|
|
53
|
+
function formatTick(v) {
|
|
54
|
+
if (Math.abs(v) >= 1000)
|
|
55
|
+
return `${(v / 1000).toFixed(v % 1000 === 0 ? 0 : 1)}k`;
|
|
56
|
+
return Number.isInteger(v) ? String(v) : v.toFixed(1);
|
|
57
|
+
}
|
|
58
|
+
export const Density2DChart = defineComponent({
|
|
59
|
+
name: "Density2DChart",
|
|
60
|
+
props: {
|
|
61
|
+
data: { type: Array, default: () => [] },
|
|
62
|
+
bins: { type: Number, default: 12 },
|
|
63
|
+
label: { type: String, default: undefined },
|
|
64
|
+
width: { type: Number, default: undefined },
|
|
65
|
+
height: { type: Number, default: 320 },
|
|
66
|
+
size: { type: Number, default: undefined },
|
|
67
|
+
class: { type: String, default: undefined },
|
|
68
|
+
},
|
|
69
|
+
setup(props, { attrs }) {
|
|
70
|
+
const hoveredKey = ref(null);
|
|
71
|
+
function handleLeave() {
|
|
72
|
+
hoveredKey.value = null;
|
|
73
|
+
}
|
|
74
|
+
function handlePointerMove(event) {
|
|
75
|
+
const target = event.target;
|
|
76
|
+
if (!(target instanceof Element)) {
|
|
77
|
+
hoveredKey.value = null;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
hoveredKey.value = target.getAttribute("data-chart-key");
|
|
81
|
+
}
|
|
82
|
+
return () => {
|
|
83
|
+
const data = props.data ?? [];
|
|
84
|
+
const label = props.label;
|
|
85
|
+
const height = props.height ?? 320;
|
|
86
|
+
const resolvedWidth = props.width ?? props.size ?? 640;
|
|
87
|
+
const plotWidth = Math.max(resolvedWidth - MARGIN.left - MARGIN.right, 1);
|
|
88
|
+
const plotHeight = Math.max(height - MARGIN.top - MARGIN.bottom, 1);
|
|
89
|
+
// Effective bin count: integer ≥ 1, capped to stay legible.
|
|
90
|
+
const binCount = Math.max(1, Math.min(40, Math.floor(Number.isFinite(props.bins) ? props.bins : 12)));
|
|
91
|
+
// Normalise: keep only finite-coordinate points.
|
|
92
|
+
const validData = data.filter((d) => d && Number.isFinite(d.x) && Number.isFinite(d.y));
|
|
93
|
+
// Extent [minX,maxX]×[minY,maxY] + nice ticks for the axes.
|
|
94
|
+
const xs = validData.map((d) => d.x);
|
|
95
|
+
const ys = validData.map((d) => d.y);
|
|
96
|
+
const xTicks = niceTicks(xs.length ? Math.min(...xs) : 0, xs.length ? Math.max(...xs) : 1);
|
|
97
|
+
const yTicks = niceTicks(ys.length ? Math.min(...ys) : 0, ys.length ? Math.max(...ys) : 1);
|
|
98
|
+
const xMin = xTicks[0];
|
|
99
|
+
const xMax = xTicks[xTicks.length - 1];
|
|
100
|
+
const yMin = yTicks[0];
|
|
101
|
+
const yMax = yTicks[yTicks.length - 1];
|
|
102
|
+
// Regular binning: binCount×binCount grid over the extent; each point
|
|
103
|
+
// falls into a cell, whose density = sum of weights (default 1).
|
|
104
|
+
let densityMax = 0;
|
|
105
|
+
const binCells = [];
|
|
106
|
+
if (validData.length > 0 && xMax !== xMin && yMax !== yMin) {
|
|
107
|
+
const counts = new Float64Array(binCount * binCount);
|
|
108
|
+
const idx = (ix, iy) => iy * binCount + ix;
|
|
109
|
+
for (const d of validData) {
|
|
110
|
+
const fx = (d.x - xMin) / (xMax - xMin);
|
|
111
|
+
const fy = (d.y - yMin) / (yMax - yMin);
|
|
112
|
+
const ix = Math.max(0, Math.min(binCount - 1, Math.floor(fx * binCount)));
|
|
113
|
+
const iy = Math.max(0, Math.min(binCount - 1, Math.floor(fy * binCount)));
|
|
114
|
+
const w = typeof d.weight === "number" && Number.isFinite(d.weight) ? d.weight : 1;
|
|
115
|
+
counts[idx(ix, iy)] += w;
|
|
116
|
+
}
|
|
117
|
+
for (let i = 0; i < counts.length; i++)
|
|
118
|
+
densityMax = Math.max(densityMax, counts[i]);
|
|
119
|
+
const cellW = plotWidth / binCount;
|
|
120
|
+
const cellH = plotHeight / binCount;
|
|
121
|
+
for (let iy = 0; iy < binCount; iy++) {
|
|
122
|
+
for (let ix = 0; ix < binCount; ix++) {
|
|
123
|
+
const density = counts[idx(ix, iy)];
|
|
124
|
+
if (density <= 0)
|
|
125
|
+
continue;
|
|
126
|
+
const x = MARGIN.left + ix * cellW;
|
|
127
|
+
const y = MARGIN.top + (binCount - 1 - iy) * cellH;
|
|
128
|
+
binCells.push({
|
|
129
|
+
key: `${ix}-${iy}`,
|
|
130
|
+
ix,
|
|
131
|
+
iy,
|
|
132
|
+
density,
|
|
133
|
+
x,
|
|
134
|
+
y,
|
|
135
|
+
width: Math.max(cellW - 1, 1),
|
|
136
|
+
height: Math.max(cellH - 1, 1),
|
|
137
|
+
cx: x + cellW / 2,
|
|
138
|
+
cy: y + cellH / 2,
|
|
139
|
+
x0: xMin + (ix / binCount) * (xMax - xMin),
|
|
140
|
+
x1: xMin + ((ix + 1) / binCount) * (xMax - xMin),
|
|
141
|
+
y0: yMin + (iy / binCount) * (yMax - yMin),
|
|
142
|
+
y1: yMin + ((iy + 1) / binCount) * (yMax - yMin),
|
|
143
|
+
tone: toneForDensity(density, densityMax),
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const xAxisTicks = xTicks.map((t) => ({
|
|
149
|
+
value: t,
|
|
150
|
+
x: MARGIN.left + scaleLinear(t, xMin, xMax, 0, plotWidth),
|
|
151
|
+
}));
|
|
152
|
+
const yAxisTicks = yTicks.map((t) => ({
|
|
153
|
+
value: t,
|
|
154
|
+
y: MARGIN.top + scaleLinear(t, yMin, yMax, plotHeight, 0),
|
|
155
|
+
}));
|
|
156
|
+
const dataValueItems = binCells.map((b) => `[${formatTick(b.x0)}–${formatTick(b.x1)}] × [${formatTick(b.y0)}–${formatTick(b.y1)}]: ${b.density}`);
|
|
157
|
+
const legendItems = TONES.map((tone) => ({ tone }));
|
|
158
|
+
const hasLegend = binCells.length > 0;
|
|
159
|
+
const svgChildren = [];
|
|
160
|
+
// tick labels (Y axis)
|
|
161
|
+
for (const tick of yAxisTicks) {
|
|
162
|
+
svgChildren.push(h("text", {
|
|
163
|
+
key: `y${tick.value}`,
|
|
164
|
+
class: "st-density2DChart__tickLabel",
|
|
165
|
+
x: MARGIN.left - 8,
|
|
166
|
+
y: tick.y,
|
|
167
|
+
"text-anchor": "end",
|
|
168
|
+
"dominant-baseline": "middle",
|
|
169
|
+
}, formatTick(tick.value)));
|
|
170
|
+
}
|
|
171
|
+
// tick labels (X axis)
|
|
172
|
+
for (const tick of xAxisTicks) {
|
|
173
|
+
svgChildren.push(h("text", {
|
|
174
|
+
key: `x${tick.value}`,
|
|
175
|
+
class: "st-density2DChart__tickLabel",
|
|
176
|
+
x: tick.x,
|
|
177
|
+
y: height - MARGIN.bottom + 16,
|
|
178
|
+
"text-anchor": "middle",
|
|
179
|
+
}, formatTick(tick.value)));
|
|
180
|
+
}
|
|
181
|
+
// axes
|
|
182
|
+
svgChildren.push(h("line", {
|
|
183
|
+
class: "st-density2DChart__axis",
|
|
184
|
+
x1: MARGIN.left,
|
|
185
|
+
x2: MARGIN.left,
|
|
186
|
+
y1: MARGIN.top,
|
|
187
|
+
y2: height - MARGIN.bottom,
|
|
188
|
+
}));
|
|
189
|
+
svgChildren.push(h("line", {
|
|
190
|
+
class: "st-density2DChart__axis",
|
|
191
|
+
x1: MARGIN.left,
|
|
192
|
+
x2: resolvedWidth - MARGIN.right,
|
|
193
|
+
y1: height - MARGIN.bottom,
|
|
194
|
+
y2: height - MARGIN.bottom,
|
|
195
|
+
}));
|
|
196
|
+
// density cells (binCount×binCount grid, color ∝ density)
|
|
197
|
+
for (const cell of binCells) {
|
|
198
|
+
const isDim = hoveredKey.value !== null && hoveredKey.value !== cell.key;
|
|
199
|
+
svgChildren.push(h("rect", {
|
|
200
|
+
key: cell.key,
|
|
201
|
+
class: classNames("st-density2DChart__cell", `st-density2DChart__cell--${cell.tone}`, isDim ? "st-density2DChart__cell--dim" : undefined),
|
|
202
|
+
x: cell.x,
|
|
203
|
+
y: cell.y,
|
|
204
|
+
width: cell.width,
|
|
205
|
+
height: cell.height,
|
|
206
|
+
rx: 1,
|
|
207
|
+
"data-chart-key": cell.key,
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
const hoveredCell = hoveredKey.value !== null ? binCells.find((b) => b.key === hoveredKey.value) ?? null : null;
|
|
211
|
+
const children = [
|
|
212
|
+
h("div", {
|
|
213
|
+
class: "st-density2DChart__visual",
|
|
214
|
+
role: "img",
|
|
215
|
+
"aria-label": label,
|
|
216
|
+
onPointermove: handlePointerMove,
|
|
217
|
+
onPointerleave: handleLeave,
|
|
218
|
+
}, [
|
|
219
|
+
h("svg", {
|
|
220
|
+
viewBox: `0 0 ${resolvedWidth} ${height}`,
|
|
221
|
+
preserveAspectRatio: "xMidYMid meet",
|
|
222
|
+
width: "100%",
|
|
223
|
+
height: "100%",
|
|
224
|
+
focusable: "false",
|
|
225
|
+
"aria-hidden": "true",
|
|
226
|
+
}, svgChildren),
|
|
227
|
+
]),
|
|
228
|
+
];
|
|
229
|
+
if (hasLegend) {
|
|
230
|
+
children.push(h("div", { class: "st-density2DChart__legend", "aria-hidden": "true" }, [
|
|
231
|
+
h("span", { class: "st-density2DChart__legendText" }, "Low"),
|
|
232
|
+
h("span", { class: "st-density2DChart__legendRamp" }, legendItems.map((item) => h("span", {
|
|
233
|
+
key: item.tone,
|
|
234
|
+
class: `st-density2DChart__legendSwatch st-density2DChart__legendSwatch--${item.tone}`,
|
|
235
|
+
}))),
|
|
236
|
+
h("span", { class: "st-density2DChart__legendText" }, "High"),
|
|
237
|
+
]));
|
|
238
|
+
}
|
|
239
|
+
children.push(chartDataList(label ?? "density 2d", dataValueItems));
|
|
240
|
+
if (hoveredCell) {
|
|
241
|
+
children.push(h("div", {
|
|
242
|
+
class: "st-density2DChart__tooltip",
|
|
243
|
+
role: "presentation",
|
|
244
|
+
style: `left:${(hoveredCell.cx / resolvedWidth) * 100}%;top:${(hoveredCell.cy / height) * 100}%`,
|
|
245
|
+
}, [
|
|
246
|
+
h("span", { class: "st-density2DChart__tooltipLabel" }, `[${formatTick(hoveredCell.x0)}–${formatTick(hoveredCell.x1)}] × [${formatTick(hoveredCell.y0)}–${formatTick(hoveredCell.y1)}]`),
|
|
247
|
+
h("span", { class: "st-density2DChart__tooltipValue" }, `${hoveredCell.density}`),
|
|
248
|
+
]));
|
|
249
|
+
}
|
|
250
|
+
return h("div", { ...attrs, class: classNames("st-density2DChart", props.class) }, children);
|
|
251
|
+
};
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
//# sourceMappingURL=Density2DChart.js.map
|