Skip to content

Commit bc06f41

Browse files
committed
fix for constant stroke
1 parent 040ba24 commit bc06f41

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/marks/line.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {defined} from "../defined.js";
44
import {Mark} from "../plot.js";
55
import {indexOf, identity, maybeTuple, maybeZ} from "../options.js";
66
import {applyDirectStyles, applyIndirectStyles, applyTransform, applyGroupedChannelStyles, offset} from "../style.js";
7-
import {applyMarkers, markers} from "./marker.js";
7+
import {applyGroupedMarkers, markers} from "./marker.js";
88

99
const defaults = {
1010
ariaLabel: "line",
@@ -41,7 +41,7 @@ export class Line extends Mark {
4141
.join("path")
4242
.call(applyDirectStyles, this)
4343
.call(applyGroupedChannelStyles, this, channels)
44-
.call(applyMarkers, this)
44+
.call(applyGroupedMarkers, this, channels)
4545
.attr("d", shapeLine()
4646
.curve(this.curve)
4747
.defined(i => defined(X[i]) && defined(Y[i]))

src/marks/link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class Link extends Mark {
3939
.join("path")
4040
.call(applyDirectStyles, this)
4141
.call(applyChannelStyles, this, channels)
42-
.call(applyMarkers, this)
42+
.call(applyMarkers, this, channels)
4343
.attr("d", i => {
4444
const p = path();
4545
const c = curve(p);

src/marks/marker.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,20 @@ function markerCircleStroke(color) {
6565

6666
let nextMarkerId = 0;
6767

68-
export function applyMarkers(path, {markerStart, markerMid, markerEnd}) {
69-
if (!(markerStart || markerMid || markerEnd)) return;
68+
export function applyMarkers(path, mark, {stroke: S}) {
69+
return applyMarkersColor(path, mark, S && (i => S[i]));
70+
}
71+
72+
export function applyGroupedMarkers(path, mark, {stroke: S}) {
73+
return applyMarkersColor(path, mark, S && (([i]) => S[i]));
74+
}
75+
76+
function applyMarkersColor(path, {markerStart, markerMid, markerEnd, stroke}, strokeof = () => stroke) {
7077
const iriByMarkerColor = new Map();
71-
path.each(function() {
72-
const color = this.getAttribute("stroke");
73-
const applyMarker = (name, marker) => {
78+
79+
function applyMarker(marker) {
80+
return function(i) {
81+
const color = strokeof(i);
7482
let iriByColor = iriByMarkerColor.get(marker);
7583
if (!iriByColor) iriByMarkerColor.set(marker, iriByColor = new Map());
7684
let iri = iriByColor.get(color);
@@ -80,10 +88,11 @@ export function applyMarkers(path, {markerStart, markerMid, markerEnd}) {
8088
node.setAttribute("id", id);
8189
iriByColor.set(color, iri = `url(#${id})`);
8290
}
83-
this.setAttribute(name, iri);
91+
return iri;
8492
};
85-
if (markerStart) applyMarker("marker-start", markerStart);
86-
if (markerMid) applyMarker("marker-mid", markerMid);
87-
if (markerEnd) applyMarker("marker-end", markerEnd);
88-
});
93+
}
94+
95+
if (markerStart) path.attr("marker-start", applyMarker(markerStart));
96+
if (markerMid) path.attr("marker-mid", applyMarker(markerMid));
97+
if (markerEnd) path.attr("marker-end", applyMarker(markerEnd));
8998
}

0 commit comments

Comments
 (0)