@opendata-ai/openchart-vanilla 7.1.1 → 7.1.3
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.js +42 -61
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/renderers/brand.ts +3 -3
- package/src/renderers/endpoint-labels.ts +12 -32
- package/src/renderers/legend.ts +31 -37
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opendata-ai/openchart-vanilla",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.3",
|
|
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.1.
|
|
54
|
-
"@opendata-ai/openchart-engine": "7.1.
|
|
53
|
+
"@opendata-ai/openchart-core": "7.1.3",
|
|
54
|
+
"@opendata-ai/openchart-engine": "7.1.3",
|
|
55
55
|
"d3-force": "^3.0.0",
|
|
56
56
|
"d3-quadtree": "^3.0.1"
|
|
57
57
|
},
|
package/src/renderers/brand.ts
CHANGED
|
@@ -46,13 +46,13 @@ export function renderBrand(parent: SVGElement, layout: ChartLayout): void {
|
|
|
46
46
|
|
|
47
47
|
// "try" in normal weight, "OpenData" in semibold, ".ai" in normal weight,
|
|
48
48
|
// rendered as a single right-aligned text element with three tspans.
|
|
49
|
-
// Use
|
|
49
|
+
// Use hanging baseline to align top-edge with source/byline chrome text.
|
|
50
50
|
const BRAND_LARGE = 16;
|
|
51
51
|
const text = createSVGElement('text');
|
|
52
52
|
setAttrs(text, {
|
|
53
53
|
x: rightEdge,
|
|
54
|
-
y: chromeY
|
|
55
|
-
'dominant-baseline': '
|
|
54
|
+
y: chromeY,
|
|
55
|
+
'dominant-baseline': 'hanging',
|
|
56
56
|
'font-family': layout.theme.fonts.family,
|
|
57
57
|
'font-size': BRAND_FONT_SIZE,
|
|
58
58
|
'text-anchor': 'end',
|
|
@@ -71,40 +71,20 @@ export function renderEndpointLabels(parent: SVGElement, layout: ChartLayout): v
|
|
|
71
71
|
entryG.appendChild(leader);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
// Swatch:
|
|
75
|
-
// the traditional legend so a chart never shows two swatch idioms.
|
|
74
|
+
// Swatch: bare colored line segment matching the legend style.
|
|
76
75
|
const rowY = entry.labelY + labelFontSize / 2;
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
ry: 3,
|
|
88
|
-
fill: ep.swatchChipFill,
|
|
76
|
+
const line = createSVGElement('line');
|
|
77
|
+
line.setAttribute('class', 'oc-endpoint-swatch-line');
|
|
78
|
+
setAttrs(line, {
|
|
79
|
+
x1: chipX,
|
|
80
|
+
y1: rowY,
|
|
81
|
+
x2: chipX + chipWidth,
|
|
82
|
+
y2: rowY,
|
|
83
|
+
stroke: entry.color,
|
|
84
|
+
'stroke-width': 2,
|
|
85
|
+
'stroke-linecap': 'round',
|
|
89
86
|
});
|
|
90
|
-
entryG.appendChild(
|
|
91
|
-
|
|
92
|
-
const barWidth = Math.max(8, chipWidth - 8);
|
|
93
|
-
const barHeight = 3;
|
|
94
|
-
const barX = chipX + (chipWidth - barWidth) / 2;
|
|
95
|
-
const barY = rowY - barHeight / 2;
|
|
96
|
-
const bar = createSVGElement('rect');
|
|
97
|
-
bar.setAttribute('class', 'oc-endpoint-swatch-bar');
|
|
98
|
-
setAttrs(bar, {
|
|
99
|
-
x: barX,
|
|
100
|
-
y: barY,
|
|
101
|
-
width: barWidth,
|
|
102
|
-
height: barHeight,
|
|
103
|
-
rx: barHeight / 2,
|
|
104
|
-
ry: barHeight / 2,
|
|
105
|
-
fill: entry.color,
|
|
106
|
-
});
|
|
107
|
-
entryG.appendChild(bar);
|
|
87
|
+
entryG.appendChild(line);
|
|
108
88
|
|
|
109
89
|
// Label text. Multi-line via tspans when wrapped.
|
|
110
90
|
const label = createSVGElement('text');
|
package/src/renderers/legend.ts
CHANGED
|
@@ -60,53 +60,47 @@ export function renderLegend(parent: SVGElement, legend: LegendLayout): void {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
// Swatch
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// and the endpoint-labels swatch so a chart never shows two swatch styles.
|
|
68
|
-
// 'circle' is preserved for point/scatter charts.
|
|
63
|
+
// Swatch: bare colored mark matching the chart type.
|
|
64
|
+
// Circle for point/scatter, line segment for line/area, filled rect for bar.
|
|
65
|
+
const midX = offsetX + legend.swatchSize / 2;
|
|
66
|
+
const midY = offsetY + legend.swatchSize / 2;
|
|
69
67
|
if (entry.shape === 'circle') {
|
|
70
68
|
const circle = createSVGElement('circle');
|
|
71
69
|
setAttrs(circle, {
|
|
72
|
-
cx:
|
|
73
|
-
cy:
|
|
70
|
+
cx: midX,
|
|
71
|
+
cy: midY,
|
|
74
72
|
r: legend.swatchSize / 2,
|
|
75
73
|
fill: entry.color,
|
|
76
74
|
});
|
|
77
75
|
entryG.appendChild(circle);
|
|
78
|
-
} else {
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
fill: legend.swatchChipFill,
|
|
76
|
+
} else if (entry.shape === 'line') {
|
|
77
|
+
const lineWidth = legend.swatchSize;
|
|
78
|
+
const line = createSVGElement('line');
|
|
79
|
+
line.setAttribute('class', 'oc-legend-swatch-line');
|
|
80
|
+
setAttrs(line, {
|
|
81
|
+
x1: offsetX,
|
|
82
|
+
y1: midY,
|
|
83
|
+
x2: offsetX + lineWidth,
|
|
84
|
+
y2: midY,
|
|
85
|
+
stroke: entry.color,
|
|
86
|
+
'stroke-width': 2,
|
|
87
|
+
'stroke-linecap': 'round',
|
|
91
88
|
});
|
|
92
|
-
entryG.appendChild(
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
height: barHeight,
|
|
105
|
-
rx: barHeight / 2,
|
|
106
|
-
ry: barHeight / 2,
|
|
89
|
+
entryG.appendChild(line);
|
|
90
|
+
} else {
|
|
91
|
+
const rectSize = Math.round(legend.swatchSize * 0.6);
|
|
92
|
+
const rect = createSVGElement('rect');
|
|
93
|
+
rect.setAttribute('class', 'oc-legend-swatch-rect');
|
|
94
|
+
setAttrs(rect, {
|
|
95
|
+
x: offsetX + (legend.swatchSize - rectSize) / 2,
|
|
96
|
+
y: midY - rectSize / 2,
|
|
97
|
+
width: rectSize,
|
|
98
|
+
height: rectSize,
|
|
99
|
+
rx: 2,
|
|
100
|
+
ry: 2,
|
|
107
101
|
fill: entry.color,
|
|
108
102
|
});
|
|
109
|
-
entryG.appendChild(
|
|
103
|
+
entryG.appendChild(rect);
|
|
110
104
|
}
|
|
111
105
|
|
|
112
106
|
// Label
|