@opendata-ai/openchart-vanilla 7.2.2 → 7.2.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opendata-ai/openchart-vanilla",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.4",
|
|
4
4
|
"description": "Vanilla JS renderer for openchart: SVG charts, HTML tables, force-directed graphs",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Riley Hilliard",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@floating-ui/dom": "^1.7.6",
|
|
53
|
-
"@opendata-ai/openchart-core": "7.2.
|
|
54
|
-
"@opendata-ai/openchart-engine": "7.2.
|
|
53
|
+
"@opendata-ai/openchart-core": "7.2.4",
|
|
54
|
+
"@opendata-ai/openchart-engine": "7.2.4",
|
|
55
55
|
"d3-force": "^3.0.0",
|
|
56
56
|
"d3-quadtree": "^3.0.1"
|
|
57
57
|
},
|
|
@@ -86,7 +86,15 @@ function makeTheme(isDark = false): ResolvedTheme {
|
|
|
86
86
|
fonts: {
|
|
87
87
|
family: 'Inter, sans-serif',
|
|
88
88
|
mono: 'monospace',
|
|
89
|
-
sizes: {
|
|
89
|
+
sizes: {
|
|
90
|
+
title: 18,
|
|
91
|
+
subtitle: 14,
|
|
92
|
+
body: 12,
|
|
93
|
+
small: 10,
|
|
94
|
+
axisTick: 11,
|
|
95
|
+
metricLabel: 10,
|
|
96
|
+
metricValue: 22,
|
|
97
|
+
},
|
|
90
98
|
weights: { normal: 400, medium: 500, semibold: 600, bold: 700 },
|
|
91
99
|
},
|
|
92
100
|
spacing: {
|
package/src/renderers/metrics.ts
CHANGED
|
@@ -7,23 +7,34 @@
|
|
|
7
7
|
import type { ChartLayout } from '@opendata-ai/openchart-core';
|
|
8
8
|
import { createSVGElement, setAttrs } from './svg-dom';
|
|
9
9
|
|
|
10
|
+
// Delta and secondary text run at a fraction of the primary value size. This
|
|
11
|
+
// preserves the editorial mock's proportion (12px delta against a 22px value)
|
|
12
|
+
// at any theme-driven value size, so scaling metricValue scales the whole cell.
|
|
13
|
+
const DELTA_SIZE_RATIO = 12 / 22;
|
|
14
|
+
|
|
10
15
|
export function renderMetrics(parent: SVGElement, layout: ChartLayout): void {
|
|
11
16
|
const bar = layout.metrics;
|
|
12
17
|
if (!bar || bar.cells.length === 0) return;
|
|
13
18
|
|
|
19
|
+
// Font sizes flow from the theme. Set them inline so they override the CSS
|
|
20
|
+
// defaults (.oc-metric-* in chrome.css) when a chart customizes the sizes.
|
|
21
|
+
const labelSize = layout.theme.fonts.sizes.metricLabel;
|
|
22
|
+
const valueSize = layout.theme.fonts.sizes.metricValue;
|
|
23
|
+
const deltaSize = Math.round(valueSize * DELTA_SIZE_RATIO);
|
|
24
|
+
|
|
14
25
|
const g = createSVGElement('g');
|
|
15
26
|
g.setAttribute('class', 'oc-metrics');
|
|
16
27
|
|
|
17
28
|
for (const cell of bar.cells) {
|
|
18
29
|
const label = createSVGElement('text');
|
|
19
30
|
label.setAttribute('class', 'oc-metric-label');
|
|
20
|
-
setAttrs(label, { x: cell.x, y: cell.labelY });
|
|
31
|
+
setAttrs(label, { x: cell.x, y: cell.labelY, 'font-size': labelSize });
|
|
21
32
|
label.textContent = cell.metric.label.toUpperCase();
|
|
22
33
|
g.appendChild(label);
|
|
23
34
|
|
|
24
35
|
const value = createSVGElement('text');
|
|
25
36
|
value.setAttribute('class', 'oc-metric-value');
|
|
26
|
-
setAttrs(value, { x: cell.x, y: cell.valueY });
|
|
37
|
+
setAttrs(value, { x: cell.x, y: cell.valueY, 'font-size': valueSize });
|
|
27
38
|
value.textContent = cell.metric.value;
|
|
28
39
|
|
|
29
40
|
if (cell.metric.delta) {
|
|
@@ -31,6 +42,7 @@ export function renderMetrics(parent: SVGElement, layout: ChartLayout): void {
|
|
|
31
42
|
const tone = cell.metric.deltaTone ?? 'up';
|
|
32
43
|
delta.setAttribute('class', tone === 'down' ? 'oc-metric-delta-down' : 'oc-metric-delta-up');
|
|
33
44
|
delta.setAttribute('dx', '8');
|
|
45
|
+
delta.setAttribute('font-size', String(deltaSize));
|
|
34
46
|
delta.textContent = cell.metric.delta;
|
|
35
47
|
value.appendChild(delta);
|
|
36
48
|
}
|
|
@@ -39,6 +51,7 @@ export function renderMetrics(parent: SVGElement, layout: ChartLayout): void {
|
|
|
39
51
|
const secondary = createSVGElement('tspan');
|
|
40
52
|
secondary.setAttribute('class', 'oc-metric-secondary');
|
|
41
53
|
secondary.setAttribute('dx', '6');
|
|
54
|
+
secondary.setAttribute('font-size', String(deltaSize));
|
|
42
55
|
secondary.textContent = cell.metric.secondary;
|
|
43
56
|
value.appendChild(secondary);
|
|
44
57
|
}
|