Skip to content
Open
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
11 changes: 9 additions & 2 deletions src/marker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {create} from "./context.js";
import {unset} from "./memoize.js";
import {keyof} from "./options.js";
import {isNoneish, keyof} from "./options.js";

export function markers(mark, {marker, markerStart = marker, markerMid = marker, markerEnd = marker} = {}) {
mark.markerStart = maybeMarker(markerStart);
Expand Down Expand Up @@ -144,7 +144,13 @@ function getGroupedOrientation(path, Z) {
return ([i]) => O[i];
}

function applyMarkersColor(path, {markerStart, markerMid, markerEnd, stroke}, strokeof = () => stroke, Z, context) {
function applyMarkersColor(
path,
{markerStart, markerMid, markerEnd, stroke, strokeDasharray},
strokeof = () => stroke,
Z,
context
) {
if (!markerStart && !markerMid && !markerEnd) return;
const iriByMarkerColor = new Map();
const orient = Z && getGroupedOrientation(path, Z);
Expand All @@ -158,6 +164,7 @@ function applyMarkersColor(path, {markerStart, markerMid, markerEnd, stroke}, st
let iri = iriByColor.get(color);
if (!iri) {
const node = this.parentNode.insertBefore(marker(color, context), this);
if (!isNoneish(strokeDasharray)) node.setAttribute("stroke-dasharray", "none");
const id = `plot-marker-${++nextMarkerId}`;
node.setAttribute("id", id);
iriByColor.set(color, (iri = `url(#${id})`));
Expand Down
28 changes: 28 additions & 0 deletions test/output/markerDasharray.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions test/plots/markers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import * as Plot from "@observablehq/plot";

export async function markerDasharray() {
return Plot.plot({
axis: null,
inset: 20,
marks: [
Plot.lineY(
[
[0, 5],
[5, 2],
[10, 0]
],
{
x: (d) => d[0],
y: (d) => d[1],
strokeDasharray: "1,10",
strokeWidth: 3,
markerStart: "dot",
markerMid: "arrow",
markerEnd: "circle-stroke"
}
)
]
});
}

export async function markerRuleX() {
return Plot.ruleX([1, 2, 3], {marker: "arrow-reverse", inset: 3}).plot();
}
Expand Down
Loading