Skip to content

Commit 4dd62d2

Browse files
committed
area and line titles
fixes #94
1 parent a362a0d commit 4dd62d2

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

src/mark.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ export function title(L) {
186186
.text(i => L[i]) : () => {};
187187
}
188188

189+
// title for groups (lines, areas).
190+
export function titleGroup(L) {
191+
return L ? selection => selection
192+
.filter(([i]) => nonempty(L[i]))
193+
.append("title")
194+
.text(([i]) => L[i]) : () => {};
195+
}
196+
189197
// Returns a Uint32Array with elements [0, 1, 2, … data.length - 1].
190198
export function range(data) {
191199
return Uint32Array.from(data, indexOf);

src/marks/area.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {create} from "d3-selection";
33
import {area as shapeArea} from "d3-shape";
44
import {Curve} from "../curve.js";
55
import {defined} from "../defined.js";
6-
import {Mark, indexOf, maybeColor, maybeZero, maybeSort, title} from "../mark.js";
6+
import {Mark, indexOf, maybeColor, maybeZero, maybeSort, titleGroup} from "../mark.js";
77
import {Style, applyDirectStyles, applyIndirectStyles, applyTransform} from "../style.js";
88

99
export class Area extends Mark {
@@ -62,7 +62,7 @@ export class Area extends Mark {
6262
.y0(i => y(Y1[i]))
6363
.x1(i => x(X2[i]))
6464
.y1(i => y(Y2[i])))
65-
.call(title(L)))
65+
.call(titleGroup(L)))
6666
.node();
6767
}
6868
}

src/marks/line.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {create} from "d3-selection";
33
import {line as shapeLine} from "d3-shape";
44
import {Curve} from "../curve.js";
55
import {defined} from "../defined.js";
6-
import {Mark, indexOf, identity, first, second, maybeColor, maybeSort, title} from "../mark.js";
6+
import {Mark, indexOf, identity, first, second, maybeColor, maybeSort, titleGroup} from "../mark.js";
77
import {Style, applyDirectStyles, applyIndirectStyles, applyTransform} from "../style.js";
88

99
export class Line extends Mark {
@@ -61,7 +61,7 @@ export class Line extends Mark {
6161
.defined(i => defined(X[i]) && defined(Y[i]))
6262
.x(i => x(X[i]))
6363
.y(i => y(Y[i])))
64-
.call(title(L)))
64+
.call(titleGroup(L)))
6565
.node();
6666
}
6767
}

0 commit comments

Comments
 (0)