class PlotSVGMark extends Plot.Mark {
constructor(
data,
{
nodeType,
x,
x1,
x2,
y,
y1,
y2,
z,
r,
title,
fill,
fillOpacity,
stroke,
strokeOpacity,
strokeWidth,
transform,
...style
} = {}
) {
const [vr, cr] = maybeNumber(r, 3);
const [vfill, cfill] = maybeColor(fill, "none");
const [vstroke, cstroke] = maybeColor(
stroke,
cfill === "none" ? "currentColor" : "none"
);
const [vstrokewidth, cstrokewidth] = maybeNumber(strokeWidth, 1);
const [vfillopacity, cfillopacity] = maybeNumber(fillOpacity, 1);
const [vstrokeopacity, cstrokeopacity] = maybeNumber(strokeOpacity, 1);
super(
data,
[
{ name: "x", value: x, scale: "x", optional: true },
{ name: "x1", value: x1, scale: "x", optional: true },
{ name: "x2", value: x2, scale: "x", optional: true },
{ name: "y", value: y, scale: "y", optional: true },
{ name: "y1", value: y1, scale: "y", optional: true },
{ name: "y2", value: y2, scale: "y", optional: true },
{ name: "z", value: z, optional: true },
{ name: "r", value: vr, scale: "r", optional: true },
{ name: "title", value: title, optional: true },
{ name: "fill", value: vfill, scale: "color", optional: true },
{ name: "stroke", value: vstroke, scale: "color", optional: true },
{
name: "strokeWidth",
value: vstrokewidth,
// scale: "strokewidth", // 🌶 channel works, but not the scale
optional: true
},
{
name: "fillOpacity",
value: vfillopacity,
// scale: "fillopacity",
optional: true
},
{
name: "strokeOpacity",
value: vstrokeopacity,
// scale: "fillopacity",
optional: true
}
],
transform
);
this.nodeType = nodeType;
this.r = cr;
Style(this, {
fill: cfill,
fillOpacity: cfillopacity,
strokeOpacity: cstrokeopacity,
stroke: cstroke,
strokeWidth:
cstroke === "none"
? undefined
: cstrokewidth === undefined
? 1.5
: cstrokewidth,
...style
});
}
render(
I,
{ x, y, r, color, strokewidth },
{
x: X,
x1: X1,
x2: X2,
y: Y,
y1: Y1,
y2: Y2,
z: Z,
r: R,
title: L,
fill: F,
fillOpacity: FO,
stroke: S,
strokeOpacity: SO,
strokeWidth: SW
}
) {
const nodeType = this.nodeType;
let index = filter(I, X, X1, X2, Y, Y1, Y2);
mutable debug2 = { I, index, X, X1 };
if (R) index = index.filter(i => positive(R[i]));
if (Z) index.sort((i, j) => ascending(Z[i], Z[j]));
return create("svg:g")
.call(applyIndirectStyles, this)
.call(applyTransform, x, y, 0.5, 0.5)
.call(g =>
g
.selectAll()
.data(index)
.join(nodeType)
.call(applyDirectStyles, this)
.attr("fill", F && (i => (F[i])))
.attr("fill-opacity", FO && (i => clamp(FO[i], 0, 1)))
.attr("stroke", S && (i => (S[i])))
.attr("stroke-opacity", SO && (i => clamp(SO[i], 0, 1)))
.attr("stroke-width", SW && (i => Math.max(0, SW[i])))
.call(title(L))
)
.node();
}
}