Skip to content

Commit

Permalink
adds support for setting opacity of text
Browse files Browse the repository at this point in the history
  • Loading branch information
nbond211 authored and davelandry committed Mar 19, 2018
1 parent 25c7282 commit f53f77d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/TextBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class TextBox extends BaseClass {
this._fontFamily = constant(["Roboto", "Helvetica Neue", "HelveticaNeue", "Helvetica", "Arial", "sans-serif"]);
this._fontMax = constant(50);
this._fontMin = constant(8);
this._fontOpacity = constant(1);
this._fontResize = constant(false);
this._fontSize = constant(10);
this._fontWeight = constant(400);
Expand Down Expand Up @@ -190,6 +191,7 @@ export default class TextBox extends BaseClass {
lines: lineData,
fC: this._fontColor(d, i),
fF: style["font-family"],
fO: this._fontOpacity(d, i),
fW: style["font-weight"],
id: this._id(d, i),
tA: this._textAnchor(d, i),
Expand Down Expand Up @@ -253,6 +255,8 @@ export default class TextBox extends BaseClass {
.style("font-size", `${d.fS}px`)
.attr("font-weight", d.fW)
.style("font-weight", d.fW)
.attr("opacity", d.fO)
.style("opacity", d.fO)
.attr("x", `${d.tA === "middle" ? d.w / 2 : rtl ? d.tA === "start" ? d.w : 0 : d.tA === "end" ? d.w : 0}px`)
.attr("y", (t, i) => `${(i + 1) * d.lH - (d.lH - d.fS)}px`);
}
Expand Down Expand Up @@ -382,6 +386,15 @@ function(text, line) {
return arguments.length ? (this._fontMin = typeof _ === "function" ? _ : constant(_), this) : this._fontMin;
}

/**
@memberof TextBox
@desc Sets the font opacity to the specified accessor function or static number between 0 and 1.
@param {Function|Number} [*value* = 1]
*/
fontOpacity(_) {
return arguments.length ? (this._fontOpacity = typeof _ === "function" ? _ : constant(_), this) : this._fontOpacity;
}

/**
@memberof TextBox
@desc Toggles font resizing, which can either be defined as a static boolean for all data points, or an accessor function that returns a boolean. See [this example](http://d3plus.org/examples/d3plus-text/resizing-text/) for a side-by-side comparison.
Expand Down

0 comments on commit f53f77d

Please sign in to comment.