d3kit-timeline
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -5,2 +5,8 @@ # d3Kit-timeline | ||
### v1.1.0 | ||
#### New API | ||
Add `.resizeToFit()` to address issue [#5](https://github.com/kristw/d3kit-timeline/issues/5). If the direction is *left* or *right*, it will set the width automatically. If the direction is *up* or *down*, it will set the height automatically. | ||
### v1.0.1 | ||
@@ -7,0 +13,0 @@ |
@@ -163,2 +163,4 @@ 'use strict'; | ||
drawLabels(force.nodes()); | ||
return skeleton; | ||
} | ||
@@ -303,5 +305,31 @@ | ||
function resizeToFit(){ | ||
var max; | ||
switch(options.direction){ | ||
case 'up': | ||
max = d3.max(force.nodes(), function(d){return Math.abs(d.y);}) || 0; | ||
skeleton.height(max + options.margin.top + options.margin.bottom); | ||
break; | ||
case 'down': | ||
max = d3.max(force.nodes(), function(d){return Math.abs(d.y + d.dy);}) || 0; | ||
skeleton.height(max + options.margin.top + options.margin.bottom); | ||
break; | ||
case 'left': | ||
max = d3.max(force.nodes(), function(d){return Math.abs(d.x);}) || 0; | ||
skeleton.width(max + options.margin.left + options.margin.right); | ||
break; | ||
case 'right': | ||
max = d3.max(force.nodes(), function(d){return Math.abs(d.x + d.dx);}) || 0; | ||
skeleton.width(max + options.margin.left + options.margin.right); | ||
break; | ||
} | ||
return skeleton; | ||
} | ||
return skeleton.mixin({ | ||
axis: axis, | ||
visualize: visualize | ||
visualize: visualize, | ||
resizeToFit: resizeToFit | ||
}); | ||
@@ -308,0 +336,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
"use strict";!function(a,b){"function"==typeof define&&define.amd?define(["d3","d3kit","labella"],b):"object"==typeof exports?module.exports=b(require("d3"),require("d3kit"),require("labella")):a.d3KitTimeline=b(a.d3,a.d3Kit,a.labella)}(this,function(a,b,c){var d={margin:{left:40,right:20,top:20,bottom:20},initialWidth:400,initialHeight:400,scale:a.time.scale(),domain:void 0,direction:"right",dotRadius:3,layerGap:60,labella:{},keyFn:void 0,timeFn:function(a){return a.time},textFn:function(a){return a.text},dotColor:"#222",labelBgColor:"#222",labelTextColor:"#fff",linkColor:"#222",labelPadding:{left:4,right:4,top:3,bottom:2},textYOffset:"0.85em"},e=["dotClick","dotMouseover","dotMousemove","dotMouseout","labelClick","labelMouseover","labelMousemove","labelMouseout"];return b.factory.createChart(d,e,function(b){function d(a){return a.w}function e(a){return a.h}function f(a){return j.scale(j.timeFn(a))}function g(){if(b.hasData()){var d=b.data();j.domain?j.scale.domain(j.domain):j.scale.domain(a.extent(d,j.timeFn)).nice(),j.scale.range([0,"left"===j.direction||"right"===j.direction?b.getInnerHeight():b.getInnerWidth()]),n.scale(j.scale);var e;switch(j.direction){case"right":n.orient("left"),e="translate(0,0)";break;case"left":n.orient("right"),e="translate("+b.getInnerWidth()+",0)";break;case"up":n.orient("bottom"),e="translate(0,"+b.getInnerHeight()+")";break;case"down":n.orient("top"),e="translate(0,0)"}l.get("main").attr("transform",e),l.get("main.axis").call(n),h(d);var g=l.get("dummy").append("text").classed("label-text",!0),k=d.map(function(a){var b=g.text(j.textFn(a))[0][0].getBBox(),d=b.width+j.labelPadding.left+j.labelPadding.right,e=b.height+j.labelPadding.top+j.labelPadding.bottom,h=new c.Node(f(a),"left"===j.direction||"right"===j.direction?e:d,a);return h.w=d,h.h=e,h});g.remove(),m.options(j.labella).nodes(k).compute(),i(m.nodes())}}function h(a){var b=l.get("main.dot").selectAll("circle.dot").data(a,j.keyFn),c="left"===j.direction||"right"===j.direction?"cy":"cx";b.enter().append("circle").classed("dot",!0).on("click",function(a,b){k.dotClick(a,b)}).on("mouseover",function(a,b){k.dotMouseover(a,b)}).on("mousemove",function(a,b){k.dotMousemove(a,b)}).on("mouseout",function(a,b){k.dotMouseout(a,b)}).style("fill",j.dotColor).attr("r",j.dotRadius).attr(c,f),b.transition().style("fill",j.dotColor).attr("r",j.dotRadius).attr(c,f),b.exit().remove()}function i(b){function f(a){switch(j.direction){case"right":return"translate("+a.x+","+(a.y-a.dy/2)+")";case"left":return"translate("+(a.x+g-a.w)+","+(a.y-a.dy/2)+")";case"up":return"translate("+(a.x-a.dx/2)+","+a.y+")";case"down":return"translate("+(a.x-a.dx/2)+","+a.y+")"}}var g;g="left"===j.direction||"right"===j.direction?a.max(b,d):a.max(b,e);var h=new c.Renderer({nodeHeight:g,layerGap:j.layerGap,direction:j.direction});h.layout(b);var i=a.functor(j.labelBgColor),m=a.functor(j.labelTextColor),n=a.functor(j.linkColor),o=l.get("main.label").selectAll("g.label-g").data(b,j.keyFn?function(a){return j.keyFn(a.data)}:void 0),p=o.enter().append("g").classed("label-g",!0).on("click",function(a,b){k.labelClick(a.data,b)}).on("mouseover",function(a,b){k.labelMouseover(a.data,b)}).on("mousemove",function(a,b){k.labelMousemove(a.data,b)}).on("mouseout",function(a,b){k.labelMouseout(a.data,b)}).attr("transform",f);p.append("rect").classed("label-bg",!0).attr("rx",2).attr("ry",2).attr("width",d).attr("height",e).style("fill",function(a){return i(a.data)}),p.append("text").classed("label-text",!0).attr("dy",j.textYOffset).attr("x",j.labelPadding.left).attr("y",j.labelPadding.top).style("fill",function(a){return m(a.data)}).text(function(a){return j.textFn(a.data)});var q=o.transition().attr("transform",f);q.select("rect").attr("width",d).attr("height",e).style("fill",function(a){return i(a.data)}),q.select("text.label-text").attr("dy",j.textYOffset).attr("x",j.labelPadding.left).attr("y",j.labelPadding.top).style("fill",function(a){return m(a.data)}).text(function(a){return j.textFn(a.data)}),o.exit().remove();var r=l.get("main.link").selectAll("path.link").data(b,j.keyFn?function(a){return j.keyFn(a.data)}:void 0);r.enter().append("path").classed("link",!0).attr("d",function(a){return h.generatePath(a)}).style("stroke",function(a){return n(a.data)}).style("fill","none"),r.transition().style("stroke",function(a){return n(a.data)}).attr("d",function(a){return h.generatePath(a)}),r.exit().remove()}var j=b.options(),k=b.getDispatcher(),l=b.getLayerOrganizer();l.create(["dummy",{main:["axis","link","label","dot"]}]);var m=new c.Force(j.labella),n=a.svg.axis();return k.on("resize",g),k.on("options",g),k.on("data",g),l.get("main.axis").classed("axis",!0),b.mixin({axis:n,visualize:g})})}); | ||
"use strict";!function(a,b){"function"==typeof define&&define.amd?define(["d3","d3kit","labella"],b):"object"==typeof exports?module.exports=b(require("d3"),require("d3kit"),require("labella")):a.d3KitTimeline=b(a.d3,a.d3Kit,a.labella)}(this,function(a,b,c){var d={margin:{left:40,right:20,top:20,bottom:20},initialWidth:400,initialHeight:400,scale:a.time.scale(),domain:void 0,direction:"right",dotRadius:3,layerGap:60,labella:{},keyFn:void 0,timeFn:function(a){return a.time},textFn:function(a){return a.text},dotColor:"#222",labelBgColor:"#222",labelTextColor:"#fff",linkColor:"#222",labelPadding:{left:4,right:4,top:3,bottom:2},textYOffset:"0.85em"},e=["dotClick","dotMouseover","dotMousemove","dotMouseout","labelClick","labelMouseover","labelMousemove","labelMouseout"];return b.factory.createChart(d,e,function(b){function d(a){return a.w}function e(a){return a.h}function f(a){return k.scale(k.timeFn(a))}function g(){if(b.hasData()){var d=b.data();k.domain?k.scale.domain(k.domain):k.scale.domain(a.extent(d,k.timeFn)).nice(),k.scale.range([0,"left"===k.direction||"right"===k.direction?b.getInnerHeight():b.getInnerWidth()]),o.scale(k.scale);var e;switch(k.direction){case"right":o.orient("left"),e="translate(0,0)";break;case"left":o.orient("right"),e="translate("+b.getInnerWidth()+",0)";break;case"up":o.orient("bottom"),e="translate(0,"+b.getInnerHeight()+")";break;case"down":o.orient("top"),e="translate(0,0)"}m.get("main").attr("transform",e),m.get("main.axis").call(o),h(d);var g=m.get("dummy").append("text").classed("label-text",!0),j=d.map(function(a){var b=g.text(k.textFn(a))[0][0].getBBox(),d=b.width+k.labelPadding.left+k.labelPadding.right,e=b.height+k.labelPadding.top+k.labelPadding.bottom,h=new c.Node(f(a),"left"===k.direction||"right"===k.direction?e:d,a);return h.w=d,h.h=e,h});return g.remove(),n.options(k.labella).nodes(j).compute(),i(n.nodes()),b}}function h(a){var b=m.get("main.dot").selectAll("circle.dot").data(a,k.keyFn),c="left"===k.direction||"right"===k.direction?"cy":"cx";b.enter().append("circle").classed("dot",!0).on("click",function(a,b){l.dotClick(a,b)}).on("mouseover",function(a,b){l.dotMouseover(a,b)}).on("mousemove",function(a,b){l.dotMousemove(a,b)}).on("mouseout",function(a,b){l.dotMouseout(a,b)}).style("fill",k.dotColor).attr("r",k.dotRadius).attr(c,f),b.transition().style("fill",k.dotColor).attr("r",k.dotRadius).attr(c,f),b.exit().remove()}function i(b){function f(a){switch(k.direction){case"right":return"translate("+a.x+","+(a.y-a.dy/2)+")";case"left":return"translate("+(a.x+g-a.w)+","+(a.y-a.dy/2)+")";case"up":return"translate("+(a.x-a.dx/2)+","+a.y+")";case"down":return"translate("+(a.x-a.dx/2)+","+a.y+")"}}var g;g="left"===k.direction||"right"===k.direction?a.max(b,d):a.max(b,e);var h=new c.Renderer({nodeHeight:g,layerGap:k.layerGap,direction:k.direction});h.layout(b);var i=a.functor(k.labelBgColor),j=a.functor(k.labelTextColor),n=a.functor(k.linkColor),o=m.get("main.label").selectAll("g.label-g").data(b,k.keyFn?function(a){return k.keyFn(a.data)}:void 0),p=o.enter().append("g").classed("label-g",!0).on("click",function(a,b){l.labelClick(a.data,b)}).on("mouseover",function(a,b){l.labelMouseover(a.data,b)}).on("mousemove",function(a,b){l.labelMousemove(a.data,b)}).on("mouseout",function(a,b){l.labelMouseout(a.data,b)}).attr("transform",f);p.append("rect").classed("label-bg",!0).attr("rx",2).attr("ry",2).attr("width",d).attr("height",e).style("fill",function(a){return i(a.data)}),p.append("text").classed("label-text",!0).attr("dy",k.textYOffset).attr("x",k.labelPadding.left).attr("y",k.labelPadding.top).style("fill",function(a){return j(a.data)}).text(function(a){return k.textFn(a.data)});var q=o.transition().attr("transform",f);q.select("rect").attr("width",d).attr("height",e).style("fill",function(a){return i(a.data)}),q.select("text.label-text").attr("dy",k.textYOffset).attr("x",k.labelPadding.left).attr("y",k.labelPadding.top).style("fill",function(a){return j(a.data)}).text(function(a){return k.textFn(a.data)}),o.exit().remove();var r=m.get("main.link").selectAll("path.link").data(b,k.keyFn?function(a){return k.keyFn(a.data)}:void 0);r.enter().append("path").classed("link",!0).attr("d",function(a){return h.generatePath(a)}).style("stroke",function(a){return n(a.data)}).style("fill","none"),r.transition().style("stroke",function(a){return n(a.data)}).attr("d",function(a){return h.generatePath(a)}),r.exit().remove()}function j(){var c;switch(k.direction){case"up":c=a.max(n.nodes(),function(a){return Math.abs(a.y)})||0,b.height(c+k.margin.top+k.margin.bottom);break;case"down":c=a.max(n.nodes(),function(a){return Math.abs(a.y+a.dy)})||0,b.height(c+k.margin.top+k.margin.bottom);break;case"left":c=a.max(n.nodes(),function(a){return Math.abs(a.x)})||0,b.width(c+k.margin.left+k.margin.right);break;case"right":c=a.max(n.nodes(),function(a){return Math.abs(a.x+a.dx)})||0,b.width(c+k.margin.left+k.margin.right)}return b}var k=b.options(),l=b.getDispatcher(),m=b.getLayerOrganizer();m.create(["dummy",{main:["axis","link","label","dot"]}]);var n=new c.Force(k.labella),o=a.svg.axis();return l.on("resize",g),l.on("options",g),l.on("data",g),m.get("main.axis").classed("axis",!0),b.mixin({axis:o,visualize:g,resizeToFit:j})})}); |
{ | ||
"name": "d3kit-timeline", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "A timeline component based on d3kit and labella.js", | ||
@@ -23,3 +23,2 @@ "homepage": "https://github.com/kristw/d3kit-timeline", | ||
"grunt": "~0.4.5", | ||
"grunt-bump": "~0.3.1", | ||
"grunt-cli": "~0.1.13", | ||
@@ -32,3 +31,2 @@ "grunt-contrib-clean": "~0.6.0", | ||
"grunt-gh-pages": "~0.10.0", | ||
"grunt-shell": "~1.1.2", | ||
"load-grunt-config": "~0.17.1", | ||
@@ -42,4 +40,8 @@ "mocha": "*", | ||
"test": "mocha --no-colors --reporter spec", | ||
"prepublish": "pkgfiles" | ||
"build": "grunt build", | ||
"preversion": "npm test", | ||
"version": "npm run build && git add -A dist", | ||
"postversion": "pkgfiles", | ||
"prepublish": "git push ; git push --tags" | ||
} | ||
} |
@@ -61,3 +61,3 @@ **Introduction** | | ||
chart.data(data); | ||
chart.data(data).resizeToFit(); | ||
``` | ||
@@ -64,0 +64,0 @@ |
33015
14
284