d3plus-text
Advanced tools
Comparing version 0.9.18 to 0.9.19
/* | ||
d3plus-text v0.9.18 | ||
d3plus-text v0.9.19 | ||
A smart SVG text box with line wrapping and automatic font size scaling. | ||
@@ -10,3 +10,3 @@ Copyright (c) 2017 D3plus - https://d3plus.org | ||
typeof define === 'function' && define.amd ? define('d3plus-text', ['exports', 'd3-selection', 'd3-transition', 'd3-array', 'd3plus-common'], factory) : | ||
(factory((global.d3plus = global.d3plus || {}),global.d3Selection,global.d3Transition,global.d3Array,global.d3plusCommon)); | ||
(factory((global.d3plus = {}),global.d3Selection,global.d3Transition,global.d3Array,global.d3plusCommon)); | ||
}(this, (function (exports,d3Selection,d3Transition,d3Array,d3plusCommon) { 'use strict'; | ||
@@ -49,2 +49,29 @@ | ||
/** | ||
@function trim | ||
@desc Cross-browser implementation of [trim](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim). | ||
@param {String} str | ||
*/ | ||
function trim(str) { | ||
return str.replace(/^\s+|\s+$/g, ""); | ||
} | ||
/** | ||
@function trimLeft | ||
@desc Cross-browser implementation of [trimLeft](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/TrimLeft). | ||
@param {String} str | ||
*/ | ||
function trimLeft(str) { | ||
return str.replace(/^\s+/, ""); | ||
} | ||
/** | ||
@function trimRight | ||
@desc Cross-browser implementation of [trimRight](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/TrimRight). | ||
@param {String} str | ||
*/ | ||
function trimRight(str) { | ||
return str.replace(/\s+$/, ""); | ||
} | ||
var alpha = "abcdefghiABCDEFGHI_!@#$%^&*()_+1234567890"; | ||
@@ -75,3 +102,3 @@ var checked = {}; | ||
if (!(font instanceof Array)) { font = font.split(","); } | ||
font = font.map(function (f) { return f.trim(); }); | ||
font = font.map(function (f) { return trim(f); }); | ||
@@ -263,3 +290,3 @@ for (var i = 0; i < font.length; i++) { | ||
} | ||
lineData[line - 1] = lineData[line - 1].trimRight(); | ||
lineData[line - 1] = trimRight(lineData[line - 1]); | ||
line++; | ||
@@ -364,3 +391,3 @@ if (lineHeight * line > height || wordWidth > width && !overflow) { | ||
/** | ||
@function TextBox | ||
@class TextBox | ||
@extends BaseClass | ||
@@ -596,3 +623,3 @@ @desc Creates a wrapped text box for each point in an array of data. See [this example](https://d3plus.org/examples/d3plus-text/getting-started/) for help getting started using the textBox function. | ||
tspan | ||
.text(function (t) { return t.trimRight(); }) | ||
.text(function (t) { return trimRight(t); }) | ||
.attr("x", ((d.x) + "px")) | ||
@@ -957,2 +984,5 @@ .attr("dx", (dx + "px")) | ||
exports.titleCase = titleCase; | ||
exports.trim = trim; | ||
exports.trimLeft = trimLeft; | ||
exports.trimRight = trimRight; | ||
@@ -959,0 +989,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
/* | ||
d3plus-text v0.9.18 | ||
d3plus-text v0.9.19 | ||
A smart SVG text box with line wrapping and automatic font size scaling. | ||
@@ -7,2 +7,2 @@ Copyright (c) 2017 D3plus - https://d3plus.org | ||
*/ | ||
(function(u,t){typeof exports==="object"&&typeof module!=="undefined"?t(exports,require("d3-selection"),require("d3-transition"),require("d3-array"),require("d3plus-common")):typeof define==="function"&&define.amd?define("d3plus-text",["exports","d3-selection","d3-transition","d3-array","d3plus-common"],t):t(u.d3plus=u.d3plus||{},u.d3Selection,u.d3Transition,u.d3Array,u.d3plusCommon)})(this,function(u,t,n,e,i){"use strict";var r=function(u,t){t=Object.assign({"font-size":10,"font-family":"sans-serif","font-style":"normal","font-weight":400,"font-variant":"normal"},t);var n=document.createElement("canvas").getContext("2d");var e=[];e.push(t["font-style"]);e.push(t["font-variant"]);e.push(t["font-weight"]);e.push(typeof t["font-size"]==="string"?t["font-size"]:t["font-size"]+"px");e.push(t["font-family"]);n.font=e.join(" ");if(u instanceof Array){return u.map(function(u){return n.measureText(u).width})}return n.measureText(u).width};var o="abcdefghiABCDEFGHI_!@#$%^&*()_+1234567890";var A={};var s=32;var a;var f;var B;var C;var D=function(u){if(!a){a=r(o,{"font-family":"DejaVuSans","font-size":s});f=r(o,{"font-family":"-apple-system","font-size":s});B=r(o,{"font-family":"monospace","font-size":s});C=r(o,{"font-family":"sans-serif","font-size":s})}if(!(u instanceof Array)){u=u.split(",")}u=u.map(function(u){return u.trim()});for(var t=0;t<u.length;t++){var n=u[t];if(A[n]||["-apple-system","monospace","sans-serif","DejaVuSans"].includes(n)){return n}else if(A[n]===false){continue}var e=r(o,{"font-family":n,"font-size":s});A[n]=e!==B;if(A[n]){A[n]=e!==C}if(f&&A[n]){A[n]=e!==f}if(a&&A[n]){A[n]=e!==a}if(A[n]){return n}}return false};var E=function(u){if(u===void 0){u="undefined"}else if(!(typeof u==="string"||u instanceof String)){u=JSON.stringify(u)}return u};var F=[[/[\300-\305]/g,"A"],[/[\340-\345]/g,"a"],[/[\306]/g,"AE"],[/[\346]/g,"ae"],[/[\337]/g,"B"],[/[\307]/g,"C"],[/[\347]/g,"c"],[/[\320\336\376]/g,"D"],[/[\360]/g,"d"],[/[\310-\313]/g,"E"],[/[\350-\353]/g,"e"],[/[\314-\317]/g,"I"],[/[\354-\357]/g,"i"],[/[\321]/g,"N"],[/[\361]/g,"n"],[/[\322-\326\330]/g,"O"],[/[\362-\366\370]/g,"o"],[/[\331-\334]/g,"U"],[/[\371-\374]/g,"u"],[/[\327]/g,"x"],[/[\335]/g,"Y"],[/[\375\377]/g,"y"]];var h=function(u){return(""+u).replace(/[^A-Za-z0-9\-_]/g,function(u){if(u===" "){return"-"}var t=false;for(var n=0;n<F.length;n++){if(new RegExp(F[n][0]).test(u)){t=F[n][1];break}}return t||""})};var l=["u0903","u093B","u093E","u093F","u0940","u0949","u094A","u094B","u094C","u094E","u094F","u0982","u0983","u09BE","u09BF","u09C0","u09C7","u09C8","u09CB","u09CC","u09D7","u0A03","u0A3E","u0A3F","u0A40","u0A83","u0ABE","u0ABF","u0AC0","u0AC9","u0ACB","u0ACC","u0B02","u0B03","u0B3E","u0B40","u0B47","u0B48","u0B4B","u0B4C","u0B57","u0BBE","u0BBF","u0BC1","u0BC2","u0BC6","u0BC7","u0BC8","u0BCA","u0BCB","u0BCC","u0BD7","u0C01","u0C02","u0C03","u0C41","u0C42","u0C43","u0C44","u0C82","u0C83","u0CBE","u0CC0","u0CC1","u0CC2","u0CC3","u0CC4","u0CC7","u0CC8","u0CCA","u0CCB","u0CD5","u0CD6","u0D02","u0D03","u0D3E","u0D3F","u0D40","u0D46","u0D47","u0D48","u0D4A","u0D4B","u0D4C","u0D57","u0D82","u0D83","u0DCF","u0DD0","u0DD1","u0DD8","u0DD9","u0DDA","u0DDB","u0DDC","u0DDD","u0DDE","u0DDF","u0DF2","u0DF3","u0F3E","u0F3F","u0F7F","u102B","u102C","u1031","u1038","u103B","u103C","u1056","u1057","u1062","u1063","u1064","u1067","u1068","u1069","u106A","u106B","u106C","u106D","u1083","u1084","u1087","u1088","u1089","u108A","u108B","u108C","u108F","u109A","u109B","u109C","u17B6","u17BE","u17BF","u17C0","u17C1","u17C2","u17C3","u17C4","u17C5","u17C7","u17C8","u1923","u1924","u1925","u1926","u1929","u192A","u192B","u1930","u1931","u1933","u1934","u1935","u1936","u1937","u1938","u1A19","u1A1A","u1A55","u1A57","u1A61","u1A63","u1A64","u1A6D","u1A6E","u1A6F","u1A70","u1A71","u1A72","u1B04","u1B35","u1B3B","u1B3D","u1B3E","u1B3F","u1B40","u1B41","u1B43","u1B44","u1B82","u1BA1","u1BA6","u1BA7","u1BAA","u1BE7","u1BEA","u1BEB","u1BEC","u1BEE","u1BF2","u1BF3","u1C24","u1C25","u1C26","u1C27","u1C28","u1C29","u1C2A","u1C2B","u1C34","u1C35","u1CE1","u1CF2","u1CF3","u302E","u302F","uA823","uA824","uA827","uA880","uA881","uA8B4","uA8B5","uA8B6","uA8B7","uA8B8","uA8B9","uA8BA","uA8BB","uA8BC","uA8BD","uA8BE","uA8BF","uA8C0","uA8C1","uA8C2","uA8C3","uA952","uA953","uA983","uA9B4","uA9B5","uA9BA","uA9BB","uA9BD","uA9BE","uA9BF","uA9C0","uAA2F","uAA30","uAA33","uAA34","uAA4D","uAA7B","uAA7D","uAAEB","uAAEE","uAAEF","uAAF5","uABE3","uABE4","uABE6","uABE7","uABE9","uABEA","uABEC"];var c=["u0300","u0301","u0302","u0303","u0304","u0305","u0306","u0307","u0308","u0309","u030A","u030B","u030C","u030D","u030E","u030F","u0310","u0311","u0312","u0313","u0314","u0315","u0316","u0317","u0318","u0319","u031A","u031B","u031C","u031D","u031E","u031F","u0320","u0321","u0322","u0323","u0324","u0325","u0326","u0327","u0328","u0329","u032A","u032B","u032C","u032D","u032E","u032F","u0330","u0331","u0332","u0333","u0334","u0335","u0336","u0337","u0338","u0339","u033A","u033B","u033C","u033D","u033E","u033F","u0340","u0341","u0342","u0343","u0344","u0345","u0346","u0347","u0348","u0349","u034A","u034B","u034C","u034D","u034E","u034F","u0350","u0351","u0352","u0353","u0354","u0355","u0356","u0357","u0358","u0359","u035A","u035B","u035C","u035D","u035E","u035F","u0360","u0361","u0362","u0363","u0364","u0365","u0366","u0367","u0368","u0369","u036A","u036B","u036C","u036D","u036E","u036F","u0483","u0484","u0485","u0486","u0487","u0591","u0592","u0593","u0594","u0595","u0596","u0597","u0598","u0599","u059A","u059B","u059C","u059D","u059E","u059F","u05A0","u05A1","u05A2","u05A3","u05A4","u05A5","u05A6","u05A7","u05A8","u05A9","u05AA","u05AB","u05AC","u05AD","u05AE","u05AF","u05B0","u05B1","u05B2","u05B3","u05B4","u05B5","u05B6","u05B7","u05B8","u05B9","u05BA","u05BB","u05BC","u05BD","u05BF","u05C1","u05C2","u05C4","u05C5","u05C7","u0610","u0611","u0612","u0613","u0614","u0615","u0616","u0617","u0618","u0619","u061A","u064B","u064C","u064D","u064E","u064F","u0650","u0651","u0652","u0653","u0654","u0655","u0656","u0657","u0658","u0659","u065A","u065B","u065C","u065D","u065E","u065F","u0670","u06D6","u06D7","u06D8","u06D9","u06DA","u06DB","u06DC","u06DF","u06E0","u06E1","u06E2","u06E3","u06E4","u06E7","u06E8","u06EA","u06EB","u06EC","u06ED","u0711","u0730","u0731","u0732","u0733","u0734","u0735","u0736","u0737","u0738","u0739","u073A","u073B","u073C","u073D","u073E","u073F","u0740","u0741","u0742","u0743","u0744","u0745","u0746","u0747","u0748","u0749","u074A","u07A6","u07A7","u07A8","u07A9","u07AA","u07AB","u07AC","u07AD","u07AE","u07AF","u07B0","u07EB","u07EC","u07ED","u07EE","u07EF","u07F0","u07F1","u07F2","u07F3","u0816","u0817","u0818","u0819","u081B","u081C","u081D","u081E","u081F","u0820","u0821","u0822","u0823","u0825","u0826","u0827","u0829","u082A","u082B","u082C","u082D","u0859","u085A","u085B","u08E3","u08E4","u08E5","u08E6","u08E7","u08E8","u08E9","u08EA","u08EB","u08EC","u08ED","u08EE","u08EF","u08F0","u08F1","u08F2","u08F3","u08F4","u08F5","u08F6","u08F7","u08F8","u08F9","u08FA","u08FB","u08FC","u08FD","u08FE","u08FF","u0900","u0901","u0902","u093A","u093C","u0941","u0942","u0943","u0944","u0945","u0946","u0947","u0948","u094D","u0951","u0952","u0953","u0954","u0955","u0956","u0957","u0962","u0963","u0981","u09BC","u09C1","u09C2","u09C3","u09C4","u09CD","u09E2","u09E3","u0A01","u0A02","u0A3C","u0A41","u0A42","u0A47","u0A48","u0A4B","u0A4C","u0A4D","u0A51","u0A70","u0A71","u0A75","u0A81","u0A82","u0ABC","u0AC1","u0AC2","u0AC3","u0AC4","u0AC5","u0AC7","u0AC8","u0ACD","u0AE2","u0AE3","u0B01","u0B3C","u0B3F","u0B41","u0B42","u0B43","u0B44","u0B4D","u0B56","u0B62","u0B63","u0B82","u0BC0","u0BCD","u0C00","u0C3E","u0C3F","u0C40","u0C46","u0C47","u0C48","u0C4A","u0C4B","u0C4C","u0C4D","u0C55","u0C56","u0C62","u0C63","u0C81","u0CBC","u0CBF","u0CC6","u0CCC","u0CCD","u0CE2","u0CE3","u0D01","u0D41","u0D42","u0D43","u0D44","u0D4D","u0D62","u0D63","u0DCA","u0DD2","u0DD3","u0DD4","u0DD6","u0E31","u0E34","u0E35","u0E36","u0E37","u0E38","u0E39","u0E3A","u0E47","u0E48","u0E49","u0E4A","u0E4B","u0E4C","u0E4D","u0E4E","u0EB1","u0EB4","u0EB5","u0EB6","u0EB7","u0EB8","u0EB9","u0EBB","u0EBC","u0EC8","u0EC9","u0ECA","u0ECB","u0ECC","u0ECD","u0F18","u0F19","u0F35","u0F37","u0F39","u0F71","u0F72","u0F73","u0F74","u0F75","u0F76","u0F77","u0F78","u0F79","u0F7A","u0F7B","u0F7C","u0F7D","u0F7E","u0F80","u0F81","u0F82","u0F83","u0F84","u0F86","u0F87","u0F8D","u0F8E","u0F8F","u0F90","u0F91","u0F92","u0F93","u0F94","u0F95","u0F96","u0F97","u0F99","u0F9A","u0F9B","u0F9C","u0F9D","u0F9E","u0F9F","u0FA0","u0FA1","u0FA2","u0FA3","u0FA4","u0FA5","u0FA6","u0FA7","u0FA8","u0FA9","u0FAA","u0FAB","u0FAC","u0FAD","u0FAE","u0FAF","u0FB0","u0FB1","u0FB2","u0FB3","u0FB4","u0FB5","u0FB6","u0FB7","u0FB8","u0FB9","u0FBA","u0FBB","u0FBC","u0FC6","u102D","u102E","u102F","u1030","u1032","u1033","u1034","u1035","u1036","u1037","u1039","u103A","u103D","u103E","u1058","u1059","u105E","u105F","u1060","u1071","u1072","u1073","u1074","u1082","u1085","u1086","u108D","u109D","u135D","u135E","u135F","u1712","u1713","u1714","u1732","u1733","u1734","u1752","u1753","u1772","u1773","u17B4","u17B5","u17B7","u17B8","u17B9","u17BA","u17BB","u17BC","u17BD","u17C6","u17C9","u17CA","u17CB","u17CC","u17CD","u17CE","u17CF","u17D0","u17D1","u17D2","u17D3","u17DD","u180B","u180C","u180D","u18A9","u1920","u1921","u1922","u1927","u1928","u1932","u1939","u193A","u193B","u1A17","u1A18","u1A1B","u1A56","u1A58","u1A59","u1A5A","u1A5B","u1A5C","u1A5D","u1A5E","u1A60","u1A62","u1A65","u1A66","u1A67","u1A68","u1A69","u1A6A","u1A6B","u1A6C","u1A73","u1A74","u1A75","u1A76","u1A77","u1A78","u1A79","u1A7A","u1A7B","u1A7C","u1A7F","u1AB0","u1AB1","u1AB2","u1AB3","u1AB4","u1AB5","u1AB6","u1AB7","u1AB8","u1AB9","u1ABA","u1ABB","u1ABC","u1ABD","u1B00","u1B01","u1B02","u1B03","u1B34","u1B36","u1B37","u1B38","u1B39","u1B3A","u1B3C","u1B42","u1B6B","u1B6C","u1B6D","u1B6E","u1B6F","u1B70","u1B71","u1B72","u1B73","u1B80","u1B81","u1BA2","u1BA3","u1BA4","u1BA5","u1BA8","u1BA9","u1BAB","u1BAC","u1BAD","u1BE6","u1BE8","u1BE9","u1BED","u1BEF","u1BF0","u1BF1","u1C2C","u1C2D","u1C2E","u1C2F","u1C30","u1C31","u1C32","u1C33","u1C36","u1C37","u1CD0","u1CD1","u1CD2","u1CD4","u1CD5","u1CD6","u1CD7","u1CD8","u1CD9","u1CDA","u1CDB","u1CDC","u1CDD","u1CDE","u1CDF","u1CE0","u1CE2","u1CE3","u1CE4","u1CE5","u1CE6","u1CE7","u1CE8","u1CED","u1CF4","u1CF8","u1CF9","u1DC0","u1DC1","u1DC2","u1DC3","u1DC4","u1DC5","u1DC6","u1DC7","u1DC8","u1DC9","u1DCA","u1DCB","u1DCC","u1DCD","u1DCE","u1DCF","u1DD0","u1DD1","u1DD2","u1DD3","u1DD4","u1DD5","u1DD6","u1DD7","u1DD8","u1DD9","u1DDA","u1DDB","u1DDC","u1DDD","u1DDE","u1DDF","u1DE0","u1DE1","u1DE2","u1DE3","u1DE4","u1DE5","u1DE6","u1DE7","u1DE8","u1DE9","u1DEA","u1DEB","u1DEC","u1DED","u1DEE","u1DEF","u1DF0","u1DF1","u1DF2","u1DF3","u1DF4","u1DF5","u1DFC","u1DFD","u1DFE","u1DFF","u20D0","u20D1","u20D2","u20D3","u20D4","u20D5","u20D6","u20D7","u20D8","u20D9","u20DA","u20DB","u20DC","u20E1","u20E5","u20E6","u20E7","u20E8","u20E9","u20EA","u20EB","u20EC","u20ED","u20EE","u20EF","u20F0","u2CEF","u2CF0","u2CF1","u2D7F","u2DE0","u2DE1","u2DE2","u2DE3","u2DE4","u2DE5","u2DE6","u2DE7","u2DE8","u2DE9","u2DEA","u2DEB","u2DEC","u2DED","u2DEE","u2DEF","u2DF0","u2DF1","u2DF2","u2DF3","u2DF4","u2DF5","u2DF6","u2DF7","u2DF8","u2DF9","u2DFA","u2DFB","u2DFC","u2DFD","u2DFE","u2DFF","u302A","u302B","u302C","u302D","u3099","u309A","uA66F","uA674","uA675","uA676","uA677","uA678","uA679","uA67A","uA67B","uA67C","uA67D","uA69E","uA69F","uA6F0","uA6F1","uA802","uA806","uA80B","uA825","uA826","uA8C4","uA8E0","uA8E1","uA8E2","uA8E3","uA8E4","uA8E5","uA8E6","uA8E7","uA8E8","uA8E9","uA8EA","uA8EB","uA8EC","uA8ED","uA8EE","uA8EF","uA8F0","uA8F1","uA926","uA927","uA928","uA929","uA92A","uA92B","uA92C","uA92D","uA947","uA948","uA949","uA94A","uA94B","uA94C","uA94D","uA94E","uA94F","uA950","uA951","uA980","uA981","uA982","uA9B3","uA9B6","uA9B7","uA9B8","uA9B9","uA9BC","uA9E5","uAA29","uAA2A","uAA2B","uAA2C","uAA2D","uAA2E","uAA31","uAA32","uAA35","uAA36","uAA43","uAA4C","uAA7C","uAAB0","uAAB2","uAAB3","uAAB4","uAAB7","uAAB8","uAABE","uAABF","uAAC1","uAAEC","uAAED","uAAF6","uABE5","uABE8","uABED","uFB1E","uFE00","uFE01","uFE02","uFE03","uFE04","uFE05","uFE06","uFE07","uFE08","uFE09","uFE0A","uFE0B","uFE0C","uFE0D","uFE0E","uFE0F","uFE20","uFE21","uFE22","uFE23","uFE24","uFE25","uFE26","uFE27","uFE28","uFE29","uFE2A","uFE2B","uFE2C","uFE2D","uFE2E","uFE2F"];var p=l.concat(c);var g=["-","/",";",":","&","u0E2F","u0EAF","u0EC6","u0ECC","u104A","u104B","u104C","u104D","u104E","u104F","u2013","u2014","u2027","u3000","u3001","u3002","uFF0C","uFF5E"];var y=["'","<","(","{","[","u00AB","u300A","u3008"];var _=["'",">",")","}","]",".","!","?","u00BB","u300B","u3009"].concat(g);var d="က-ဪဿ-၉ၐ-ၕ";var v="-ゟ゠-ヿ-+--}⦅-゚㐀-䶿";var x="㐀-龿";var m="ກ-ຮະ-ໄ່-໋ໍ-ໝ";var w=d+x+m;var z=new RegExp("(\\"+g.join("|\\")+")*[^\\s|\\"+g.join("|\\")+"]*(\\"+g.join("|\\")+")*","g");var b=new RegExp("["+v+"]");var S=new RegExp("["+w+"]");var j=new RegExp("(\\"+y.join("|\\")+")*["+w+"](\\"+_.join("|\\")+"|\\"+p.join("|\\")+")*|[a-z0-9]+","gi");var M=function(u){if(!S.test(u)){return E(u).match(z).filter(function(u){return u.length})}return e.merge(E(u).match(z).map(function(u){if(!b.test(u)&&S.test(u)){return u.match(j)}return[u]}))};var H=function(){var u="Verdana",t=10,n=400,e=200,i,o=false,A=M,s=200;function a(a){a=E(a);if(i===void 0){i=Math.ceil(t*1.1)}var f=A(a);var B={"font-family":u,"font-size":t,"font-weight":n,"line-height":i};var C=1,D="",F=false,h=0;var l=[],c=r(f,B),p=r(" ",B);for(var g=0;g<f.length;g++){var y=f[g];var _=c[f.indexOf(y)];y+=a.slice(D.length+y.length).match("^( |\n)*","g")[0];if(D.slice(-1)==="\n"||h+_>s){if(!g&&!o){F=true;break}l[C-1]=l[C-1].trimRight();C++;if(i*C>e||_>s&&!o){F=true;break}h=0;l.push(y)}else if(!g){l[0]=y}else{l[C-1]+=y}D+=y;h+=_;h+=y.match(/[\s]*$/g)[0].length*p}return{lines:l,sentence:a,truncated:F,words:f}}a.fontFamily=function(t){return arguments.length?(u=t,a):u};a.fontSize=function(u){return arguments.length?(t=u,a):t};a.fontWeight=function(u){return arguments.length?(n=u,a):n};a.height=function(u){return arguments.length?(e=u,a):e};a.lineHeight=function(u){return arguments.length?(i=u,a):i};a.overflow=function(u){return arguments.length?(o=u,a):o};a.split=function(u){return arguments.length?(A=u,a):A};a.width=function(u){return arguments.length?(s=u,a):s};return a};var W=function(u){function o(){u.call(this);this._delay=0;this._duration=0;this._ellipsis=function(u){return u.replace(/\.|,$/g,"")+"..."};this._fontColor=i.constant("black");this._fontFamily=i.constant("Verdana");this._fontMax=i.constant(50);this._fontMin=i.constant(8);this._fontResize=i.constant(false);this._fontSize=i.constant(10);this._fontWeight=i.constant(400);this._height=i.accessor("height",200);this._id=function(u,t){return u.id||""+t};this._on={};this._overflow=i.constant(false);this._pointerEvents=i.constant("auto");this._rotate=i.constant(0);this._split=M;this._text=i.accessor("text");this._textAnchor=i.constant("start");this._verticalAlign=i.constant("top");this._width=i.accessor("width",200);this._x=i.accessor("x",0);this._y=i.accessor("y",0)}if(u)o.__proto__=u;o.prototype=Object.create(u&&u.prototype);o.prototype.constructor=o;o.prototype.render=function u(i){var o=this;if(this._select===void 0){this.select(t.select("body").append("svg").style("width",window.innerWidth+"px").style("height",window.innerHeight+"px").node())}if(this._lineHeight===void 0){this._lineHeight=function(u,t){return o._fontSize(u,t)*1.1}}var A=this;var s=this._select.selectAll(".d3plus-textBox").data(this._data.reduce(function(u,t,n){var i=o._text(t,n);if(i===void 0){return u}var s=o._fontResize(t,n);var a=s?o._fontMax(t,n):o._fontSize(t,n),f=s?a*1.1:o._lineHeight(t,n),B=1,C=[],D;var E={"font-family":o._fontFamily(t,n),"font-size":a,"font-weight":o._fontWeight(t,n),"line-height":f};var F=o._height(t,n),h=o._width(t,n);var l=H().fontFamily(E["font-family"]).fontSize(a).fontWeight(E["font-weight"]).lineHeight(f).height(F).overflow(o._overflow(t,n)).width(h);var c=o._fontMax(t,n),p=o._fontMin(t,n),g=o._verticalAlign(t,n),y=o._split(i,n);function _(){if(a<p){C=[];return}else if(a>c){a=c}if(s){f=a*1.1;l.fontSize(a).lineHeight(f);E["font-size"]=a;E["line-height"]=f}var u=l(i);C=u.lines.filter(function(u){return u!==""});B=C.length;if(u.truncated){if(s){a--;if(a<p){C=[]}else{_()}}else if(B<1){C=[A._ellipsis("")]}else{C[B-1]=A._ellipsis(C[B-1])}}}if(h>p&&(F>f||s&&F>p*1.1)){if(s){D=r(y,E);var d=1.165+h/F*.1,v=h*F,x=e.max(D),m=e.sum(D,function(u){return u*f})*d;if(x>h||m>v){var w=Math.sqrt(v/m),z=h/x;var b=e.min([w,z]);a=Math.floor(a*b)}var S=Math.floor(F*.8);if(a>S){a=S}}_()}if(C.length){var j=B*f;var M=g==="top"?0:g==="middle"?F/2-j/2:F-j;M-=f*.1;u.push({data:t,i:n,lines:C,fC:o._fontColor(t,n),fF:E["font-family"],fW:E["font-weight"],id:o._id(t,n),tA:o._textAnchor(t,n),fS:a,lH:f,w:h,x:o._x(t,n),y:o._y(t,n)+M})}return u},[]),this._id);var a=n.transition().duration(this._duration);if(this._duration===0){s.exit().remove()}else{s.exit().transition().delay(this._duration).remove();s.exit().selectAll("tspan").transition(a).attr("opacity",0)}function f(u){u.attr("transform",function(u,t){return"rotate("+A._rotate(u,t)+" "+(u.x+u.w/2)+" "+(u.y+u.lH/4+u.lH*u.lines.length/2)+")"})}var B=s.enter().append("text").attr("class","d3plus-textBox").attr("id",function(u){return"d3plus-textBox-"+u.id}).attr("y",function(u){return u.y+"px"}).call(f).merge(s);B.attr("fill",function(u){return u.fC}).attr("text-anchor",function(u){return u.tA}).attr("font-family",function(u){return u.fF}).style("font-family",function(u){return u.fF}).attr("font-size",function(u){return u.fS+"px"}).style("font-size",function(u){return u.fS+"px"}).attr("font-weight",function(u){return u.fW}).style("font-weight",function(u){return u.fW}).style("pointer-events",function(u){return o._pointerEvents(u.data,u.i)}).each(function(u){var n=u.tA==="start"?0:u.tA==="end"?u.w:u.w/2,e=t.select(this);if(A._duration===0){e.attr("y",function(u){return u.y+"px"})}else{e.transition(a).attr("y",function(u){return u.y+"px"})}function i(t){t.text(function(u){return u.trimRight()}).attr("x",u.x+"px").attr("dx",n+"px").attr("dy",u.lH+"px")}var r=e.selectAll("tspan").data(u.lines);if(A._duration===0){r.call(i);r.exit().remove();r.enter().append("tspan").attr("dominant-baseline","alphabetic").style("baseline-shift","0%").call(i)}else{r.transition(a).call(i);r.exit().transition(a).attr("opacity",0).remove();r.enter().append("tspan").attr("dominant-baseline","alphabetic").style("baseline-shift","0%").attr("opacity",0).call(i).merge(r).transition(a).delay(A._delay).call(i).attr("opacity",1)}}).transition(a).call(f);var C=Object.keys(this._on),D=C.reduce(function(u,t){u[t]=function(u,n){return o._on[t](u.data,n)};return u},{});for(var E=0;E<C.length;E++){B.on(C[E],D[C[E]])}if(i){setTimeout(i,this._duration+100)}return this};o.prototype.data=function u(t){return arguments.length?(this._data=t,this):this._data};o.prototype.delay=function u(t){return arguments.length?(this._delay=t,this):this._delay};o.prototype.duration=function u(t){return arguments.length?(this._duration=t,this):this._duration};o.prototype.ellipsis=function u(t){return arguments.length?(this._ellipsis=typeof t==="function"?t:i.constant(t),this):this._ellipsis};o.prototype.fontColor=function u(t){return arguments.length?(this._fontColor=typeof t==="function"?t:i.constant(t),this):this._fontColor};o.prototype.fontFamily=function u(t){return arguments.length?(this._fontFamily=typeof t==="function"?t:i.constant(t),this):this._fontFamily};o.prototype.fontMax=function u(t){return arguments.length?(this._fontMax=typeof t==="function"?t:i.constant(t),this):this._fontMax};o.prototype.fontMin=function u(t){return arguments.length?(this._fontMin=typeof t==="function"?t:i.constant(t),this):this._fontMin};o.prototype.fontResize=function u(t){return arguments.length?(this._fontResize=typeof t==="function"?t:i.constant(t),this):this._fontResize};o.prototype.fontSize=function u(t){return arguments.length?(this._fontSize=typeof t==="function"?t:i.constant(t),this):this._fontSize};o.prototype.fontWeight=function u(t){return arguments.length?(this._fontWeight=typeof t==="function"?t:i.constant(t),this):this._fontWeight};o.prototype.height=function u(t){return arguments.length?(this._height=typeof t==="function"?t:i.constant(t),this):this._height};o.prototype.id=function u(t){return arguments.length?(this._id=typeof t==="function"?t:i.constant(t),this):this._id};o.prototype.lineHeight=function u(t){return arguments.length?(this._lineHeight=typeof t==="function"?t:i.constant(t),this):this._lineHeight};o.prototype.overflow=function u(t){return arguments.length?(this._overflow=typeof t==="function"?t:i.constant(t),this):this._overflow};o.prototype.pointerEvents=function u(t){return arguments.length?(this._pointerEvents=typeof t==="function"?t:i.constant(t),this):this._pointerEvents};o.prototype.rotate=function u(t){return arguments.length?(this._rotate=typeof t==="function"?t:i.constant(t),this):this._rotate};o.prototype.select=function u(n){return arguments.length?(this._select=t.select(n),this):this._select};o.prototype.split=function u(t){return arguments.length?(this._split=t,this):this._split};o.prototype.text=function u(t){return arguments.length?(this._text=typeof t==="function"?t:i.constant(t),this):this._text};o.prototype.textAnchor=function u(t){return arguments.length?(this._textAnchor=typeof t==="function"?t:i.constant(t),this):this._textAnchor};o.prototype.verticalAlign=function u(t){return arguments.length?(this._verticalAlign=typeof t==="function"?t:i.constant(t),this):this._verticalAlign};o.prototype.width=function u(t){return arguments.length?(this._width=typeof t==="function"?t:i.constant(t),this):this._width};o.prototype.x=function u(t){return arguments.length?(this._x=typeof t==="function"?t:i.constant(t),this):this._x};o.prototype.y=function u(t){return arguments.length?(this._y=typeof t==="function"?t:i.constant(t),this):this._y};return o}(i.BaseClass);var R=function(u,t){if(u===void 0){return""}t=Object.assign({lng:"en-US"},t);var n=t.lng;var e=i.locale.t("array.lowercase",{lng:n,returnObjects:true}).map(function(u){return u.toLowerCase()});var r=i.locale.t("array.uppercase",{lng:n,returnObjects:true});r=r.concat(r.map(function(u){return u+"s"}));var o=r.map(function(u){return u.toLowerCase()});var A=M(u);return A.map(function(u,t){if(u){var n=u.toLowerCase();var i=_.includes(n.charAt(n.length-1))?n.slice(0,-1):n;var s=o.indexOf(i);if(s>=0){return r[s]}else if(e.includes(i)&&t!==0&&t!==A.length-1){return n}else{return u.charAt(0).toUpperCase()+u.substr(1).toLowerCase()}}else{return""}}).reduce(function(t,n,e){if(e&&u.charAt(t.length)===" "){t+=" "}t+=n;return t},"")};u.fontExists=D;u.stringify=E;u.strip=h;u.TextBox=W;u.textSplit=M;u.textWidth=r;u.textWrap=H;u.titleCase=R;Object.defineProperty(u,"__esModule",{value:true})}); | ||
(function(u,t){typeof exports==="object"&&typeof module!=="undefined"?t(exports,require("d3-selection"),require("d3-transition"),require("d3-array"),require("d3plus-common")):typeof define==="function"&&define.amd?define("d3plus-text",["exports","d3-selection","d3-transition","d3-array","d3plus-common"],t):t(u.d3plus={},u.d3Selection,u.d3Transition,u.d3Array,u.d3plusCommon)})(this,function(u,t,n,e,i){"use strict";var r=function(u,t){t=Object.assign({"font-size":10,"font-family":"sans-serif","font-style":"normal","font-weight":400,"font-variant":"normal"},t);var n=document.createElement("canvas").getContext("2d");var e=[];e.push(t["font-style"]);e.push(t["font-variant"]);e.push(t["font-weight"]);e.push(typeof t["font-size"]==="string"?t["font-size"]:t["font-size"]+"px");e.push(t["font-family"]);n.font=e.join(" ");if(u instanceof Array){return u.map(function(u){return n.measureText(u).width})}return n.measureText(u).width};function o(u){return u.replace(/^\s+|\s+$/g,"")}function A(u){return u.replace(/^\s+/,"")}function s(u){return u.replace(/\s+$/,"")}var a="abcdefghiABCDEFGHI_!@#$%^&*()_+1234567890";var f={};var B=32;var C;var D;var E;var F;var l=function(u){if(!C){C=r(a,{"font-family":"DejaVuSans","font-size":B});D=r(a,{"font-family":"-apple-system","font-size":B});E=r(a,{"font-family":"monospace","font-size":B});F=r(a,{"font-family":"sans-serif","font-size":B})}if(!(u instanceof Array)){u=u.split(",")}u=u.map(function(u){return o(u)});for(var t=0;t<u.length;t++){var n=u[t];if(f[n]||["-apple-system","monospace","sans-serif","DejaVuSans"].includes(n)){return n}else if(f[n]===false){continue}var e=r(a,{"font-family":n,"font-size":B});f[n]=e!==E;if(f[n]){f[n]=e!==F}if(D&&f[n]){f[n]=e!==D}if(C&&f[n]){f[n]=e!==C}if(f[n]){return n}}return false};var h=function(u){if(u===void 0){u="undefined"}else if(!(typeof u==="string"||u instanceof String)){u=JSON.stringify(u)}return u};var c=[[/[\300-\305]/g,"A"],[/[\340-\345]/g,"a"],[/[\306]/g,"AE"],[/[\346]/g,"ae"],[/[\337]/g,"B"],[/[\307]/g,"C"],[/[\347]/g,"c"],[/[\320\336\376]/g,"D"],[/[\360]/g,"d"],[/[\310-\313]/g,"E"],[/[\350-\353]/g,"e"],[/[\314-\317]/g,"I"],[/[\354-\357]/g,"i"],[/[\321]/g,"N"],[/[\361]/g,"n"],[/[\322-\326\330]/g,"O"],[/[\362-\366\370]/g,"o"],[/[\331-\334]/g,"U"],[/[\371-\374]/g,"u"],[/[\327]/g,"x"],[/[\335]/g,"Y"],[/[\375\377]/g,"y"]];var p=function(u){return(""+u).replace(/[^A-Za-z0-9\-_]/g,function(u){if(u===" "){return"-"}var t=false;for(var n=0;n<c.length;n++){if(new RegExp(c[n][0]).test(u)){t=c[n][1];break}}return t||""})};var g=["u0903","u093B","u093E","u093F","u0940","u0949","u094A","u094B","u094C","u094E","u094F","u0982","u0983","u09BE","u09BF","u09C0","u09C7","u09C8","u09CB","u09CC","u09D7","u0A03","u0A3E","u0A3F","u0A40","u0A83","u0ABE","u0ABF","u0AC0","u0AC9","u0ACB","u0ACC","u0B02","u0B03","u0B3E","u0B40","u0B47","u0B48","u0B4B","u0B4C","u0B57","u0BBE","u0BBF","u0BC1","u0BC2","u0BC6","u0BC7","u0BC8","u0BCA","u0BCB","u0BCC","u0BD7","u0C01","u0C02","u0C03","u0C41","u0C42","u0C43","u0C44","u0C82","u0C83","u0CBE","u0CC0","u0CC1","u0CC2","u0CC3","u0CC4","u0CC7","u0CC8","u0CCA","u0CCB","u0CD5","u0CD6","u0D02","u0D03","u0D3E","u0D3F","u0D40","u0D46","u0D47","u0D48","u0D4A","u0D4B","u0D4C","u0D57","u0D82","u0D83","u0DCF","u0DD0","u0DD1","u0DD8","u0DD9","u0DDA","u0DDB","u0DDC","u0DDD","u0DDE","u0DDF","u0DF2","u0DF3","u0F3E","u0F3F","u0F7F","u102B","u102C","u1031","u1038","u103B","u103C","u1056","u1057","u1062","u1063","u1064","u1067","u1068","u1069","u106A","u106B","u106C","u106D","u1083","u1084","u1087","u1088","u1089","u108A","u108B","u108C","u108F","u109A","u109B","u109C","u17B6","u17BE","u17BF","u17C0","u17C1","u17C2","u17C3","u17C4","u17C5","u17C7","u17C8","u1923","u1924","u1925","u1926","u1929","u192A","u192B","u1930","u1931","u1933","u1934","u1935","u1936","u1937","u1938","u1A19","u1A1A","u1A55","u1A57","u1A61","u1A63","u1A64","u1A6D","u1A6E","u1A6F","u1A70","u1A71","u1A72","u1B04","u1B35","u1B3B","u1B3D","u1B3E","u1B3F","u1B40","u1B41","u1B43","u1B44","u1B82","u1BA1","u1BA6","u1BA7","u1BAA","u1BE7","u1BEA","u1BEB","u1BEC","u1BEE","u1BF2","u1BF3","u1C24","u1C25","u1C26","u1C27","u1C28","u1C29","u1C2A","u1C2B","u1C34","u1C35","u1CE1","u1CF2","u1CF3","u302E","u302F","uA823","uA824","uA827","uA880","uA881","uA8B4","uA8B5","uA8B6","uA8B7","uA8B8","uA8B9","uA8BA","uA8BB","uA8BC","uA8BD","uA8BE","uA8BF","uA8C0","uA8C1","uA8C2","uA8C3","uA952","uA953","uA983","uA9B4","uA9B5","uA9BA","uA9BB","uA9BD","uA9BE","uA9BF","uA9C0","uAA2F","uAA30","uAA33","uAA34","uAA4D","uAA7B","uAA7D","uAAEB","uAAEE","uAAEF","uAAF5","uABE3","uABE4","uABE6","uABE7","uABE9","uABEA","uABEC"];var y=["u0300","u0301","u0302","u0303","u0304","u0305","u0306","u0307","u0308","u0309","u030A","u030B","u030C","u030D","u030E","u030F","u0310","u0311","u0312","u0313","u0314","u0315","u0316","u0317","u0318","u0319","u031A","u031B","u031C","u031D","u031E","u031F","u0320","u0321","u0322","u0323","u0324","u0325","u0326","u0327","u0328","u0329","u032A","u032B","u032C","u032D","u032E","u032F","u0330","u0331","u0332","u0333","u0334","u0335","u0336","u0337","u0338","u0339","u033A","u033B","u033C","u033D","u033E","u033F","u0340","u0341","u0342","u0343","u0344","u0345","u0346","u0347","u0348","u0349","u034A","u034B","u034C","u034D","u034E","u034F","u0350","u0351","u0352","u0353","u0354","u0355","u0356","u0357","u0358","u0359","u035A","u035B","u035C","u035D","u035E","u035F","u0360","u0361","u0362","u0363","u0364","u0365","u0366","u0367","u0368","u0369","u036A","u036B","u036C","u036D","u036E","u036F","u0483","u0484","u0485","u0486","u0487","u0591","u0592","u0593","u0594","u0595","u0596","u0597","u0598","u0599","u059A","u059B","u059C","u059D","u059E","u059F","u05A0","u05A1","u05A2","u05A3","u05A4","u05A5","u05A6","u05A7","u05A8","u05A9","u05AA","u05AB","u05AC","u05AD","u05AE","u05AF","u05B0","u05B1","u05B2","u05B3","u05B4","u05B5","u05B6","u05B7","u05B8","u05B9","u05BA","u05BB","u05BC","u05BD","u05BF","u05C1","u05C2","u05C4","u05C5","u05C7","u0610","u0611","u0612","u0613","u0614","u0615","u0616","u0617","u0618","u0619","u061A","u064B","u064C","u064D","u064E","u064F","u0650","u0651","u0652","u0653","u0654","u0655","u0656","u0657","u0658","u0659","u065A","u065B","u065C","u065D","u065E","u065F","u0670","u06D6","u06D7","u06D8","u06D9","u06DA","u06DB","u06DC","u06DF","u06E0","u06E1","u06E2","u06E3","u06E4","u06E7","u06E8","u06EA","u06EB","u06EC","u06ED","u0711","u0730","u0731","u0732","u0733","u0734","u0735","u0736","u0737","u0738","u0739","u073A","u073B","u073C","u073D","u073E","u073F","u0740","u0741","u0742","u0743","u0744","u0745","u0746","u0747","u0748","u0749","u074A","u07A6","u07A7","u07A8","u07A9","u07AA","u07AB","u07AC","u07AD","u07AE","u07AF","u07B0","u07EB","u07EC","u07ED","u07EE","u07EF","u07F0","u07F1","u07F2","u07F3","u0816","u0817","u0818","u0819","u081B","u081C","u081D","u081E","u081F","u0820","u0821","u0822","u0823","u0825","u0826","u0827","u0829","u082A","u082B","u082C","u082D","u0859","u085A","u085B","u08E3","u08E4","u08E5","u08E6","u08E7","u08E8","u08E9","u08EA","u08EB","u08EC","u08ED","u08EE","u08EF","u08F0","u08F1","u08F2","u08F3","u08F4","u08F5","u08F6","u08F7","u08F8","u08F9","u08FA","u08FB","u08FC","u08FD","u08FE","u08FF","u0900","u0901","u0902","u093A","u093C","u0941","u0942","u0943","u0944","u0945","u0946","u0947","u0948","u094D","u0951","u0952","u0953","u0954","u0955","u0956","u0957","u0962","u0963","u0981","u09BC","u09C1","u09C2","u09C3","u09C4","u09CD","u09E2","u09E3","u0A01","u0A02","u0A3C","u0A41","u0A42","u0A47","u0A48","u0A4B","u0A4C","u0A4D","u0A51","u0A70","u0A71","u0A75","u0A81","u0A82","u0ABC","u0AC1","u0AC2","u0AC3","u0AC4","u0AC5","u0AC7","u0AC8","u0ACD","u0AE2","u0AE3","u0B01","u0B3C","u0B3F","u0B41","u0B42","u0B43","u0B44","u0B4D","u0B56","u0B62","u0B63","u0B82","u0BC0","u0BCD","u0C00","u0C3E","u0C3F","u0C40","u0C46","u0C47","u0C48","u0C4A","u0C4B","u0C4C","u0C4D","u0C55","u0C56","u0C62","u0C63","u0C81","u0CBC","u0CBF","u0CC6","u0CCC","u0CCD","u0CE2","u0CE3","u0D01","u0D41","u0D42","u0D43","u0D44","u0D4D","u0D62","u0D63","u0DCA","u0DD2","u0DD3","u0DD4","u0DD6","u0E31","u0E34","u0E35","u0E36","u0E37","u0E38","u0E39","u0E3A","u0E47","u0E48","u0E49","u0E4A","u0E4B","u0E4C","u0E4D","u0E4E","u0EB1","u0EB4","u0EB5","u0EB6","u0EB7","u0EB8","u0EB9","u0EBB","u0EBC","u0EC8","u0EC9","u0ECA","u0ECB","u0ECC","u0ECD","u0F18","u0F19","u0F35","u0F37","u0F39","u0F71","u0F72","u0F73","u0F74","u0F75","u0F76","u0F77","u0F78","u0F79","u0F7A","u0F7B","u0F7C","u0F7D","u0F7E","u0F80","u0F81","u0F82","u0F83","u0F84","u0F86","u0F87","u0F8D","u0F8E","u0F8F","u0F90","u0F91","u0F92","u0F93","u0F94","u0F95","u0F96","u0F97","u0F99","u0F9A","u0F9B","u0F9C","u0F9D","u0F9E","u0F9F","u0FA0","u0FA1","u0FA2","u0FA3","u0FA4","u0FA5","u0FA6","u0FA7","u0FA8","u0FA9","u0FAA","u0FAB","u0FAC","u0FAD","u0FAE","u0FAF","u0FB0","u0FB1","u0FB2","u0FB3","u0FB4","u0FB5","u0FB6","u0FB7","u0FB8","u0FB9","u0FBA","u0FBB","u0FBC","u0FC6","u102D","u102E","u102F","u1030","u1032","u1033","u1034","u1035","u1036","u1037","u1039","u103A","u103D","u103E","u1058","u1059","u105E","u105F","u1060","u1071","u1072","u1073","u1074","u1082","u1085","u1086","u108D","u109D","u135D","u135E","u135F","u1712","u1713","u1714","u1732","u1733","u1734","u1752","u1753","u1772","u1773","u17B4","u17B5","u17B7","u17B8","u17B9","u17BA","u17BB","u17BC","u17BD","u17C6","u17C9","u17CA","u17CB","u17CC","u17CD","u17CE","u17CF","u17D0","u17D1","u17D2","u17D3","u17DD","u180B","u180C","u180D","u18A9","u1920","u1921","u1922","u1927","u1928","u1932","u1939","u193A","u193B","u1A17","u1A18","u1A1B","u1A56","u1A58","u1A59","u1A5A","u1A5B","u1A5C","u1A5D","u1A5E","u1A60","u1A62","u1A65","u1A66","u1A67","u1A68","u1A69","u1A6A","u1A6B","u1A6C","u1A73","u1A74","u1A75","u1A76","u1A77","u1A78","u1A79","u1A7A","u1A7B","u1A7C","u1A7F","u1AB0","u1AB1","u1AB2","u1AB3","u1AB4","u1AB5","u1AB6","u1AB7","u1AB8","u1AB9","u1ABA","u1ABB","u1ABC","u1ABD","u1B00","u1B01","u1B02","u1B03","u1B34","u1B36","u1B37","u1B38","u1B39","u1B3A","u1B3C","u1B42","u1B6B","u1B6C","u1B6D","u1B6E","u1B6F","u1B70","u1B71","u1B72","u1B73","u1B80","u1B81","u1BA2","u1BA3","u1BA4","u1BA5","u1BA8","u1BA9","u1BAB","u1BAC","u1BAD","u1BE6","u1BE8","u1BE9","u1BED","u1BEF","u1BF0","u1BF1","u1C2C","u1C2D","u1C2E","u1C2F","u1C30","u1C31","u1C32","u1C33","u1C36","u1C37","u1CD0","u1CD1","u1CD2","u1CD4","u1CD5","u1CD6","u1CD7","u1CD8","u1CD9","u1CDA","u1CDB","u1CDC","u1CDD","u1CDE","u1CDF","u1CE0","u1CE2","u1CE3","u1CE4","u1CE5","u1CE6","u1CE7","u1CE8","u1CED","u1CF4","u1CF8","u1CF9","u1DC0","u1DC1","u1DC2","u1DC3","u1DC4","u1DC5","u1DC6","u1DC7","u1DC8","u1DC9","u1DCA","u1DCB","u1DCC","u1DCD","u1DCE","u1DCF","u1DD0","u1DD1","u1DD2","u1DD3","u1DD4","u1DD5","u1DD6","u1DD7","u1DD8","u1DD9","u1DDA","u1DDB","u1DDC","u1DDD","u1DDE","u1DDF","u1DE0","u1DE1","u1DE2","u1DE3","u1DE4","u1DE5","u1DE6","u1DE7","u1DE8","u1DE9","u1DEA","u1DEB","u1DEC","u1DED","u1DEE","u1DEF","u1DF0","u1DF1","u1DF2","u1DF3","u1DF4","u1DF5","u1DFC","u1DFD","u1DFE","u1DFF","u20D0","u20D1","u20D2","u20D3","u20D4","u20D5","u20D6","u20D7","u20D8","u20D9","u20DA","u20DB","u20DC","u20E1","u20E5","u20E6","u20E7","u20E8","u20E9","u20EA","u20EB","u20EC","u20ED","u20EE","u20EF","u20F0","u2CEF","u2CF0","u2CF1","u2D7F","u2DE0","u2DE1","u2DE2","u2DE3","u2DE4","u2DE5","u2DE6","u2DE7","u2DE8","u2DE9","u2DEA","u2DEB","u2DEC","u2DED","u2DEE","u2DEF","u2DF0","u2DF1","u2DF2","u2DF3","u2DF4","u2DF5","u2DF6","u2DF7","u2DF8","u2DF9","u2DFA","u2DFB","u2DFC","u2DFD","u2DFE","u2DFF","u302A","u302B","u302C","u302D","u3099","u309A","uA66F","uA674","uA675","uA676","uA677","uA678","uA679","uA67A","uA67B","uA67C","uA67D","uA69E","uA69F","uA6F0","uA6F1","uA802","uA806","uA80B","uA825","uA826","uA8C4","uA8E0","uA8E1","uA8E2","uA8E3","uA8E4","uA8E5","uA8E6","uA8E7","uA8E8","uA8E9","uA8EA","uA8EB","uA8EC","uA8ED","uA8EE","uA8EF","uA8F0","uA8F1","uA926","uA927","uA928","uA929","uA92A","uA92B","uA92C","uA92D","uA947","uA948","uA949","uA94A","uA94B","uA94C","uA94D","uA94E","uA94F","uA950","uA951","uA980","uA981","uA982","uA9B3","uA9B6","uA9B7","uA9B8","uA9B9","uA9BC","uA9E5","uAA29","uAA2A","uAA2B","uAA2C","uAA2D","uAA2E","uAA31","uAA32","uAA35","uAA36","uAA43","uAA4C","uAA7C","uAAB0","uAAB2","uAAB3","uAAB4","uAAB7","uAAB8","uAABE","uAABF","uAAC1","uAAEC","uAAED","uAAF6","uABE5","uABE8","uABED","uFB1E","uFE00","uFE01","uFE02","uFE03","uFE04","uFE05","uFE06","uFE07","uFE08","uFE09","uFE0A","uFE0B","uFE0C","uFE0D","uFE0E","uFE0F","uFE20","uFE21","uFE22","uFE23","uFE24","uFE25","uFE26","uFE27","uFE28","uFE29","uFE2A","uFE2B","uFE2C","uFE2D","uFE2E","uFE2F"];var _=g.concat(y);var d=["-","/",";",":","&","u0E2F","u0EAF","u0EC6","u0ECC","u104A","u104B","u104C","u104D","u104E","u104F","u2013","u2014","u2027","u3000","u3001","u3002","uFF0C","uFF5E"];var v=["'","<","(","{","[","u00AB","u300A","u3008"];var x=["'",">",")","}","]",".","!","?","u00BB","u300B","u3009"].concat(d);var m="က-ဪဿ-၉ၐ-ၕ";var w="-ゟ゠-ヿ-+--}⦅-゚㐀-䶿";var z="㐀-龿";var b="ກ-ຮະ-ໄ່-໋ໍ-ໝ";var S=m+z+b;var j=new RegExp("(\\"+d.join("|\\")+")*[^\\s|\\"+d.join("|\\")+"]*(\\"+d.join("|\\")+")*","g");var M=new RegExp("["+w+"]");var H=new RegExp("["+S+"]");var W=new RegExp("(\\"+v.join("|\\")+")*["+S+"](\\"+x.join("|\\")+"|\\"+_.join("|\\")+")*|[a-z0-9]+","gi");var O=function(u){if(!H.test(u)){return h(u).match(j).filter(function(u){return u.length})}return e.merge(h(u).match(j).map(function(u){if(!M.test(u)&&H.test(u)){return u.match(W)}return[u]}))};var R=function(){var u="Verdana",t=10,n=400,e=200,i,o=false,A=O,a=200;function f(f){f=h(f);if(i===void 0){i=Math.ceil(t*1.1)}var B=A(f);var C={"font-family":u,"font-size":t,"font-weight":n,"line-height":i};var D=1,E="",F=false,l=0;var c=[],p=r(B,C),g=r(" ",C);for(var y=0;y<B.length;y++){var _=B[y];var d=p[B.indexOf(_)];_+=f.slice(E.length+_.length).match("^( |\n)*","g")[0];if(E.slice(-1)==="\n"||l+d>a){if(!y&&!o){F=true;break}c[D-1]=s(c[D-1]);D++;if(i*D>e||d>a&&!o){F=true;break}l=0;c.push(_)}else if(!y){c[0]=_}else{c[D-1]+=_}E+=_;l+=d;l+=_.match(/[\s]*$/g)[0].length*g}return{lines:c,sentence:f,truncated:F,words:B}}f.fontFamily=function(t){return arguments.length?(u=t,f):u};f.fontSize=function(u){return arguments.length?(t=u,f):t};f.fontWeight=function(u){return arguments.length?(n=u,f):n};f.height=function(u){return arguments.length?(e=u,f):e};f.lineHeight=function(u){return arguments.length?(i=u,f):i};f.overflow=function(u){return arguments.length?(o=u,f):o};f.split=function(u){return arguments.length?(A=u,f):A};f.width=function(u){return arguments.length?(a=u,f):a};return f};var k=function(u){function o(){u.call(this);this._delay=0;this._duration=0;this._ellipsis=function(u){return u.replace(/\.|,$/g,"")+"..."};this._fontColor=i.constant("black");this._fontFamily=i.constant("Verdana");this._fontMax=i.constant(50);this._fontMin=i.constant(8);this._fontResize=i.constant(false);this._fontSize=i.constant(10);this._fontWeight=i.constant(400);this._height=i.accessor("height",200);this._id=function(u,t){return u.id||""+t};this._on={};this._overflow=i.constant(false);this._pointerEvents=i.constant("auto");this._rotate=i.constant(0);this._split=O;this._text=i.accessor("text");this._textAnchor=i.constant("start");this._verticalAlign=i.constant("top");this._width=i.accessor("width",200);this._x=i.accessor("x",0);this._y=i.accessor("y",0)}if(u)o.__proto__=u;o.prototype=Object.create(u&&u.prototype);o.prototype.constructor=o;o.prototype.render=function u(i){var o=this;if(this._select===void 0){this.select(t.select("body").append("svg").style("width",window.innerWidth+"px").style("height",window.innerHeight+"px").node())}if(this._lineHeight===void 0){this._lineHeight=function(u,t){return o._fontSize(u,t)*1.1}}var A=this;var a=this._select.selectAll(".d3plus-textBox").data(this._data.reduce(function(u,t,n){var i=o._text(t,n);if(i===void 0){return u}var s=o._fontResize(t,n);var a=s?o._fontMax(t,n):o._fontSize(t,n),f=s?a*1.1:o._lineHeight(t,n),B=1,C=[],D;var E={"font-family":o._fontFamily(t,n),"font-size":a,"font-weight":o._fontWeight(t,n),"line-height":f};var F=o._height(t,n),l=o._width(t,n);var h=R().fontFamily(E["font-family"]).fontSize(a).fontWeight(E["font-weight"]).lineHeight(f).height(F).overflow(o._overflow(t,n)).width(l);var c=o._fontMax(t,n),p=o._fontMin(t,n),g=o._verticalAlign(t,n),y=o._split(i,n);function _(){if(a<p){C=[];return}else if(a>c){a=c}if(s){f=a*1.1;h.fontSize(a).lineHeight(f);E["font-size"]=a;E["line-height"]=f}var u=h(i);C=u.lines.filter(function(u){return u!==""});B=C.length;if(u.truncated){if(s){a--;if(a<p){C=[]}else{_()}}else if(B<1){C=[A._ellipsis("")]}else{C[B-1]=A._ellipsis(C[B-1])}}}if(l>p&&(F>f||s&&F>p*1.1)){if(s){D=r(y,E);var d=1.165+l/F*.1,v=l*F,x=e.max(D),m=e.sum(D,function(u){return u*f})*d;if(x>l||m>v){var w=Math.sqrt(v/m),z=l/x;var b=e.min([w,z]);a=Math.floor(a*b)}var S=Math.floor(F*.8);if(a>S){a=S}}_()}if(C.length){var j=B*f;var M=g==="top"?0:g==="middle"?F/2-j/2:F-j;M-=f*.1;u.push({data:t,i:n,lines:C,fC:o._fontColor(t,n),fF:E["font-family"],fW:E["font-weight"],id:o._id(t,n),tA:o._textAnchor(t,n),fS:a,lH:f,w:l,x:o._x(t,n),y:o._y(t,n)+M})}return u},[]),this._id);var f=n.transition().duration(this._duration);if(this._duration===0){a.exit().remove()}else{a.exit().transition().delay(this._duration).remove();a.exit().selectAll("tspan").transition(f).attr("opacity",0)}function B(u){u.attr("transform",function(u,t){return"rotate("+A._rotate(u,t)+" "+(u.x+u.w/2)+" "+(u.y+u.lH/4+u.lH*u.lines.length/2)+")"})}var C=a.enter().append("text").attr("class","d3plus-textBox").attr("id",function(u){return"d3plus-textBox-"+u.id}).attr("y",function(u){return u.y+"px"}).call(B).merge(a);C.attr("fill",function(u){return u.fC}).attr("text-anchor",function(u){return u.tA}).attr("font-family",function(u){return u.fF}).style("font-family",function(u){return u.fF}).attr("font-size",function(u){return u.fS+"px"}).style("font-size",function(u){return u.fS+"px"}).attr("font-weight",function(u){return u.fW}).style("font-weight",function(u){return u.fW}).style("pointer-events",function(u){return o._pointerEvents(u.data,u.i)}).each(function(u){var n=u.tA==="start"?0:u.tA==="end"?u.w:u.w/2,e=t.select(this);if(A._duration===0){e.attr("y",function(u){return u.y+"px"})}else{e.transition(f).attr("y",function(u){return u.y+"px"})}function i(t){t.text(function(u){return s(u)}).attr("x",u.x+"px").attr("dx",n+"px").attr("dy",u.lH+"px")}var r=e.selectAll("tspan").data(u.lines);if(A._duration===0){r.call(i);r.exit().remove();r.enter().append("tspan").attr("dominant-baseline","alphabetic").style("baseline-shift","0%").call(i)}else{r.transition(f).call(i);r.exit().transition(f).attr("opacity",0).remove();r.enter().append("tspan").attr("dominant-baseline","alphabetic").style("baseline-shift","0%").attr("opacity",0).call(i).merge(r).transition(f).delay(A._delay).call(i).attr("opacity",1)}}).transition(f).call(B);var D=Object.keys(this._on),E=D.reduce(function(u,t){u[t]=function(u,n){return o._on[t](u.data,n)};return u},{});for(var F=0;F<D.length;F++){C.on(D[F],E[D[F]])}if(i){setTimeout(i,this._duration+100)}return this};o.prototype.data=function u(t){return arguments.length?(this._data=t,this):this._data};o.prototype.delay=function u(t){return arguments.length?(this._delay=t,this):this._delay};o.prototype.duration=function u(t){return arguments.length?(this._duration=t,this):this._duration};o.prototype.ellipsis=function u(t){return arguments.length?(this._ellipsis=typeof t==="function"?t:i.constant(t),this):this._ellipsis};o.prototype.fontColor=function u(t){return arguments.length?(this._fontColor=typeof t==="function"?t:i.constant(t),this):this._fontColor};o.prototype.fontFamily=function u(t){return arguments.length?(this._fontFamily=typeof t==="function"?t:i.constant(t),this):this._fontFamily};o.prototype.fontMax=function u(t){return arguments.length?(this._fontMax=typeof t==="function"?t:i.constant(t),this):this._fontMax};o.prototype.fontMin=function u(t){return arguments.length?(this._fontMin=typeof t==="function"?t:i.constant(t),this):this._fontMin};o.prototype.fontResize=function u(t){return arguments.length?(this._fontResize=typeof t==="function"?t:i.constant(t),this):this._fontResize};o.prototype.fontSize=function u(t){return arguments.length?(this._fontSize=typeof t==="function"?t:i.constant(t),this):this._fontSize};o.prototype.fontWeight=function u(t){return arguments.length?(this._fontWeight=typeof t==="function"?t:i.constant(t),this):this._fontWeight};o.prototype.height=function u(t){return arguments.length?(this._height=typeof t==="function"?t:i.constant(t),this):this._height};o.prototype.id=function u(t){return arguments.length?(this._id=typeof t==="function"?t:i.constant(t),this):this._id};o.prototype.lineHeight=function u(t){return arguments.length?(this._lineHeight=typeof t==="function"?t:i.constant(t),this):this._lineHeight};o.prototype.overflow=function u(t){return arguments.length?(this._overflow=typeof t==="function"?t:i.constant(t),this):this._overflow};o.prototype.pointerEvents=function u(t){return arguments.length?(this._pointerEvents=typeof t==="function"?t:i.constant(t),this):this._pointerEvents};o.prototype.rotate=function u(t){return arguments.length?(this._rotate=typeof t==="function"?t:i.constant(t),this):this._rotate};o.prototype.select=function u(n){return arguments.length?(this._select=t.select(n),this):this._select};o.prototype.split=function u(t){return arguments.length?(this._split=t,this):this._split};o.prototype.text=function u(t){return arguments.length?(this._text=typeof t==="function"?t:i.constant(t),this):this._text};o.prototype.textAnchor=function u(t){return arguments.length?(this._textAnchor=typeof t==="function"?t:i.constant(t),this):this._textAnchor};o.prototype.verticalAlign=function u(t){return arguments.length?(this._verticalAlign=typeof t==="function"?t:i.constant(t),this):this._verticalAlign};o.prototype.width=function u(t){return arguments.length?(this._width=typeof t==="function"?t:i.constant(t),this):this._width};o.prototype.x=function u(t){return arguments.length?(this._x=typeof t==="function"?t:i.constant(t),this):this._x};o.prototype.y=function u(t){return arguments.length?(this._y=typeof t==="function"?t:i.constant(t),this):this._y};return o}(i.BaseClass);var q=function(u,t){if(u===void 0){return""}t=Object.assign({lng:"en-US"},t);var n=t.lng;var e=i.locale.t("array.lowercase",{lng:n,returnObjects:true}).map(function(u){return u.toLowerCase()});var r=i.locale.t("array.uppercase",{lng:n,returnObjects:true});r=r.concat(r.map(function(u){return u+"s"}));var o=r.map(function(u){return u.toLowerCase()});var A=O(u);return A.map(function(u,t){if(u){var n=u.toLowerCase();var i=x.includes(n.charAt(n.length-1))?n.slice(0,-1):n;var s=o.indexOf(i);if(s>=0){return r[s]}else if(e.includes(i)&&t!==0&&t!==A.length-1){return n}else{return u.charAt(0).toUpperCase()+u.substr(1).toLowerCase()}}else{return""}}).reduce(function(t,n,e){if(e&&u.charAt(t.length)===" "){t+=" "}t+=n;return t},"")};u.fontExists=l;u.stringify=h;u.strip=p;u.TextBox=k;u.textSplit=O;u.textWidth=r;u.textWrap=R;u.titleCase=q;u.trim=o;u.trimLeft=A;u.trimRight=s;Object.defineProperty(u,"__esModule",{value:true})}); |
@@ -9,1 +9,2 @@ export {default as fontExists} from "./src/fontExists"; | ||
export {default as titleCase} from "./src/titleCase"; | ||
export {trim, trimLeft, trimRight} from "./src/trim"; |
{ | ||
"name": "d3plus-text", | ||
"version": "0.9.18", | ||
"version": "0.9.19", | ||
"description": "A smart SVG text box with line wrapping and automatic font size scaling.", | ||
@@ -29,3 +29,3 @@ "main": "build/d3plus-text.js", | ||
"d3-transition": "^1.1.0", | ||
"d3plus-common": "^0.6.18" | ||
"d3plus-common": "^0.6.22" | ||
}, | ||
@@ -41,4 +41,4 @@ "scripts": { | ||
"devDependencies": { | ||
"d3plus-dev": "^0.4.10" | ||
"d3plus-dev": "^0.4.13" | ||
} | ||
} |
249
README.md
@@ -57,2 +57,5 @@ # d3plus-text | ||
##### Classes | ||
* [TextBox](#TextBox) | ||
##### Functions | ||
@@ -62,3 +65,2 @@ * [fontExists](#fontExists) - Given either a single font-family or a list of fonts, returns the name of the first font that can be rendered, or `false` if none are installed on the user's machine. | ||
* [strip](#strip) - Removes all non ASCII characters from a string. | ||
* [TextBox](#TextBox) - Creates a wrapped text box for each point in an array of data. See [this example](https://d3plus.org/examples/d3plus-text/getting-started/) for help getting started using the textBox function. | ||
* [textSplit](#textSplit) - Splits a given sentence into an array of words. | ||
@@ -68,46 +70,17 @@ * [textWidth](#textWidth) - Given a text string, returns the predicted pixel width of the string when placed into DOM. | ||
* [titleCase](#titleCase) - Capitalizes the first letter of each word in a phrase/sentence. | ||
* [trim](#trim) - Cross-browser implementation of [trim](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim). | ||
* [trimLeft](#trimLeft) - Cross-browser implementation of [trimLeft](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/TrimLeft). | ||
* [trimRight](#trimRight) - Cross-browser implementation of [trimRight](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/TrimRight). | ||
--- | ||
<a name="fontExists"></a> | ||
#### d3plus.**fontExists**(font) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/fontExists.js#L9) | ||
Given either a single font-family or a list of fonts, returns the name of the first font that can be rendered, or `false` if none are installed on the user's machine. | ||
This is a global function. | ||
**Returns**: <code>String</code> \| <code>Boolean</code> - Either the name of the first font that can be rendered, or `false` if none are installed on the user's machine. | ||
--- | ||
<a name="stringify"></a> | ||
#### d3plus.**stringify**(value) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/stringify.js#L1) | ||
Coerces value into a String. | ||
This is a global function. | ||
--- | ||
<a name="strip"></a> | ||
#### d3plus.**strip**(value) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/strip.js#L18) | ||
Removes all non ASCII characters from a string. | ||
This is a global function. | ||
--- | ||
<a name="TextBox"></a> | ||
#### d3plus.**TextBox**() [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L10) | ||
#### **TextBox** [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L11) | ||
Creates a wrapped text box for each point in an array of data. See [this example](https://d3plus.org/examples/d3plus-text/getting-started/) for help getting started using the textBox function. | ||
This is a global class, and extends all of the methods and functionality of <code>BaseClass</code>. | ||
This is a global function, and extends all of the methods and functionality of <code>BaseClass</code>. | ||
* [TextBox()](#TextBox) ⇐ <code>BaseClass</code> | ||
* [TextBox](#TextBox) ⇐ <code>BaseClass</code> | ||
* [new TextBox()](#new_TextBox_new) | ||
* [.render([*callback*])](#TextBox.render) | ||
@@ -140,4 +113,13 @@ * [.data([*data*])](#TextBox.data) | ||
<a name="TextBox.render" href="TextBox.render">#</a> d3plus..**render**([*callback*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L57) | ||
<a name="new_TextBox_new" href="#new_TextBox_new">#</a> new **TextBox**() | ||
Creates a wrapped text box for each point in an array of data. See [this example](https://d3plus.org/examples/d3plus-text/getting-started/) for help getting started using the textBox function. | ||
<a name="TextBox.render" href="#TextBox.render">#</a> TextBox.**render**([*callback*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L58) | ||
Renders the text boxes. If a *callback* is specified, it will be called once the shapes are done drawing. | ||
@@ -148,4 +130,5 @@ | ||
<a name="TextBox.data" href="TextBox.data">#</a> d3plus..**data**([*data*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L301) | ||
<a name="TextBox.data" href="#TextBox.data">#</a> TextBox.**data**([*data*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L302) | ||
If *data* is specified, sets the data array to the specified array and returns this generator. If *data* is not specified, returns the current data array. A text box will be drawn for each object in the array. | ||
@@ -156,4 +139,5 @@ | ||
<a name="TextBox.delay" href="TextBox.delay">#</a> d3plus..**delay**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L310) | ||
<a name="TextBox.delay" href="#TextBox.delay">#</a> TextBox.**delay**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L311) | ||
If *value* is specified, sets the animation delay to the specified number and returns this generator. If *value* is not specified, returns the current animation delay. | ||
@@ -164,4 +148,5 @@ | ||
<a name="TextBox.duration" href="TextBox.duration">#</a> d3plus..**duration**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L319) | ||
<a name="TextBox.duration" href="#TextBox.duration">#</a> TextBox.**duration**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L320) | ||
If *value* is specified, sets the animation duration to the specified number and returns this generator. If *value* is not specified, returns the current animation duration. | ||
@@ -172,4 +157,5 @@ | ||
<a name="TextBox.ellipsis" href="TextBox.ellipsis">#</a> d3plus..**ellipsis**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L332) | ||
<a name="TextBox.ellipsis" href="#TextBox.ellipsis">#</a> TextBox.**ellipsis**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L333) | ||
If *value* is specified, sets the ellipsis method to the specified function or string and returns this generator. If *value* is not specified, returns the current ellipsis method, which simply adds an ellipsis to the string by default. | ||
@@ -179,4 +165,4 @@ | ||
This is a static method of [<code>TextBox</code>](#TextBox). | ||
default accessor | ||
default accessor | ||
```js | ||
@@ -187,4 +173,6 @@ function(d) { | ||
``` | ||
<a name="TextBox.fontColor" href="TextBox.fontColor">#</a> d3plus..**fontColor**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L341) | ||
<a name="TextBox.fontColor" href="#TextBox.fontColor">#</a> TextBox.**fontColor**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L342) | ||
If *value* is specified, sets the font color accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current font color accessor, which is inferred from the [container element](#textBox.select) by default. | ||
@@ -195,4 +183,5 @@ | ||
<a name="TextBox.fontFamily" href="TextBox.fontFamily">#</a> d3plus..**fontFamily**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L350) | ||
<a name="TextBox.fontFamily" href="#TextBox.fontFamily">#</a> TextBox.**fontFamily**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L351) | ||
If *value* is specified, sets the font family accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current font family accessor, which is inferred from the [container element](#textBox.select) by default. | ||
@@ -203,4 +192,5 @@ | ||
<a name="TextBox.fontMax" href="TextBox.fontMax">#</a> d3plus..**fontMax**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L359) | ||
<a name="TextBox.fontMax" href="#TextBox.fontMax">#</a> TextBox.**fontMax**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L360) | ||
If *value* is specified, sets the maximum font size accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current maximum font size accessor. The maximum font size is used when [resizing fonts](#textBox.fontResize) dynamically. | ||
@@ -211,4 +201,5 @@ | ||
<a name="TextBox.fontMin" href="TextBox.fontMin">#</a> d3plus..**fontMin**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L368) | ||
<a name="TextBox.fontMin" href="#TextBox.fontMin">#</a> TextBox.**fontMin**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L369) | ||
If *value* is specified, sets the minimum font size accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current minimum font size accessor. The minimum font size is used when [resizing fonts](#textBox.fontResize) dynamically. | ||
@@ -219,4 +210,5 @@ | ||
<a name="TextBox.fontResize" href="TextBox.fontResize">#</a> d3plus..**fontResize**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L377) | ||
<a name="TextBox.fontResize" href="#TextBox.fontResize">#</a> TextBox.**fontResize**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L378) | ||
If *value* is specified, sets the font resizing accessor to the specified function or boolean and returns this generator. If *value* is not specified, returns the current font resizing accessor. | ||
@@ -227,4 +219,5 @@ | ||
<a name="TextBox.fontSize" href="TextBox.fontSize">#</a> d3plus..**fontSize**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L386) | ||
<a name="TextBox.fontSize" href="#TextBox.fontSize">#</a> TextBox.**fontSize**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L387) | ||
If *value* is specified, sets the font size accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current font size accessor, which is inferred from the [container element](#textBox.select) by default. | ||
@@ -235,4 +228,5 @@ | ||
<a name="TextBox.fontWeight" href="TextBox.fontWeight">#</a> d3plus..**fontWeight**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L395) | ||
<a name="TextBox.fontWeight" href="#TextBox.fontWeight">#</a> TextBox.**fontWeight**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L396) | ||
If *value* is specified, sets the font weight accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current font weight accessor, which is inferred from the [container element](#textBox.select) by default. | ||
@@ -243,4 +237,5 @@ | ||
<a name="TextBox.height" href="TextBox.height">#</a> d3plus..**height**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L408) | ||
<a name="TextBox.height" href="#TextBox.height">#</a> TextBox.**height**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L409) | ||
If *value* is specified, sets the height accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current height accessor. | ||
@@ -250,4 +245,4 @@ | ||
This is a static method of [<code>TextBox</code>](#TextBox). | ||
default accessor | ||
default accessor | ||
```js | ||
@@ -258,4 +253,6 @@ function(d) { | ||
``` | ||
<a name="TextBox.id" href="TextBox.id">#</a> d3plus..**id**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L421) | ||
<a name="TextBox.id" href="#TextBox.id">#</a> TextBox.**id**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L422) | ||
If *value* is specified, sets the id accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current id accessor. | ||
@@ -265,4 +262,4 @@ | ||
This is a static method of [<code>TextBox</code>](#TextBox). | ||
default accessor | ||
default accessor | ||
```js | ||
@@ -273,4 +270,6 @@ function(d, i) { | ||
``` | ||
<a name="TextBox.lineHeight" href="TextBox.lineHeight">#</a> d3plus..**lineHeight**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L430) | ||
<a name="TextBox.lineHeight" href="#TextBox.lineHeight">#</a> TextBox.**lineHeight**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L431) | ||
If *value* is specified, sets the line height accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current line height accessor, which is 1.1 times the [font size](#textBox.fontSize) by default. | ||
@@ -281,4 +280,5 @@ | ||
<a name="TextBox.overflow" href="TextBox.overflow">#</a> d3plus..**overflow**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L439) | ||
<a name="TextBox.overflow" href="#TextBox.overflow">#</a> TextBox.**overflow**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L440) | ||
If *value* is specified, sets the overflow accessor to the specified function or boolean and returns this generator. If *value* is not specified, returns the current overflow accessor. | ||
@@ -289,4 +289,5 @@ | ||
<a name="TextBox.pointerEvents" href="TextBox.pointerEvents">#</a> d3plus..**pointerEvents**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L448) | ||
<a name="TextBox.pointerEvents" href="#TextBox.pointerEvents">#</a> TextBox.**pointerEvents**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L449) | ||
If *value* is specified, sets the pointer-events accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current pointer-events accessor. | ||
@@ -297,4 +298,5 @@ | ||
<a name="TextBox.rotate" href="TextBox.rotate">#</a> d3plus..**rotate**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L457) | ||
<a name="TextBox.rotate" href="#TextBox.rotate">#</a> TextBox.**rotate**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L458) | ||
If *value* is specified, sets the rotate accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current rotate accessor. | ||
@@ -305,4 +307,5 @@ | ||
<a name="TextBox.select" href="TextBox.select">#</a> d3plus..**select**([*selector*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L466) | ||
<a name="TextBox.select" href="#TextBox.select">#</a> TextBox.**select**([*selector*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L467) | ||
If *selector* is specified, sets the SVG container element to the specified d3 selector or DOM element and returns this generator. If *selector* is not specified, returns the current SVG container element, which adds an SVG element to the page by default. | ||
@@ -313,4 +316,5 @@ | ||
<a name="TextBox.split" href="TextBox.split">#</a> d3plus..**split**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L475) | ||
<a name="TextBox.split" href="#TextBox.split">#</a> TextBox.**split**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L476) | ||
If *value* is specified, sets the word split function to the specified function and returns this generator. If *value* is not specified, returns the current word split function. | ||
@@ -321,4 +325,5 @@ | ||
<a name="TextBox.text" href="TextBox.text">#</a> d3plus..**text**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L488) | ||
<a name="TextBox.text" href="#TextBox.text">#</a> TextBox.**text**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L489) | ||
If *value* is specified, sets the text accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current text accessor. | ||
@@ -328,4 +333,4 @@ | ||
This is a static method of [<code>TextBox</code>](#TextBox). | ||
default accessor | ||
default accessor | ||
```js | ||
@@ -336,4 +341,6 @@ function(d) { | ||
``` | ||
<a name="TextBox.textAnchor" href="TextBox.textAnchor">#</a> d3plus..**textAnchor**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L497) | ||
<a name="TextBox.textAnchor" href="#TextBox.textAnchor">#</a> TextBox.**textAnchor**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L498) | ||
If *value* is specified, sets the horizontal text anchor accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current horizontal text anchor accessor. | ||
@@ -344,4 +351,5 @@ | ||
<a name="TextBox.verticalAlign" href="TextBox.verticalAlign">#</a> d3plus..**verticalAlign**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L506) | ||
<a name="TextBox.verticalAlign" href="#TextBox.verticalAlign">#</a> TextBox.**verticalAlign**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L507) | ||
If *value* is specified, sets the vertical alignment accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current vertical alignment accessor. | ||
@@ -352,4 +360,5 @@ | ||
<a name="TextBox.width" href="TextBox.width">#</a> d3plus..**width**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L519) | ||
<a name="TextBox.width" href="#TextBox.width">#</a> TextBox.**width**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L520) | ||
If *value* is specified, sets the width accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current width accessor. | ||
@@ -359,4 +368,4 @@ | ||
This is a static method of [<code>TextBox</code>](#TextBox). | ||
default accessor | ||
default accessor | ||
```js | ||
@@ -367,4 +376,6 @@ function(d) { | ||
``` | ||
<a name="TextBox.x" href="TextBox.x">#</a> d3plus..**x**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L532) | ||
<a name="TextBox.x" href="#TextBox.x">#</a> TextBox.**x**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L533) | ||
If *value* is specified, sets the x accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current x accessor. The number returned should correspond to the left position of the textBox. | ||
@@ -374,4 +385,4 @@ | ||
This is a static method of [<code>TextBox</code>](#TextBox). | ||
default accessor | ||
default accessor | ||
```js | ||
@@ -382,4 +393,6 @@ function(d) { | ||
``` | ||
<a name="TextBox.y" href="TextBox.y">#</a> d3plus..**y**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L545) | ||
<a name="TextBox.y" href="#TextBox.y">#</a> TextBox.**y**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/TextBox.js#L546) | ||
If *value* is specified, sets the y accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current y accessor. The number returned should correspond to the top position of the textBox. | ||
@@ -389,4 +402,4 @@ | ||
This is a static method of [<code>TextBox</code>](#TextBox). | ||
default accessor | ||
default accessor | ||
```js | ||
@@ -397,4 +410,36 @@ function(d) { | ||
``` | ||
--- | ||
<a name="fontExists"></a> | ||
#### d3plus.**fontExists**(font) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/fontExists.js#L10) | ||
Given either a single font-family or a list of fonts, returns the name of the first font that can be rendered, or `false` if none are installed on the user's machine. | ||
This is a global function. | ||
**Returns**: <code>String</code> \| <code>Boolean</code> - Either the name of the first font that can be rendered, or `false` if none are installed on the user's machine. | ||
--- | ||
<a name="stringify"></a> | ||
#### d3plus.**stringify**(value) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/stringify.js#L1) | ||
Coerces value into a String. | ||
This is a global function. | ||
--- | ||
<a name="strip"></a> | ||
#### d3plus.**strip**(value) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/strip.js#L18) | ||
Removes all non ASCII characters from a string. | ||
This is a global function. | ||
--- | ||
<a name="textSplit"></a> | ||
@@ -418,3 +463,2 @@ #### d3plus.**textSplit**(sentence) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textSplit.js#L50) | ||
| Param | Type | Description | | ||
@@ -425,6 +469,7 @@ | --- | --- | --- | | ||
--- | ||
<a name="textWrap"></a> | ||
#### d3plus.**textWrap**() [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L5) | ||
#### d3plus.**textWrap**() [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L6) | ||
@@ -447,4 +492,5 @@ Based on the defined styles and dimensions, breaks a string into an array of strings for each line of text. | ||
<a name="textWrap.fontFamily" href="textWrap.fontFamily">#</a> d3plus..**fontFamily**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L85) | ||
<a name="textWrap.fontFamily" href="#textWrap.fontFamily">#</a> d3plus..**fontFamily**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L86) | ||
If *value* is specified, sets the font family accessor to the specified function or string and returns this generator. If *value* is not specified, returns the current font family. | ||
@@ -455,4 +501,5 @@ | ||
<a name="textWrap.fontSize" href="textWrap.fontSize">#</a> d3plus..**fontSize**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L94) | ||
<a name="textWrap.fontSize" href="#textWrap.fontSize">#</a> d3plus..**fontSize**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L95) | ||
If *value* is specified, sets the font size accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current font size. | ||
@@ -463,4 +510,5 @@ | ||
<a name="textWrap.fontWeight" href="textWrap.fontWeight">#</a> d3plus..**fontWeight**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L103) | ||
<a name="textWrap.fontWeight" href="#textWrap.fontWeight">#</a> d3plus..**fontWeight**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L104) | ||
If *value* is specified, sets the font weight accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current font weight. | ||
@@ -471,4 +519,5 @@ | ||
<a name="textWrap.height" href="textWrap.height">#</a> d3plus..**height**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L112) | ||
<a name="textWrap.height" href="#textWrap.height">#</a> d3plus..**height**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L113) | ||
If *value* is specified, sets height limit to the specified value and returns this generator. If *value* is not specified, returns the current value. | ||
@@ -479,4 +528,5 @@ | ||
<a name="textWrap.lineHeight" href="textWrap.lineHeight">#</a> d3plus..**lineHeight**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L121) | ||
<a name="textWrap.lineHeight" href="#textWrap.lineHeight">#</a> d3plus..**lineHeight**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L122) | ||
If *value* is specified, sets the line height accessor to the specified function or number and returns this generator. If *value* is not specified, returns the current line height accessor, which is 1.1 times the [font size](#textWrap.fontSize) by default. | ||
@@ -487,4 +537,5 @@ | ||
<a name="textWrap.overflow" href="textWrap.overflow">#</a> d3plus..**overflow**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L130) | ||
<a name="textWrap.overflow" href="#textWrap.overflow">#</a> d3plus..**overflow**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L131) | ||
If *value* is specified, sets the overflow to the specified boolean and returns this generator. If *value* is not specified, returns the current overflow value. | ||
@@ -495,4 +546,5 @@ | ||
<a name="textWrap.split" href="textWrap.split">#</a> d3plus..**split**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L139) | ||
<a name="textWrap.split" href="#textWrap.split">#</a> d3plus..**split**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L140) | ||
If *value* is specified, sets the word split function to the specified function and returns this generator. If *value* is not specified, returns the current word split function. | ||
@@ -503,4 +555,5 @@ | ||
<a name="textWrap.width" href="textWrap.width">#</a> d3plus..**width**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L148) | ||
<a name="textWrap.width" href="#textWrap.width">#</a> d3plus..**width**([*value*]) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/textWrap.js#L149) | ||
If *value* is specified, sets width limit to the specified value and returns this generator. If *value* is not specified, returns the current value. | ||
@@ -521,3 +574,2 @@ | ||
| Param | Type | Description | | ||
@@ -529,4 +581,37 @@ | --- | --- | --- | | ||
--- | ||
###### <sub>Documentation generated on Fri, 26 May 2017 19:59:36 GMT</sub> | ||
<a name="trim"></a> | ||
#### d3plus.**trim**(str) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/trim.js#L1) | ||
Cross-browser implementation of [trim](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim). | ||
This is a global function. | ||
--- | ||
<a name="trimLeft"></a> | ||
#### d3plus.**trimLeft**(str) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/trim.js#L10) | ||
Cross-browser implementation of [trimLeft](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/TrimLeft). | ||
This is a global function. | ||
--- | ||
<a name="trimRight"></a> | ||
#### d3plus.**trimRight**(str) [<>](https://github.com/d3plus/d3plus-text/blob/master/src/trim.js#L19) | ||
Cross-browser implementation of [trimRight](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/TrimRight). | ||
This is a global function. | ||
--- | ||
###### <sub>Documentation generated on Fri, 21 Jul 2017 22:48:30 GMT</sub> |
import {default as textWidth} from "./textWidth"; | ||
import {trim} from "./trim"; | ||
@@ -25,3 +26,3 @@ const alpha = "abcdefghiABCDEFGHI_!@#$%^&*()_+1234567890", | ||
if (!(font instanceof Array)) font = font.split(","); | ||
font = font.map(f => f.trim()); | ||
font = font.map(f => trim(f)); | ||
@@ -28,0 +29,0 @@ for (let i = 0; i < font.length; i++) { |
@@ -9,5 +9,6 @@ import {select} from "d3-selection"; | ||
import {default as wrap} from "./textWrap"; | ||
import {trimRight} from "./trim"; | ||
/** | ||
@function TextBox | ||
@class TextBox | ||
@extends BaseClass | ||
@@ -243,3 +244,3 @@ @desc Creates a wrapped text box for each point in an array of data. See [this example](https://d3plus.org/examples/d3plus-text/getting-started/) for help getting started using the textBox function. | ||
tspan | ||
.text(t => t.trimRight()) | ||
.text(t => trimRight(t)) | ||
.attr("x", `${d.x}px`) | ||
@@ -246,0 +247,0 @@ .attr("dx", `${dx}px`) |
import {default as measure} from "./textWidth"; | ||
import {default as defaultSplit} from "./textSplit"; | ||
import {default as stringify} from "./stringify"; | ||
import {trimRight} from "./trim"; | ||
@@ -57,3 +58,3 @@ /** | ||
} | ||
lineData[line - 1] = lineData[line - 1].trimRight(); | ||
lineData[line - 1] = trimRight(lineData[line - 1]); | ||
line++; | ||
@@ -60,0 +61,0 @@ if (lineHeight * line > height || wordWidth > width && !overflow) { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
1070428
28
7151
569
Updatedd3plus-common@^0.6.22