Skip to content

Commit 8c2a818

Browse files
committed
tick marker
1 parent 7452deb commit 8c2a818

File tree

6 files changed

+399
-2
lines changed

6 files changed

+399
-2
lines changed

src/marker.d.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,20 @@
77
* - *circle-fill* - a filled circle with a white stroke and 3px radius
88
* - *circle-stroke* - a stroked circle with a white fill and 3px radius
99
* - *circle* - alias for *circle-fill*
10+
* - *tick* - a small opposing line
11+
* - *tick-x* - a small horizontal opposing line
12+
* - *tick-y* - a small vertical opposing line
1013
*/
11-
export type MarkerName = "arrow" | "arrow-reverse" | "dot" | "circle" | "circle-fill" | "circle-stroke";
14+
export type MarkerName =
15+
| "arrow"
16+
| "arrow-reverse"
17+
| "dot"
18+
| "circle"
19+
| "circle-fill"
20+
| "circle-stroke"
21+
| "tick"
22+
| "tick-x"
23+
| "tick-y";
1224

1325
/** A custom marker implementation. */
1426
export type MarkerFunction = (color: string, context: {document: Document}) => SVGMarkerElement;

src/marker.js

+18
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ function maybeMarker(marker) {
2424
return markerCircleFill;
2525
case "circle-stroke":
2626
return markerCircleStroke;
27+
case "tick":
28+
return markerTick("auto");
29+
case "tick-x":
30+
return markerTick(90);
31+
case "tick-y":
32+
return markerTick(0);
2733
}
2834
throw new Error(`invalid marker: ${marker}`);
2935
}
@@ -79,6 +85,18 @@ function markerCircleStroke(color, context) {
7985
.node();
8086
}
8187

88+
function markerTick(orient) {
89+
return (color, context) =>
90+
create("svg:marker", context)
91+
.attr("viewBox", "-3 -3 6 6")
92+
.attr("markerWidth", 6)
93+
.attr("markerHeight", 6)
94+
.attr("orient", orient)
95+
.attr("stroke", color)
96+
.call((marker) => marker.append("path").attr("d", "M0,-3v6"))
97+
.node();
98+
}
99+
82100
let nextMarkerId = 0;
83101

84102
export function applyMarkers(path, mark, {stroke: S}, context) {

test/output/errorBarX.svg

+164
Loading

0 commit comments

Comments
 (0)