@fishawack/lab-d3
Advanced tools
Comparing version 2.7.2 to 2.8.0
## Changelog | ||
### 2.8.0 (2021-03-09) | ||
* [Feature] Can now have line breaks in text by adding <br> tags | ||
### 2.7.2 (2021-03-03) | ||
@@ -4,0 +7,0 @@ * [Feature] Band and Point scales can now have their axis tick values hard coded |
{ | ||
"name": "@fishawack/lab-d3", | ||
"version": "2.7.2", | ||
"version": "2.8.0", | ||
"description": "Abstract layer built on top of d3", | ||
@@ -13,4 +13,5 @@ "scripts": { | ||
"test": "npm test --prefix node_modules/@fishawack/core/", | ||
"prepublishOnly": "rimraf src && mkdir src && npm test", | ||
"pretest": "rimraf src && mkdir src && babel _Build/js/ --out-dir src/ --ignore \"_Build/js/script.js\",\"_Build/js/archive/**/*.js\",\"_Build/js/generated/**/*.js\",\"_Build/js/libs/archive/**/*.js\",\"_Build/js/libs/*.js\"" | ||
"pretest": "rimraf src && mkdir src && babel _Build/js/ --out-dir src/ --ignore \"_Build/js/script.js\",\"_Build/js/archive/**/*.js\",\"_Build/js/generated/**/*.js\",\"_Build/js/libs/archive/**/*.js\",\"_Build/js/libs/*.js\"", | ||
"preversion": "lab-env test", | ||
"postversion": "git push && git push --tags && npm publish" | ||
}, | ||
@@ -17,0 +18,0 @@ "license": "BSD-3-Clause", |
@@ -134,26 +134,39 @@ "use strict"; | ||
text.each(function () { | ||
var text = d3.select(this), | ||
words = text.text().split(/\s+/).reverse(), | ||
word = words.pop(), | ||
line = [], | ||
lineNumber = 0, | ||
lineHeight = 1.1, | ||
// ems | ||
x = text.attr("x") || 0, | ||
y = text.attr("y") || 0, | ||
dy = parseFloat(text.attr("dy")) || 0, | ||
tspan = text.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", dy + "em"); | ||
var text = d3.select(this); | ||
var breaks = text.text().split(/<br>/).reverse(); | ||
var breakage = breaks.pop(); | ||
var line = []; | ||
var lineNumber = 0; | ||
var lineHeight = 1.1; // ems | ||
while (word) { | ||
line.push(word); | ||
tspan.text(line.join(" ")); | ||
var x = text.attr("x") || 0; | ||
var y = text.attr("y") || 0; | ||
var dy = parseFloat(text.attr("dy")) || 0; | ||
var tspan = text.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", dy + "em"); | ||
if (tspan.node().getComputedTextLength() > width && line.length > 1) { | ||
line.pop(); | ||
while (breakage != null) { | ||
var words = breakage.split(/\s+/).reverse(); | ||
var word = words.pop(); | ||
while (word != null) { | ||
line.push(word || " "); // Insert hidden   char when empty so height calculations are still accurate | ||
tspan.text(line.join(" ")); | ||
line = [word]; | ||
if (tspan.node().getComputedTextLength() > width && line.length > 1) { | ||
line.pop(); | ||
tspan.text(line.join(" ")); | ||
line = [word]; | ||
tspan = text.append("tspan").attr("x", x).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word); | ||
} | ||
word = words.pop(); | ||
} | ||
breakage = breaks.pop(); | ||
if (breakage != null) { | ||
tspan = text.append("tspan").attr("x", x).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word); | ||
line = []; | ||
} | ||
word = words.pop(); | ||
} | ||
@@ -160,0 +173,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
568206
5512