layerchart 0.98.1 → 0.99.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.
|
@@ -84,7 +84,8 @@
|
|
|
84
84
|
/** Filter nodes */
|
|
85
85
|
export let filterNodes: (nodeId: string, graph: dagre.graphlib.Graph) => boolean = () => true;
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
/** Exposed to access to Dagre Graph instance via `bind:graph` */
|
|
88
|
+
export let graph: dagre.graphlib.Graph | undefined = undefined;
|
|
88
89
|
$: {
|
|
89
90
|
let g = new dagre.graphlib.Graph({ directed, multigraph, compound });
|
|
90
91
|
|
|
@@ -135,17 +136,17 @@
|
|
|
135
136
|
);
|
|
136
137
|
});
|
|
137
138
|
|
|
138
|
-
g = filterNodes ? g.filterNodes((nodeId) => filterNodes(nodeId, graph)) : graph
|
|
139
|
+
g = filterNodes ? g.filterNodes((nodeId) => filterNodes(nodeId, graph!)) : graph!;
|
|
139
140
|
|
|
140
141
|
dagre.layout(g);
|
|
141
142
|
|
|
142
143
|
graph = g;
|
|
143
144
|
}
|
|
144
145
|
|
|
145
|
-
$: graphNodes = graph
|
|
146
|
-
$: graphEdges = graph
|
|
146
|
+
$: graphNodes = graph!.nodes().map((id) => graph!.node(id));
|
|
147
|
+
$: graphEdges = graph!.edges().map((edge) => ({ ...edge, ...graph!.edge(edge) })) as Array<
|
|
147
148
|
Edge & EdgeConfig & GraphEdge // `EdgeConfig` is excluded when inferred from usage
|
|
148
149
|
>;
|
|
149
150
|
</script>
|
|
150
151
|
|
|
151
|
-
<slot nodes={graphNodes} edges={graphEdges} />
|
|
152
|
+
<slot nodes={graphNodes} edges={graphEdges} {graph} />
|
|
@@ -52,6 +52,7 @@ declare const __propDef: {
|
|
|
52
52
|
/** Default edge label height if not defined on edge */ edgeLabelPosition?: keyof typeof EdgeLabelPosition;
|
|
53
53
|
/** Default pixels to move the label away from the edge if not defined on edge. Applies only when labelpos is l or r.*/ edgeLabelOffset?: number;
|
|
54
54
|
/** Filter nodes */ filterNodes?: (nodeId: string, graph: dagre.graphlib.Graph) => boolean;
|
|
55
|
+
/** Exposed to access to Dagre Graph instance via `bind:graph` */ graph?: dagre.graphlib.Graph | undefined;
|
|
55
56
|
};
|
|
56
57
|
events: {
|
|
57
58
|
[evt: string]: CustomEvent<any>;
|
|
@@ -74,6 +75,7 @@ declare const __propDef: {
|
|
|
74
75
|
shape?: string | undefined;
|
|
75
76
|
}[];
|
|
76
77
|
edges: (dagre.Edge & dagre.EdgeConfig & dagre.GraphEdge)[];
|
|
78
|
+
graph: dagre.graphlib.Graph<{}> | undefined;
|
|
77
79
|
};
|
|
78
80
|
};
|
|
79
81
|
};
|
|
@@ -128,6 +128,7 @@
|
|
|
128
128
|
|
|
129
129
|
let isHoveringTooltip = false;
|
|
130
130
|
let hideTimeoutId: NodeJS.Timeout;
|
|
131
|
+
let tooltipContextNode: HTMLDivElement;
|
|
131
132
|
|
|
132
133
|
$: bisectX = bisector((d: any) => {
|
|
133
134
|
const value = $x(d);
|
|
@@ -187,20 +188,15 @@
|
|
|
187
188
|
return;
|
|
188
189
|
}
|
|
189
190
|
|
|
190
|
-
const
|
|
191
|
-
const point = localPoint(e,
|
|
192
|
-
const pointerX = point?.x ?? 0;
|
|
193
|
-
const pointerY = point?.y ?? 0;
|
|
191
|
+
const containerNode = (e.target as Element).closest('.layercake-container')!;
|
|
192
|
+
const point = localPoint(e, containerNode);
|
|
194
193
|
|
|
195
194
|
if (
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
pointerY < e.currentTarget?.offsetTop ||
|
|
202
|
-
// @ts-expect-error
|
|
203
|
-
pointerY > e.currentTarget?.offsetTop + e.currentTarget?.offsetHeight
|
|
195
|
+
mode !== 'manual' &&
|
|
196
|
+
(point.x < tooltipContextNode.offsetLeft ||
|
|
197
|
+
point.x > tooltipContextNode.offsetLeft + tooltipContextNode.offsetWidth ||
|
|
198
|
+
point.y < tooltipContextNode.offsetTop ||
|
|
199
|
+
point.y > tooltipContextNode.offsetTop + tooltipContextNode.offsetHeight)
|
|
204
200
|
) {
|
|
205
201
|
// Ignore if within padding of chart
|
|
206
202
|
hideTooltip();
|
|
@@ -215,10 +211,10 @@
|
|
|
215
211
|
let xValueAtPoint: any;
|
|
216
212
|
if ($radial) {
|
|
217
213
|
// Assume radial is always centered
|
|
218
|
-
const { radians } = cartesianToPolar(
|
|
214
|
+
const { radians } = cartesianToPolar(point.x - $width / 2, point.y - $height / 2);
|
|
219
215
|
xValueAtPoint = scaleInvert($xScale, radians);
|
|
220
216
|
} else {
|
|
221
|
-
xValueAtPoint = scaleInvert($xScale,
|
|
217
|
+
xValueAtPoint = scaleInvert($xScale, point.x - $padding.left);
|
|
222
218
|
}
|
|
223
219
|
|
|
224
220
|
const index = bisectX($flatData, xValueAtPoint, 1);
|
|
@@ -230,7 +226,7 @@
|
|
|
230
226
|
|
|
231
227
|
case 'bisect-y': {
|
|
232
228
|
// `y` value at pointer coordinate
|
|
233
|
-
const yValueAtPoint = scaleInvert($yScale,
|
|
229
|
+
const yValueAtPoint = scaleInvert($yScale, point.y - $padding.top);
|
|
234
230
|
|
|
235
231
|
const index = bisectY($flatData, yValueAtPoint, 1);
|
|
236
232
|
const previousValue = $flatData[index - 1];
|
|
@@ -241,8 +237,8 @@
|
|
|
241
237
|
|
|
242
238
|
case 'bisect-band': {
|
|
243
239
|
// `x` and `y` values at pointer coordinate
|
|
244
|
-
const xValueAtPoint = scaleInvert($xScale,
|
|
245
|
-
const yValueAtPoint = scaleInvert($yScale,
|
|
240
|
+
const xValueAtPoint = scaleInvert($xScale, point.x);
|
|
241
|
+
const yValueAtPoint = scaleInvert($yScale, point.y);
|
|
246
242
|
|
|
247
243
|
if (isScaleBand($xScale)) {
|
|
248
244
|
// Find point closest to pointer within the x band
|
|
@@ -269,7 +265,7 @@
|
|
|
269
265
|
}
|
|
270
266
|
|
|
271
267
|
case 'quadtree': {
|
|
272
|
-
tooltipData = quadtree.find(
|
|
268
|
+
tooltipData = quadtree.find(point.x, point.y, radius);
|
|
273
269
|
break;
|
|
274
270
|
}
|
|
275
271
|
}
|
|
@@ -282,8 +278,8 @@
|
|
|
282
278
|
|
|
283
279
|
$tooltip = {
|
|
284
280
|
...$tooltip,
|
|
285
|
-
x:
|
|
286
|
-
y:
|
|
281
|
+
x: point.x,
|
|
282
|
+
y: point.y,
|
|
287
283
|
data: tooltipData,
|
|
288
284
|
};
|
|
289
285
|
} else {
|
|
@@ -427,6 +423,7 @@
|
|
|
427
423
|
onclick(e, { data: $tooltip?.data });
|
|
428
424
|
}
|
|
429
425
|
}}
|
|
426
|
+
bind:this={tooltipContextNode}
|
|
430
427
|
>
|
|
431
428
|
<!-- Rendering slot within TooltipContext to allow pointer events to bubble up (ex. Brush) -->
|
|
432
429
|
<div
|