d3plus-shape
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -9,4 +9,8 @@ (function (global, factory) { | ||
var version = "0.2.0"; | ||
var version = "0.2.1"; | ||
/** | ||
Wraps non-function variables in a simple return function. | ||
@private | ||
*/ | ||
function constant (x) { | ||
@@ -18,2 +22,6 @@ return function constant() { | ||
/** | ||
The default height accessor function. | ||
@private | ||
*/ | ||
function rectHeight(d) { | ||
@@ -23,2 +31,6 @@ return d.height; | ||
/** | ||
The default id accessor function. | ||
@private | ||
*/ | ||
function rectId(d) { | ||
@@ -28,2 +40,6 @@ return d.id; | ||
/** | ||
The default inner bounds function. | ||
@private | ||
*/ | ||
function rectInnerBounds(w, h) { | ||
@@ -33,2 +49,6 @@ return { "width": w, "height": h, "x": -w / 2, "y": -h / 2 }; | ||
/** | ||
The default width accessor function. | ||
@private | ||
*/ | ||
function rectWidth(d) { | ||
@@ -38,2 +58,6 @@ return d.width; | ||
/** | ||
The default x accessor function. | ||
@private | ||
*/ | ||
function rectX(d) { | ||
@@ -43,2 +67,6 @@ return d.x; | ||
/** | ||
The default y accessor function. | ||
@private | ||
*/ | ||
function rectY(d) { | ||
@@ -53,9 +81,9 @@ return d.y; | ||
var fill = constant("black"), | ||
data = [], | ||
var data = [], | ||
fill = constant("black"), | ||
height = rectHeight, | ||
id = rectId, | ||
innerBounds = rectInnerBounds, | ||
height = rectHeight, | ||
label, | ||
select, | ||
label = undefined, | ||
select = undefined, | ||
timing = 600, | ||
@@ -66,2 +94,6 @@ width = rectWidth, | ||
/** | ||
The inner return object and draw function that gets assigned the public methods. | ||
@private | ||
*/ | ||
function rect() { | ||
@@ -111,2 +143,3 @@ | ||
groups.each(function (d) { | ||
if (label !== void 0) { | ||
@@ -122,8 +155,4 @@ var b = innerBounds(width(d), height(d)); | ||
}).height(b.height).select(elem.node()).width(b.width).x(b.x).y(b.y)(); | ||
} else { | ||
d3.select(this).select("text").remove(); | ||
} | ||
} else { | ||
d3.select(this).select("text").remove(); | ||
} | ||
} else d3.select(this).select("text").remove(); | ||
} else d3.select(this).select("text").remove(); | ||
}); | ||
@@ -130,0 +159,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3"),require("d3plus-text"),require("d3plus-color")):"function"==typeof define&&define.amd?define("d3plus-shape",["exports","d3","d3plus-text","d3plus-color"],n):n(t.d3plus_shape={},t.d3,t.d3plus_text,t.d3plus_color)}(this,function(t,n,e,r){"use strict";function u(t){return function(){return t}}function i(t){return t.height}function o(t){return t.id}function c(t,n){return{width:t,height:n,x:-t/2,y:-n/2}}function a(t){return t.width}function f(t){return t.x}function l(t){return t.y}function s(){function t(){var u=d.selectAll(".d3plus-shape-rect").data(p,g),i=u.enter().append("g").attr("class","d3plus-shape-rect").attr("id",function(t){return"d3plus-shape-rect-"+g(t)}).attr("transform",function(t){return"translate("+w(t)+","+b(t)+")"});return i.append("rect").attr("width",0).attr("height",0).attr("x",0).attr("y",0).attr("fill",function(t){return h(t)}),u.transition().duration(y).attr("transform",function(t){return"translate("+w(t)+","+b(t)+")"}),u.selectAll("rect").transition().duration(y).attr("width",function(t){return v(t)}).attr("height",function(t){return m(t)}).attr("x",function(t){return-v(t)/2}).attr("y",function(t){return-m(t)/2}).attr("fill",function(t){return h(t)}),u.exit().transition().delay(y).remove(),u.exit().selectAll("rect").transition().duration(y).attr("width",0).attr("height",0).attr("x",function(t){return w(t)}).attr("y",function(t){return b(t)}),u.each(function(t){if(void 0!==s){var u=x(v(t),m(t));if(u){var i=n.select(this).selectAll("text").data([0]);i.enter().append("text").html(s(t)),e.box().fontColor(function(){return r.contrast(h(t))}).height(u.height).select(i.node()).width(u.width).x(u.x).y(u.y)()}else n.select(this).select("text").remove()}else n.select(this).select("text").remove()}),t}var s,d,h=u("black"),p=[],g=o,x=c,m=i,y=600,v=a,w=f,b=l;return t.data=function(n){return arguments.length?(p=n,t):p},t.fill=function(n){return arguments.length?(h="function"==typeof n?n:u(n),t):h},t.height=function(n){return arguments.length?(m="function"==typeof n?n:u(n),t):m},t.id=function(n){return arguments.length?(g=n,t):g},t.innerBounds=function(n){return arguments.length?(x=n,t):x},t.label=function(n){return arguments.length?(s="function"==typeof n?n:u(n),t):s},t.select=function(e){return arguments.length?(d=n.select(e),t):d},t.timing=function(n){return arguments.length?(y=n,t):y},t.width=function(n){return arguments.length?(v="function"==typeof n?n:u(n),t):v},t.x=function(n){return arguments.length?(w="function"==typeof n?n:u(n),t):w},t.y=function(n){return arguments.length?(b="function"==typeof n?n:u(n),t):b},t}n="default"in n?n["default"]:n;var d="0.2.0";t.version=d,t.rect=s}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3"),require("d3plus-text"),require("d3plus-color")):"function"==typeof define&&define.amd?define("d3plus-shape",["exports","d3","d3plus-text","d3plus-color"],n):n(t.d3plus_shape={},t.d3,t.d3plus_text,t.d3plus_color)}(this,function(t,n,e,r){"use strict";function u(t){return function(){return t}}function i(t){return t.height}function o(t){return t.id}function c(t,n){return{width:t,height:n,x:-t/2,y:-n/2}}function a(t){return t.width}function f(t){return t.x}function l(t){return t.y}function s(){function t(){var u=m.selectAll(".d3plus-shape-rect").data(s,p),i=u.enter().append("g").attr("class","d3plus-shape-rect").attr("id",function(t){return"d3plus-shape-rect-"+p(t)}).attr("transform",function(t){return"translate("+w(t)+","+b(t)+")"});return i.append("rect").attr("width",0).attr("height",0).attr("x",0).attr("y",0).attr("fill",function(t){return d(t)}),u.transition().duration(y).attr("transform",function(t){return"translate("+w(t)+","+b(t)+")"}),u.selectAll("rect").transition().duration(y).attr("width",function(t){return v(t)}).attr("height",function(t){return h(t)}).attr("x",function(t){return-v(t)/2}).attr("y",function(t){return-h(t)/2}).attr("fill",function(t){return d(t)}),u.exit().transition().delay(y).remove(),u.exit().selectAll("rect").transition().duration(y).attr("width",0).attr("height",0).attr("x",function(t){return w(t)}).attr("y",function(t){return b(t)}),u.each(function(t){if(void 0!==x){var u=g(v(t),h(t));if(u){var i=n.select(this).selectAll("text").data([0]);i.enter().append("text").html(x(t)),e.box().fontColor(function(){return r.contrast(d(t))}).height(u.height).select(i.node()).width(u.width).x(u.x).y(u.y)()}else n.select(this).select("text").remove()}else n.select(this).select("text").remove()}),t}var s=[],d=u("black"),h=i,p=o,g=c,x=void 0,m=void 0,y=600,v=a,w=f,b=l;return t.data=function(n){return arguments.length?(s=n,t):s},t.fill=function(n){return arguments.length?(d="function"==typeof n?n:u(n),t):d},t.height=function(n){return arguments.length?(h="function"==typeof n?n:u(n),t):h},t.id=function(n){return arguments.length?(p=n,t):p},t.innerBounds=function(n){return arguments.length?(g=n,t):g},t.label=function(n){return arguments.length?(x="function"==typeof n?n:u(n),t):x},t.select=function(e){return arguments.length?(m=n.select(e),t):m},t.timing=function(n){return arguments.length?(y=n,t):y},t.width=function(n){return arguments.length?(v="function"==typeof n?n:u(n),t):v},t.x=function(n){return arguments.length?(w="function"==typeof n?n:u(n),t):w},t.y=function(n){return arguments.length?(b="function"==typeof n?n:u(n),t):b},t}n="default"in n?n["default"]:n;var d="0.2.1";t.version=d,t.rect=s}); |
{ | ||
"name": "d3plus-shape", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Shape drawing for javascript visualizations.", | ||
@@ -49,4 +49,4 @@ "main": "build/d3plus-shape.js", | ||
"serve": "static -p 4000", | ||
"test": "npm run serve & eslint src/* test/browser/*.js && casperjs test ./test/browser/*.js && killall node" | ||
"test": "npm run serve & eslint index.js src/* && casperjs test ./test/browser/*.js && killall node" | ||
} | ||
} |
@@ -11,3 +11,3 @@ import json from "rollup-plugin-json"; | ||
moduleName: "d3plus_shape", | ||
plugins: [json(), babel()] | ||
plugins: [json(), babel({"presets": ["es2015-rollup"]})] | ||
}; |
@@ -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() { |
@@ -6,2 +6,6 @@ import {default as d3} from "d3"; | ||
/** | ||
The default height accessor function. | ||
@private | ||
*/ | ||
function rectHeight(d) { | ||
@@ -11,2 +15,6 @@ return d.height; | ||
/** | ||
The default id accessor function. | ||
@private | ||
*/ | ||
function rectId(d) { | ||
@@ -16,2 +24,6 @@ return d.id; | ||
/** | ||
The default inner bounds function. | ||
@private | ||
*/ | ||
function rectInnerBounds(w, h) { | ||
@@ -21,2 +33,6 @@ return {"width": w, "height": h, "x": -w / 2, "y": -h / 2}; | ||
/** | ||
The default width accessor function. | ||
@private | ||
*/ | ||
function rectWidth(d) { | ||
@@ -26,2 +42,6 @@ return d.width; | ||
/** | ||
The default x accessor function. | ||
@private | ||
*/ | ||
function rectX(d) { | ||
@@ -31,2 +51,6 @@ return d.x; | ||
/** | ||
The default y accessor function. | ||
@private | ||
*/ | ||
function rectY(d) { | ||
@@ -41,7 +65,7 @@ return d.y; | ||
var fill = constant("black"), | ||
data = [], | ||
let data = [], | ||
fill = constant("black"), | ||
height = rectHeight, | ||
id = rectId, | ||
innerBounds = rectInnerBounds, | ||
height = rectHeight, | ||
label, | ||
@@ -54,12 +78,16 @@ select, | ||
/** | ||
The inner return object and draw function that gets assigned the public methods. | ||
@private | ||
*/ | ||
function rect() { | ||
/* Bind data array to elements using provided id matching. */ | ||
var groups = select.selectAll(".d3plus-shape-rect") | ||
const groups = select.selectAll(".d3plus-shape-rect") | ||
.data(data, id); | ||
/* Enter */ | ||
var enter = groups.enter().append("g") | ||
const enter = groups.enter().append("g") | ||
.attr("class", "d3plus-shape-rect") | ||
.attr("id", (d) => "d3plus-shape-rect-" + id(d)) | ||
.attr("id", (d) => `d3plus-shape-rect-${id(d)}`) | ||
.attr("transform", (d) => `translate(${x(d)},${y(d)})`); | ||
@@ -95,14 +123,13 @@ | ||
/* Draw labels based on inner bounds */ | ||
groups.each(function(d){ | ||
groups.each(function(d) { | ||
if (label !== void 0) { | ||
var b = innerBounds(width(d), height(d)); | ||
const b = innerBounds(width(d), height(d)); | ||
if (b) { | ||
var elem = d3.select(this).selectAll("text").data([0]); | ||
const elem = d3.select(this).selectAll("text").data([0]); | ||
elem.enter().append("text").html(label(d)); | ||
box() | ||
.fontColor(function(){ | ||
return contrast(fill(d)); | ||
}) | ||
.fontColor(() => contrast(fill(d))) | ||
.height(b.height) | ||
@@ -115,9 +142,6 @@ .select(elem.node()) | ||
} | ||
else { | ||
d3.select(this).select("text").remove(); | ||
} | ||
else d3.select(this).select("text").remove(); | ||
} | ||
else { | ||
d3.select(this).select("text").remove(); | ||
} | ||
else d3.select(this).select("text").remove(); | ||
}); | ||
@@ -124,0 +148,0 @@ |
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
33904
15
505