New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

d3plus-text

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3plus-text - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

.eslintignore

54

build/d3plus-text.js

@@ -9,2 +9,6 @@ (function (global, factory) {

/**
Wraps non-function variables in a simple return function.
@private
*/
function constant (x) {

@@ -16,2 +20,6 @@ return function constant() {

/**
The default ellipsis function.
@private
*/
function boxEllipsis(_) {

@@ -27,2 +35,6 @@ if (_.includes(" ")) {

var splitRegex = new RegExp("[^\\s\\" + splitChars.join("\\") + "]+\\" + splitChars.join("?\\") + "?", "g");
/**
The default word split function.
@private
*/
function boxSplit(_) {

@@ -35,10 +47,10 @@ return _.match(splitRegex);

var ellipsis = boxEllipsis,
fontColor,
fontFamily,
fontSize,
fontColor = undefined,
fontFamily = undefined,
fontSize = undefined,
height = constant(200),
lineHeight,
select,
lineHeight = undefined,
select = undefined,
split = boxSplit,
text,
text = undefined,
width = constant(200),

@@ -52,5 +64,3 @@ x = constant(0),

h = height(select),
l = 1,
lH = lineHeight(),
p = "",
t = text(select),

@@ -60,2 +70,5 @@ w = width(select),

var l = 1,
p = "";
select.attr("y", y(select) + "px").attr("fill", fontColor()).attr("font-family", fontFamily()).attr("font-size", fS + "px").size("font-size", fS + "px");

@@ -69,5 +82,5 @@

function addWord(word) {
var temp = p + word,
curr = tspan.html(),
join = t.charAt(temp.length);
var curr = tspan.html(),
temp = p + word;
var join = t.charAt(temp.length);
tspan.html(curr + word);

@@ -79,5 +92,5 @@

if (tspan.size()) {
t = tspan.html();
var e = ellipsis(t);
tspan.html(e ? e : t);
var tl = tspan.html();
var e = ellipsis(tl);
tspan.html(e ? e : tl);
}

@@ -87,2 +100,3 @@ return false;

tspan.html(curr.trimRight());
if (l === 1 && curr === "") return false;
tspan = select.append("tspan").call(tspanStyle);

@@ -108,5 +122,3 @@ l++;

var r = addWord(word);
if (!r) {
break;
}
if (!r) break;
}

@@ -154,8 +166,4 @@ } catch (err) {

text = constant(select.text());
if (fontColor === void 0) {
fontColor = constant(select.style("font-color"));
}
if (fontFamily === void 0) {
fontFamily = constant(select.style("font-family"));
}
if (fontColor === void 0) fontColor = constant(select.style("font-color"));
if (fontFamily === void 0) fontFamily = constant(select.style("font-family"));
if (fontSize === void 0) {

@@ -162,0 +170,0 @@ fontSize = constant(parseFloat(select.style("font-size"), 10));

@@ -1,1 +0,1 @@

!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3-selection")):"function"==typeof define&&define.amd?define("d3plus-text",["exports","d3-selection"],n):n(t.d3plus_text={},t.d3_selection)}(this,function(t,n){"use strict";function e(t){return function(){return t}}function r(t){if(t.includes(" ")){var n=t.split(/\s+/);return t.replace(" "+n[n.length-1],"...")}return"..."}function o(t){return t.match(l)}function i(){function t(){function t(t){t.attr("x",j+"px").attr("dx","0px").attr("dy",x+"px").attr("dominant-baseline","alphabetic").style("baseline-shift","0%")}function e(r){var i=v+r,u=w.html(),f=b.charAt(i.length);if(w.html(u+r),a.node().getBBox().height>o){if(w.remove(),w=n.select(a.node().lastChild),w.size()){b=w.html();var l=s(b);w.html(l?l:b)}return!1}if(w.node().getComputedTextLength()>z)return w.html(u.trimRight()),w=a.append("tspan").call(t),y++,e(r);var c=" "===f?" ":"";return v=i+c,w.html(u+r+c),!0}var r=f(),o=p(a),y=1,x=l(),v="",b=c(a),z=g(a),j=d(a);a.attr("y",m(a)+"px").attr("fill",i()).attr("font-family",u()).attr("font-size",r+"px").size("font-size",r+"px");var w=a.html("").append("tspan").call(t),C=!0,B=!1,F=void 0;try{for(var R,S=h(b)[Symbol.iterator]();!(C=(R=S.next()).done);C=!0){var _=R.value,k=e(_);if(!k)break}}catch(q){B=!0,F=q}finally{try{!C&&S["return"]&&S["return"]()}finally{if(B)throw F}}}var i,u,f,l,a,c,s=r,p=e(200),h=o,g=e(200),d=e(0),m=e(0);return t.ellipsis=function(n){return arguments.length?(s="function"==typeof n?n:e(n),t):s},t.fontColor=function(n){return arguments.length?(i="function"==typeof n?n:e(n),t):i},t.fontFamily=function(n){return arguments.length?(u="function"==typeof n?n:e(n),t):u},t.fontSize=function(n){return arguments.length?(f="function"==typeof n?n:e(n),t):f},t.height=function(n){return arguments.length?(p="function"==typeof n?n:e(n),t):p},t.select=function(r){return arguments.length?(a=n.select(r),void 0===c&&(c=e(a.text()),void 0===i&&(i=e(a.style("font-color"))),void 0===u&&(u=e(a.style("font-family"))),void 0===f&&(f=e(parseFloat(a.style("font-size"),10)),l=e(Math.ceil(1.1*f())))),t):a},t.split=function(n){return arguments.length?(h=n,t):h},t.text=function(n){return arguments.length?(c="function"==typeof n?n:e(n),t):c},t.width=function(n){return arguments.length?(g="function"==typeof n?n:e(n),t):g},t.x=function(n){return arguments.length?(d="function"==typeof n?n:e(n),t):d},t.y=function(n){return arguments.length?(m="function"==typeof n?n:e(n),t):m},t}var u="0.2.0",f=["-","/",";",":","&"],l=new RegExp("[^\\s\\"+f.join("\\")+"]+\\"+f.join("?\\")+"?","g");t.version=u,t.box=i});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3-selection")):"function"==typeof define&&define.amd?define("d3plus-text",["exports","d3-selection"],n):n(t.d3plus_text={},t.d3_selection)}(this,function(t,n){"use strict";function e(t){return function(){return t}}function r(t){if(t.includes(" ")){var n=t.split(/\s+/);return t.replace(" "+n[n.length-1],"...")}return"..."}function o(t){return t.match(l)}function i(){function t(){function t(t){t.attr("x",b+"px").attr("dx","0px").attr("dy",y+"px").attr("dominant-baseline","alphabetic").style("baseline-shift","0%")}function e(r){var u=w.html(),f=j+r,l=v.charAt(f.length);if(w.html(u+r),s.node().getBBox().height>o){if(w.remove(),w=n.select(s.node().lastChild),w.size()){var a=w.html(),c=i(a);w.html(c?c:a)}return!1}if(w.node().getComputedTextLength()>x)return w.html(u.trimRight()),1===z&&""===u?!1:(w=s.append("tspan").call(t),z++,e(r));var p=" "===l?" ":"";return j=f+p,w.html(u+r+p),!0}var r=l(),o=a(s),y=c(),v=d(s),x=h(s),b=g(s),z=1,j="";s.attr("y",m(s)+"px").attr("fill",u()).attr("font-family",f()).attr("font-size",r+"px").size("font-size",r+"px");var w=s.html("").append("tspan").call(t),C=!0,B=!1,F=void 0;try{for(var R,S=p(v)[Symbol.iterator]();!(C=(R=S.next()).done);C=!0){var _=R.value,k=e(_);if(!k)break}}catch(q){B=!0,F=q}finally{try{!C&&S["return"]&&S["return"]()}finally{if(B)throw F}}}var i=r,u=void 0,f=void 0,l=void 0,a=e(200),c=void 0,s=void 0,p=o,d=void 0,h=e(200),g=e(0),m=e(0);return t.ellipsis=function(n){return arguments.length?(i="function"==typeof n?n:e(n),t):i},t.fontColor=function(n){return arguments.length?(u="function"==typeof n?n:e(n),t):u},t.fontFamily=function(n){return arguments.length?(f="function"==typeof n?n:e(n),t):f},t.fontSize=function(n){return arguments.length?(l="function"==typeof n?n:e(n),t):l},t.height=function(n){return arguments.length?(a="function"==typeof n?n:e(n),t):a},t.select=function(r){return arguments.length?(s=n.select(r),void 0===d&&(d=e(s.text()),void 0===u&&(u=e(s.style("font-color"))),void 0===f&&(f=e(s.style("font-family"))),void 0===l&&(l=e(parseFloat(s.style("font-size"),10)),c=e(Math.ceil(1.1*l())))),t):s},t.split=function(n){return arguments.length?(p=n,t):p},t.text=function(n){return arguments.length?(d="function"==typeof n?n:e(n),t):d},t.width=function(n){return arguments.length?(h="function"==typeof n?n:e(n),t):h},t.x=function(n){return arguments.length?(g="function"==typeof n?n:e(n),t):g},t.y=function(n){return arguments.length?(m="function"==typeof n?n:e(n),t):m},t}var u="0.2.0",f=["-","/",";",":","&"],l=new RegExp("[^\\s\\"+f.join("\\")+"]+\\"+f.join("?\\")+"?","g");t.version=u,t.box=i});
{
"name": "d3plus-text",
"version": "0.2.0",
"version": "0.2.1",
"description": "Smart SVG text box with line wrapping and automatic font scaling.",

@@ -31,3 +31,3 @@ "main": "build/d3plus-text.js",

"casperjs": "^1.1.0-beta3",
"eslint": "^0.24.1",
"eslint": "^1.10.3",
"jsdoc-to-markdown": "^1.1.1",

@@ -34,0 +34,0 @@ "node-static": "^0.7.7",

@@ -11,3 +11,3 @@ import json from "rollup-plugin-json";

moduleName: "d3plus_text",
plugins: [json(), babel()]
plugins: [json(), babel({"presets": ["es2015-rollup"]})]
};
import {select as d3} from "d3-selection";
import {default as constant} from "./constant";
/**
The default ellipsis function.
@private
*/
function boxEllipsis(_) {
if (_.includes(" ")) {
var a = _.split(/\s+/);
const a = _.split(/\s+/);
return _.replace(` ${a[a.length - 1]}`, "...");

@@ -12,4 +16,9 @@ }

var splitChars = ["-", "/", ";", ":", "&"],
splitRegex = new RegExp("[^\\s\\" + splitChars.join("\\") + "]+\\" + splitChars.join("?\\") + "?", "g");
const splitChars = ["-", "/", ";", ":", "&"],
splitRegex = new RegExp(`[^\\s\\${splitChars.join("\\")}]+\\${splitChars.join("?\\")}?`, "g");
/**
The default word split function.
@private
*/
function boxSplit(_) {

@@ -21,3 +30,3 @@ return _.match(splitRegex);

var ellipsis = boxEllipsis,
let ellipsis = boxEllipsis,
fontColor,

@@ -37,11 +46,12 @@ fontFamily,

var fS = fontSize(),
h = height(select),
l = 1,
lH = lineHeight(),
p = "",
t = text(select),
w = width(select),
xP = x(select);
const fS = fontSize(),
h = height(select),
lH = lineHeight(),
t = text(select),
w = width(select),
xP = x(select);
let l = 1,
p = "";
select

@@ -63,7 +73,7 @@ .attr("y", `${y(select)}px`)

var tspan = select.html("").append("tspan").call(tspanStyle);
let tspan = select.html("").append("tspan").call(tspanStyle);
function addWord(word) {
var temp = p + word,
curr = tspan.html(),
join = t.charAt(temp.length);
const curr = tspan.html(),
temp = p + word;
const join = t.charAt(temp.length);
tspan.html(curr + word);

@@ -75,5 +85,5 @@

if (tspan.size()) {
t = tspan.html();
var e = ellipsis(t);
tspan.html(e ? e : t);
const tl = tspan.html();
const e = ellipsis(tl);
tspan.html(e ? e : tl);
}

@@ -84,2 +94,3 @@ return false;

tspan.html(curr.trimRight());
if (l === 1 && curr === "") return false;
tspan = select.append("tspan").call(tspanStyle);

@@ -90,3 +101,3 @@ l++;

else {
var char = join === " " ? " " : "";
const char = join === " " ? " " : "";
p = temp + char;

@@ -98,5 +109,5 @@ tspan.html(curr + word + char);

for (let word of split(t)) {
var r = addWord(word);
if (!r) { break; }
for (const word of split(t)) {
const r = addWord(word);
if (!r) break;
}

@@ -131,4 +142,4 @@

text = constant(select.text());
if (fontColor === void 0) { fontColor = constant(select.style("font-color")); }
if (fontFamily === void 0) { fontFamily = constant(select.style("font-family")); }
if (fontColor === void 0) fontColor = constant(select.style("font-color"));
if (fontFamily === void 0) fontFamily = constant(select.style("font-family"));
if (fontSize === void 0) {

@@ -135,0 +146,0 @@ fontSize = constant(parseFloat(select.style("font-size"), 10));

@@ -0,1 +1,5 @@

/**
Wraps non-function variables in a simple return function.
@private
*/
export default function(x) {

@@ -2,0 +6,0 @@ return function constant() {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc