@opendata-ai/openchart-vanilla 2.2.0 → 2.3.0
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.d.ts +4 -0
- package/dist/index.js +19 -13
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/graph/canvas-renderer.ts +13 -10
- package/src/graph-mount.ts +13 -5
package/dist/index.d.ts
CHANGED
|
@@ -88,6 +88,10 @@ interface GraphMountOptions {
|
|
|
88
88
|
theme?: ThemeConfig;
|
|
89
89
|
darkMode?: DarkMode;
|
|
90
90
|
responsive?: boolean;
|
|
91
|
+
/** Show the built-in tooltip on node/edge hover. Defaults to true. */
|
|
92
|
+
tooltip?: boolean;
|
|
93
|
+
/** Show the built-in legend. Defaults to true. */
|
|
94
|
+
legend?: boolean;
|
|
91
95
|
onNodeClick?: (node: Record<string, unknown>) => void;
|
|
92
96
|
onNodeDoubleClick?: (node: Record<string, unknown>) => void;
|
|
93
97
|
onNodeHover?: (node: Record<string, unknown> | null) => void;
|
package/dist/index.js
CHANGED
|
@@ -107,15 +107,15 @@ function createSimulationWorker() {
|
|
|
107
107
|
import { compileGraph } from "@opendata-ai/openchart-engine";
|
|
108
108
|
|
|
109
109
|
// src/graph/canvas-renderer.ts
|
|
110
|
-
var LABEL_FONT_MIN =
|
|
111
|
-
var LABEL_FONT_MAX =
|
|
110
|
+
var LABEL_FONT_MIN = 8;
|
|
111
|
+
var LABEL_FONT_MAX = 12;
|
|
112
112
|
var EDGE_ALPHA_DEFAULT = 0.35;
|
|
113
113
|
var EDGE_ALPHA_CONNECTED = 1;
|
|
114
114
|
var EDGE_ALPHA_DIMMED = 0.05;
|
|
115
115
|
var SEARCH_NON_MATCH_ALPHA = 0.15;
|
|
116
116
|
var GLOW_NODE_THRESHOLD = 2e3;
|
|
117
|
-
var GLOW_RADIUS_MULTIPLIER = 1.
|
|
118
|
-
var GLOW_ALPHA = 0.
|
|
117
|
+
var GLOW_RADIUS_MULTIPLIER = 1.3;
|
|
118
|
+
var GLOW_ALPHA = 0.15;
|
|
119
119
|
var CULL_MARGIN = 50;
|
|
120
120
|
var TWO_PI = Math.PI * 2;
|
|
121
121
|
var MIN_SCREEN_RADIUS = 2.5;
|
|
@@ -203,8 +203,10 @@ var GraphCanvasRenderer = class {
|
|
|
203
203
|
ctx.save();
|
|
204
204
|
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
205
205
|
ctx.clearRect(0, 0, cssWidth, cssHeight);
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
if (theme.colors.background !== "transparent") {
|
|
207
|
+
ctx.fillStyle = theme.colors.background;
|
|
208
|
+
ctx.fillRect(0, 0, cssWidth, cssHeight);
|
|
209
|
+
}
|
|
208
210
|
ctx.translate(transform.x, transform.y);
|
|
209
211
|
ctx.scale(transform.k, transform.k);
|
|
210
212
|
this.drawEdgesBatched(
|
|
@@ -542,7 +544,7 @@ var GraphCanvasRenderer = class {
|
|
|
542
544
|
// Labels (drawn individually, skipped during gestures)
|
|
543
545
|
// -------------------------------------------------------------------------
|
|
544
546
|
drawLabels(ctx, nodes, threshold, hoveredNodeId, selectedNodeIds, searchMatches, zoom, theme) {
|
|
545
|
-
const rawSize =
|
|
547
|
+
const rawSize = 10 / zoom;
|
|
546
548
|
const fontSize = Math.max(LABEL_FONT_MIN, Math.min(LABEL_FONT_MAX, rawSize));
|
|
547
549
|
ctx.font = `${fontSize}px ${theme.fonts.family}`;
|
|
548
550
|
ctx.textAlign = "center";
|
|
@@ -556,7 +558,7 @@ var GraphCanvasRenderer = class {
|
|
|
556
558
|
if (!forced && node.labelPriority < threshold) continue;
|
|
557
559
|
ctx.globalAlpha = dimmed ? SEARCH_NON_MATCH_ALPHA : 1;
|
|
558
560
|
const labelY = node.y + node.radius + 3;
|
|
559
|
-
ctx.strokeStyle = theme.colors.background;
|
|
561
|
+
ctx.strokeStyle = theme.colors.background === "transparent" ? "rgba(0, 0, 0, 0.7)" : theme.colors.background;
|
|
560
562
|
ctx.lineWidth = 3;
|
|
561
563
|
ctx.lineJoin = "round";
|
|
562
564
|
ctx.strokeText(node.label, node.x, labelY);
|
|
@@ -1653,10 +1655,12 @@ function createGraph(container, spec, options) {
|
|
|
1653
1655
|
canvas.setAttribute("aria-label", compilation.a11y.altText);
|
|
1654
1656
|
}
|
|
1655
1657
|
wrapper.appendChild(canvas);
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1658
|
+
if (options?.legend !== false) {
|
|
1659
|
+
legendEl = document.createElement("div");
|
|
1660
|
+
legendEl.className = "viz-graph-legend";
|
|
1661
|
+
renderLegend2();
|
|
1662
|
+
wrapper.appendChild(legendEl);
|
|
1663
|
+
}
|
|
1660
1664
|
container.appendChild(wrapper);
|
|
1661
1665
|
const chromeHeight = chromeEl.getBoundingClientRect().height || 0;
|
|
1662
1666
|
const canvasHeight = Math.max(height - chromeHeight, 200);
|
|
@@ -1781,7 +1785,9 @@ function createGraph(container, spec, options) {
|
|
|
1781
1785
|
}
|
|
1782
1786
|
function initInteraction() {
|
|
1783
1787
|
if (!canvas) return;
|
|
1784
|
-
|
|
1788
|
+
if (options?.tooltip !== false) {
|
|
1789
|
+
tooltipManager = createTooltipManager(wrapper);
|
|
1790
|
+
}
|
|
1785
1791
|
interactionManager = new GraphInteractionManager(canvas, spatialIndex, {
|
|
1786
1792
|
onTransformChange(_transform) {
|
|
1787
1793
|
markGesture();
|