Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 15 additions & 32 deletions packages/common/src/SVGZoomWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class SVGZoomWidget extends SVGWidget {

protected _marqueeSelectionRoot;
protected _marqueeSelection;
protected _marqueeAnchor: { x: number, y: number } | null = null;

protected _autoSelectionMode = false;

Expand Down Expand Up @@ -233,6 +234,7 @@ export class SVGZoomWidget extends SVGWidget {

mousedownMarqueeSelection() {
const p = d3Mouse(this._marqueeSelectionRoot.node());
this._marqueeAnchor = { x: p[0], y: p[1] };
this._marqueeSelection = this.element().append("rect")
.attr("class", "marqueeSelection")
.attr("rx", 6)
Expand All @@ -246,45 +248,26 @@ export class SVGZoomWidget extends SVGWidget {
}

mousemoveMarqueeSelection() {
if (this._marqueeSelection) {
if (this._marqueeSelection && this._marqueeAnchor) {
const p = d3Mouse(this._marqueeSelectionRoot.node());
const d = {
x: parseInt(this._marqueeSelection.attr("x"), 10),
y: parseInt(this._marqueeSelection.attr("y"), 10),
width: parseInt(this._marqueeSelection.attr("width"), 10),
height: parseInt(this._marqueeSelection.attr("height"), 10)
};
const move = {
x: p[0] - d.x,
y: p[1] - d.y
};

if (move.x < 1 || (move.x * 2 < d.width)) {
d.x = p[0];
d.width -= move.x;
} else {
d.width = move.x;
}

if (move.y < 1 || (move.y * 2 < d.height)) {
d.y = p[1];
d.height -= move.y;
} else {
d.height = move.y;
}
const x = Math.min(p[0], this._marqueeAnchor.x);
const y = Math.min(p[1], this._marqueeAnchor.y);
const w = Math.abs(p[0] - this._marqueeAnchor.x);
const h = Math.abs(p[1] - this._marqueeAnchor.y);

this._marqueeSelection
.attr("x", d.x)
.attr("y", d.y)
.attr("width", d.width)
.attr("height", d.height)
.attr("x", x)
.attr("y", y)
.attr("width", w)
.attr("height", h)
;

this.updateMarqueeSelection({
x: (d.x - this._zoomTranslate[0]) / this._zoomScale,
y: (d.y - this._zoomTranslate[1]) / this._zoomScale,
width: d.width / this._zoomScale,
height: d.height / this._zoomScale
x: (x - this._zoomTranslate[0]) / this._zoomScale,
y: (y - this._zoomTranslate[1]) / this._zoomScale,
width: w / this._zoomScale,
height: h / this._zoomScale
});
}
}
Expand Down
49 changes: 47 additions & 2 deletions packages/graph/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html>
<html style="color-scheme: light;">

<head>
<title>Home</title>
Expand All @@ -17,14 +17,24 @@
}

#placeholder,
#placeholderDark,
#placeholder1,
#placeholder2,
#placeholder3 {
#placeholder3,
#placeholder4 {
width: 100%;
height: 500px;
background-color: #fff;
margin-top: 20px;
}

#placeholder {
color-scheme: light;
}

#placeholderDark {
color-scheme: dark;
}
</style>
<script type="module">
import "@hpcc-js/common/font-awesome/css/font-awesome.min.css";
Expand All @@ -33,6 +43,41 @@

<body onresize="doResize()">
<h1>ESM Quick Test</h1>
<div id="placeholder"></div>
<script type="module">
import { testGraphviz as Test } from "./tests/index.ts";

const graphvizWidget = await Test();
graphvizWidget
.target("placeholder")
.render()
;
window.addEventListener("keydown", e => {
if (e.ctrlKey && e.key.toLowerCase() === "u") {
e.preventDefault();
const g = graphvizWidget.data();
const nodes = g.nodeNames();
console.log(nodes);
if (nodes.length > 0) {
g.removeNode(nodes[nodes.length - 1]);
graphvizWidget.render();
}
const edges = g.edges();
console.log(edges);
}
});

</script>
<div id="placeholderDark"></div>
<script type="module">
import { testGraphviz as Test } from "./tests/index.ts";

const graphvizWidgetDark = await Test();
graphvizWidgetDark
.target("placeholderDark")
.render()
;
</script>
<div id="placeholder1"></div>
<script type="module">
import { Test6 as Test } from "./tests/index.ts";
Expand Down
138 changes: 138 additions & 0 deletions packages/graph/src/graphviz/Widget.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
.graph_GraphvizWidget {
--gv-bg: light-dark(#ffffff, #1a1a2e);
--gv-shadow: light-dark(#e6e6e6, #0d0d18);
--gv-fg: light-dark(#242424, #e0e0e0);
--gv-select-stroke: light-dark(#0078d4, #4cc2ff);
--gv-select-fill: light-dark(#deecf9, #1b3a5c);

--gv-unknown-stroke: light-dark(#616161, #9e9e9e);
--gv-unknown-fill: light-dark(#e0e0e0, #2a2a3e);
--gv-complete-stroke: light-dark(#2e7d32, #66bb6a);
--gv-complete-fill: light-dark(#e8f5e9, #1b3a1e);
--gv-failed-stroke: light-dark(#c62828, #ef5350);
--gv-failed-fill: light-dark(#ffebee, #3a1b1b);
--gv-running-stroke: light-dark(#e65100, #ffa726);
--gv-running-fill: light-dark(#fff3e0, #3a2a1b);

background-color: var(--gv-shadow);
stroke: var(--gv-fg);
}

.graph_GraphvizWidget > g > rect.zoomBackground {
fill: var(--gv-shadow) !important;
stroke: none;
}

/* Selection rules */
.graph_GraphvizWidget .node>path,
.graph_GraphvizWidget .node>polygon,
.graph_GraphvizWidget .node>ellipse,
.graph_GraphvizWidget .node>polyline,
.graph_GraphvizWidget .node>rect,
.graph_GraphvizWidget .cluster>path,
.graph_GraphvizWidget .cluster>polygon,
.graph_GraphvizWidget .cluster>ellipse,
.graph_GraphvizWidget .cluster>polyline,
.graph_GraphvizWidget .cluster>rect {
pointer-events: all;
}

.graph_GraphvizWidget .node.selected>path,
.graph_GraphvizWidget .node.selected>polygon,
.graph_GraphvizWidget .node.selected>ellipse,
.graph_GraphvizWidget .node.selected>polyline,
.graph_GraphvizWidget .node.selected>rect,
.graph_GraphvizWidget .cluster.selected>:is(path, polygon, ellipse, polyline, rect):first-of-type {
stroke: var(--gv-select-stroke);
}

.graph_GraphvizWidget .node>path:first-of-type,
.graph_GraphvizWidget .node>polygon:first-of-type,
.graph_GraphvizWidget .node>ellipse:first-of-type,
.graph_GraphvizWidget .node>polyline:first-of-type,
.graph_GraphvizWidget .cluster>path:first-of-type,
.graph_GraphvizWidget .cluster>polygon:first-of-type,
.graph_GraphvizWidget .cluster>ellipse:first-of-type,
.graph_GraphvizWidget .cluster>polyline:first-of-type {
fill: var(--gv-bg);
}

.graph_GraphvizWidget .node.selected>path:first-of-type,
.graph_GraphvizWidget .node.selected>polygon:first-of-type,
.graph_GraphvizWidget .node.selected>ellipse:first-of-type,
.graph_GraphvizWidget .node.selected>polyline:first-of-type,
.graph_GraphvizWidget .cluster.selected>path:first-of-type,
.graph_GraphvizWidget .cluster.selected>polygon:first-of-type,
.graph_GraphvizWidget .cluster.selected>ellipse:first-of-type,
.graph_GraphvizWidget .cluster.selected>polyline:first-of-type {
fill: var(--gv-select-fill);
}

.graph_GraphvizWidget .edge.selected path,
.graph_GraphvizWidget .edge.selected polygon,
.graph_GraphvizWidget .edge.selected ellipse,
.graph_GraphvizWidget .edge.selected polyline {
stroke: var(--gv-select-stroke);
}

.graph_GraphvizWidget .edge.selected polygon,
.graph_GraphvizWidget .edge.selected ellipse,
.graph_GraphvizWidget .edge.selected polyline {
fill: var(--gv-select-stroke);
}

.graph_GraphvizWidget text {
stroke: none;
fill: var(--gv-fg);
}

.graph_GraphvizWidget .selected text {
font-weight: bold;
stroke: none;
}

/* Generic state rules */
.graph_GraphvizWidget :is(.unknown, .complete, .failed, .running)>:is(path, polygon, ellipse, polyline) {
stroke: var(--_stroke);
}

.graph_GraphvizWidget :is(.unknown, .complete, .failed, .running):is(.node, .cluster)>:is(path, polygon, ellipse, polyline):first-of-type {
fill: var(--_fill);
}

.graph_GraphvizWidget :is(.unknown, .complete, .failed, .running).edge>:is(polygon, ellipse, polyline) {
fill: var(--_stroke);
}

.graph_GraphvizWidget .unknown {
--_stroke: var(--gv-unknown-stroke);
--_fill: var(--gv-unknown-fill);
}

.graph_GraphvizWidget .complete {
--_stroke: var(--gv-complete-stroke);
--_fill: var(--gv-complete-fill);
}

.graph_GraphvizWidget .failed {
--_stroke: var(--gv-failed-stroke);
--_fill: var(--gv-failed-fill);
}

.graph_GraphvizWidget .running {
--_stroke: var(--gv-running-stroke);
--_fill: var(--gv-running-fill);
}

/* Keep node and cluster outlines visible when zoomed out */
.graph_GraphvizWidget .node>path,
.graph_GraphvizWidget .node>polygon,
.graph_GraphvizWidget .node>ellipse,
.graph_GraphvizWidget .node>polyline,
.graph_GraphvizWidget .cluster>path,
.graph_GraphvizWidget .cluster>polygon,
.graph_GraphvizWidget .cluster>ellipse,
.graph_GraphvizWidget .cluster>polyline {
vector-effect: non-scaling-stroke;
stroke-width: 0.75px;
}
Loading
Loading