Skip to content

Commit 9c84cdd

Browse files
mbostockFil
andauthored
href channel (#645)
* href channel * apply href and target to the line and area marks document * Update README * test plot for href (#647) * cheeky test plot for href * tweak test; add snapshot Co-authored-by: Mike Bostock <mbostock@gmail.com> Co-authored-by: Philippe Rivière <fil@rezo.net>
1 parent eb09fb7 commit 9c84cdd

File tree

16 files changed

+267
-25
lines changed

16 files changed

+267
-25
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ All marks support the following style options:
611611
* **shapeRendering** - the [shape-rendering mode](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/shape-rendering) (*e.g.*, *crispEdges*)
612612
* **dx** - horizontal offset (in pixels; defaults to 0)
613613
* **dy** - vertical offset (in pixels; defaults to 0)
614+
* **target** - link target (e.g., “_blank” for a new window); for use with the **href** channel
614615

615616
For all marks except [text](#plottextdata-options), the **dx** and **dy** options are rendered as a transform property, possibly including a 0.5px offset on low-density screens.
616617

@@ -623,6 +624,7 @@ All marks support the following optional channels:
623624
* **strokeWidth** - a stroke width (in pixels)
624625
* **opacity** - an object opacity; bound to the *opacity* scale
625626
* **title** - a tooltip (a string of text, possibly with newlines)
627+
* **href** - a URL to link to
626628

627629
The **fill**, **fillOpacity**, **stroke**, **strokeWidth**, **strokeOpacity**, and **opacity** options can be specified as either channels or constants. When the fill or stroke is specified as a function or array, it is interpreted as a channel; when the fill or stroke is specified as a string, it is interpreted as a constant if a valid CSS color and otherwise it is interpreted as a column name for a channel. Similarly when the fill opacity, stroke opacity, object opacity, stroke width, or radius is specified as a number, it is interpreted as a constant; otherwise it is interpreted as a channel.
628630

src/marks/area.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class Area extends Mark {
3838
.data(Z ? group(I, i => Z[i]).values() : [I])
3939
.join("path")
4040
.call(applyDirectStyles, this)
41-
.call(applyGroupedChannelStyles, channels)
41+
.call(applyGroupedChannelStyles, this, channels)
4242
.attr("d", shapeArea()
4343
.curve(this.curve)
4444
.defined(i => defined(X1[i]) && defined(Y1[i]) && defined(X2[i]) && defined(Y2[i]))

src/marks/bar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class AbstractBar extends Mark {
3636
.attr("height", this._height(scales, channels, dimensions))
3737
.call(applyAttr, "rx", rx)
3838
.call(applyAttr, "ry", ry)
39-
.call(applyChannelStyles, channels))
39+
.call(applyChannelStyles, this, channels))
4040
.node();
4141
}
4242
_x(scales, {x: X}, {marginLeft}) {

src/marks/dot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class Dot extends Mark {
4545
.attr("cx", X ? i => X[i] : (marginLeft + width - marginRight) / 2)
4646
.attr("cy", Y ? i => Y[i] : (marginTop + height - marginBottom) / 2)
4747
.attr("r", R ? i => R[i] : this.r)
48-
.call(applyChannelStyles, channels))
48+
.call(applyChannelStyles, this, channels))
4949
.node();
5050
}
5151
}

src/marks/image.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class Image extends Mark {
8383
.call(applyAttr, "href", S ? i => S[i] : this.src)
8484
.call(applyAttr, "preserveAspectRatio", this.preserveAspectRatio)
8585
.call(applyAttr, "crossorigin", this.crossOrigin)
86-
.call(applyChannelStyles, channels))
86+
.call(applyChannelStyles, this, channels))
8787
.node();
8888
}
8989
}

src/marks/line.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class Line extends Mark {
3636
.data(Z ? group(I, i => Z[i]).values() : [I])
3737
.join("path")
3838
.call(applyDirectStyles, this)
39-
.call(applyGroupedChannelStyles, channels)
39+
.call(applyGroupedChannelStyles, this, channels)
4040
.attr("d", shapeLine()
4141
.curve(this.curve)
4242
.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
@@ -46,7 +46,7 @@ export class Link extends Mark {
4646
c.lineEnd();
4747
return `${p}`;
4848
})
49-
.call(applyChannelStyles, channels))
49+
.call(applyChannelStyles, this, channels))
5050
.node();
5151
}
5252
}

src/marks/rect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class Rect extends Mark {
6060
.attr("height", Y1 && Y2 && !isCollapsed(y) ? i => Math.max(0, Math.abs(Y1[i] - Y2[i]) - insetTop - insetBottom) : height - marginTop - marginBottom - insetTop - insetBottom)
6161
.call(applyAttr, "rx", rx)
6262
.call(applyAttr, "ry", ry)
63-
.call(applyChannelStyles, channels))
63+
.call(applyChannelStyles, this, channels))
6464
.node();
6565
}
6666
}

src/marks/rule.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class RuleX extends Mark {
4949
.attr("x2", X ? i => X[i] : (marginLeft + width - marginRight) / 2)
5050
.attr("y1", Y1 && !isCollapsed(y) ? i => Y1[i] + insetTop : marginTop + insetTop)
5151
.attr("y2", Y2 && !isCollapsed(y) ? (y.bandwidth ? i => Y2[i] + y.bandwidth() - insetBottom : i => Y2[i] - insetBottom) : height - marginBottom - insetBottom)
52-
.call(applyChannelStyles, channels))
52+
.call(applyChannelStyles, this, channels))
5353
.node();
5454
}
5555
}
@@ -93,7 +93,7 @@ export class RuleY extends Mark {
9393
.attr("x2", X2 && !isCollapsed(x) ? (x.bandwidth ? i => X2[i] + x.bandwidth() - insetRight : i => X2[i] - insetRight) : width - marginRight - insetRight)
9494
.attr("y1", Y ? i => Y[i] : (marginTop + height - marginBottom) / 2)
9595
.attr("y2", Y ? i => Y[i] : (marginTop + height - marginBottom) / 2)
96-
.call(applyChannelStyles, channels))
96+
.call(applyChannelStyles, this, channels))
9797
.node();
9898
}
9999
}

src/marks/text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class Text extends Mark {
7272
: text => text.attr("x", X ? i => X[i] : cx).attr("y", Y ? i => Y[i] : cy))
7373
.call(applyAttr, "font-size", FS && (i => FS[i]))
7474
.text(i => T[i])
75-
.call(applyChannelStyles, channels))
75+
.call(applyChannelStyles, this, channels))
7676
.node();
7777
}
7878
}

0 commit comments

Comments
 (0)