@d3fc/d3fc-chart
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -949,5 +949,11 @@ (function (global, factory) { | ||
var cartesianChart = (function () { | ||
var xScale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : d3Scale.scaleIdentity(); | ||
var yScale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : d3Scale.scaleIdentity(); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var _getArguments = getArguments.apply(undefined, args), | ||
xScale = _getArguments.xScale, | ||
yScale = _getArguments.yScale, | ||
xAxis = _getArguments.xAxis, | ||
yAxis = _getArguments.yAxis; | ||
@@ -1017,5 +1023,5 @@ var xLabel = functor$1(''); | ||
}).on('draw', function (d, i, nodes) { | ||
var xAxis = d === 'top' ? axisTop(xScale) : axisBottom(xScale); | ||
xAxis.decorate(xDecorate); | ||
transitionPropagator(d3Selection.select(nodes[i])).select('svg').call(xAxisStore(xAxis)); | ||
var xAxisComponent = d === 'top' ? xAxis.top(xScale) : xAxis.bottom(xScale); | ||
xAxisComponent.decorate(xDecorate); | ||
transitionPropagator(d3Selection.select(nodes[i])).select('svg').call(xAxisStore(xAxisComponent)); | ||
}); | ||
@@ -1035,5 +1041,5 @@ | ||
}).on('draw', function (d, i, nodes) { | ||
var yAxis = d === 'left' ? axisLeft(yScale) : axisRight(yScale); | ||
yAxis.decorate(yDecorate); | ||
transitionPropagator(d3Selection.select(nodes[i])).select('svg').call(yAxisStore(yAxis)); | ||
var yAxisComponent = d === 'left' ? yAxis.left(yScale) : yAxis.right(yScale); | ||
yAxisComponent.decorate(yDecorate); | ||
transitionPropagator(d3Selection.select(nodes[i])).select('svg').call(yAxisStore(yAxisComponent)); | ||
}); | ||
@@ -1149,2 +1155,26 @@ | ||
var getArguments = function getArguments() { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
var defaultSettings = { | ||
xScale: d3Scale.scaleIdentity(), | ||
yScale: d3Scale.scaleIdentity(), | ||
xAxis: { bottom: axisBottom, top: axisTop }, | ||
yAxis: { right: axisRight, left: axisLeft } | ||
}; | ||
if (args.length === 1 && !args[0].domain && !args[0].range) { | ||
// Settings object | ||
return Object.assign(defaultSettings, args[0]); | ||
} | ||
// xScale/yScale parameters | ||
return Object.assign(defaultSettings, { | ||
xScale: args[0] || defaultSettings.xScale, | ||
yScale: args[1] || defaultSettings.yScale | ||
}); | ||
}; | ||
var functor = function functor(v) { | ||
@@ -1158,6 +1188,6 @@ return typeof v === 'function' ? v : function () { | ||
return function () { | ||
var xScale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : d3Scale.scaleIdentity(); | ||
var yScale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : d3Scale.scaleIdentity(); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var chartLabel = functor(''); | ||
@@ -1168,3 +1198,3 @@ var yLabel = functor(''); | ||
var cartesian = cartesianChart(xScale, yScale); | ||
var cartesian = cartesianChart.apply(undefined, args); | ||
@@ -1171,0 +1201,0 @@ var cartesianBase = function cartesianBase(selection$$1) { |
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3-scale"),require("d3-selection"),require("d3-shape"),require("d3-path"),require("d3-array")):"function"==typeof define&&define.amd?define(["exports","d3-scale","d3-selection","d3-shape","d3-path","d3-array"],n):n(t.fc=t.fc||{},t.d3,t.d3,t.d3,t.d3,t.d3)}(this,function(t,n,e,r,i,o){"use strict";function a(){var t=arguments;return function(n,e){for(var r=0,i=t.length;r<i;r++)if(null==t[r](n,e))return!1;return!0}}var c=function(t,n,e){var r=n[e];if("function"!=typeof r)throw new Error("Attempt to rebind "+e+" which isn't a function on the source object");return function(){for(var e=arguments.length,i=Array(e),o=0;o<e;o++)i[o]=arguments[o];var a=r.apply(n,i);return a===n?t:a}},l=function(t,n){for(var e=arguments.length,r=Array(e>2?e-2:0),i=2;i<e;i++)r[i-2]=arguments[i];var o=!0,a=!1,l=void 0;try{for(var u,s=r[Symbol.iterator]();!(o=(u=s.next()).done);o=!0){var f=u.value;t[f]=c(t,n,f)}}catch(t){a=!0,l=t}finally{try{!o&&s.return&&s.return()}finally{if(a)throw l}}return t},u=function(t){return function(n){return t.reduce(function(t,n){return t&&n(t)},n)}},s=function(t,n){for(var e=arguments.length,r=Array(e>2?e-2:0),i=2;i<e;i++)r[i-2]=arguments[i];var o=u(r),a=!0,l=!1,s=void 0;try{for(var f,d=Object.keys(n)[Symbol.iterator]();!(a=(f=d.next()).done);a=!0){var g=f.value,h=o(g);h&&(t[h]=c(t,n,g))}}catch(t){l=!0,s=t}finally{try{!a&&d.return&&d.return()}finally{if(l)throw s}}return t},f=function(t){return t.map(function(t){return"string"==typeof t?new RegExp("^"+t+"$"):t})},d=function(){for(var t=arguments.length,n=Array(t),e=0;e<t;e++)n[e]=arguments[e];return n=f(n),function(t){return n.every(function(n){return!n.test(t)})&&t}},g=function(){for(var t=arguments.length,n=Array(t),e=0;e<t;e++)n[e]=arguments[e];return n=f(n),function(t){return n.some(function(n){return n.test(t)})&&t}},h=function(t){return t[0].toUpperCase()+t.slice(1)},m=function(t){return function(n){return t+h(n)}},v=function(t,n){t=t||"g";var e=function(t,n){return n},r=null,i=function(i,o){o=o||function(t){return t};var a=i.selection?i:null;a&&(i=i.selection());var c=i.selectAll(function(t,n,e){return Array.from(e[n].childNodes).filter(function(t){return 1===t.nodeType})}).filter(null==n?t:t+"."+n),l=c.data(o,e),u=l.enter().append(t).attr("class",n),s=l.exit();l=l.merge(u);var f=a||r;return f&&(l=l.transition(f).style("opacity",1),u.style("opacity",1e-6),s=s.transition(f).style("opacity",1e-6)),s.remove(),l.enter=function(){return u},l.exit=function(){return s},l};return i.element=function(){return arguments.length?(t=arguments.length<=0?void 0:arguments[0],i):t},i.className=function(){return arguments.length?(n=arguments.length<=0?void 0:arguments[0],i):n},i.key=function(){return arguments.length?(e=arguments.length<=0?void 0:arguments[0],i):e},i.transition=function(){return arguments.length?(r=arguments.length<=0?void 0:arguments[0],i):r},i},y=function(t){return"function"==typeof t?t:function(){return t}},p=function(t,n){switch(t){case"left":return n/2;case"right":return-n/2;default:return 0}},x=function(t){var n=Object.assign({},t),e=function(){};return Object.keys(n).forEach(function(t){e[t]=function(){return arguments.length?(n[t]=arguments.length<=0?void 0:arguments[0],e):n[t]}}),e},w=function(){var t=function(){return 0},e=function(t){return t.x},r=function(t){return t.y},i="center",o=function(){return 5},c="vertical",l=x({decorate:function(){},defined:function(n,i){return a(t,e,r)(n,i)},xScale:n.scaleIdentity(),yScale:n.scaleIdentity()});return l.values=function(n,a){var u=o(n,a),s=p(i,u),f=l.xScale(),d=l.yScale();if("vertical"===c){var g=d(r(n,a),a),h=d(t(n,a),a),m=f(e(n,a),a)+s;return{d:n,x:m,y:g,y0:h,width:u,height:g-h,origin:[m,g],baseOrigin:[m,h],transposedX:m,transposedY:g}}var v=f(r(n,a),a),y=f(t(n,a),a),x=d(e(n,a),a)+s;return{d:n,x:x,y:v,y0:y,width:u,height:v-y,origin:[v,x],baseOrigin:[y,x],transposedX:v,transposedY:x}},l.baseValue=function(){return arguments.length?(t=y(arguments.length<=0?void 0:arguments[0]),l):t},l.crossValue=function(){return arguments.length?(e=y(arguments.length<=0?void 0:arguments[0]),l):e},l.mainValue=function(){return arguments.length?(r=y(arguments.length<=0?void 0:arguments[0]),l):r},l.bandwidth=function(){return arguments.length?(o=y(arguments.length<=0?void 0:arguments[0]),l):o},l.align=function(){return arguments.length?(i=arguments.length<=0?void 0:arguments[0],l):i},l.orient=function(){return arguments.length?(c=arguments.length<=0?void 0:arguments[0],l):c},l},b={red:"#c60",green:"#6c0",black:"#000",gray:"#ddd",darkGray:"#999"},k=function(){var t=w(),n=r.line().x(function(n,e){return t.values(n,e).transposedX}).y(function(n,e){return t.values(n,e).transposedY}),i=v("path","line"),o=function(r){r.selection&&i.transition(r),n.defined(t.defined()),r.each(function(r,o,a){var c=i(e.select(a[o]),[r]);c.enter().attr("fill","none").attr("stroke",b.black),c.attr("d",n),t.decorate()(c,r,o)})};return s(o,t,d("baseValue","bandwidth","align")),l(o,i,"key"),l(o,n,"curve"),o},S=function(){var t=w(),n=r.line().x(function(n,e){return t.values(n,e).transposedX}).y(function(n,e){return t.values(n,e).transposedY}),e=function(e){var r=n.context();r.beginPath(),n.defined(t.defined())(e),r.strokeStyle=b.black,r.fillStyle="transparent",t.decorate()(r,e),r.fill(),r.stroke(),r.closePath()};return s(e,t,d("baseValue","bandwidth","align")),l(e,n,"curve","context"),e},A=function(){var t=[],e=function(t){return t},r=function(t,n){return n},i=x({decorate:function(){},xScale:n.scaleIdentity(),yScale:n.scaleIdentity()});return i.mapping=function(){return arguments.length?(e=arguments.length<=0?void 0:arguments[0],i):e},i.key=function(){return arguments.length?(r=arguments.length<=0?void 0:arguments[0],i):r},i.series=function(){return arguments.length?(t=arguments.length<=0?void 0:arguments[0],i):t},i},_=function(){var t=A(),n=v("g"),r=v("g","multi"),i=function(i){i.selection&&(r.transition(i),n.transition(i));var o=t.mapping(),a=t.series(),c=t.xScale(),l=t.yScale();i.each(function(i,u,s){var f=r(e.select(s[u]),a);f.each(function(t,r,u){t.xScale(c).yScale(l);var s=o(i,r,a);n(e.select(u[r]),[s]).call(t)}),(f.selection?f.selection():f).order(),t.decorate()(f,i,u)})};return s(i,t),l(i,r,"key"),i},O=function(){var t=null,n=A(),e=function(e){var r=n.mapping(),i=n.series(),o=n.xScale(),a=n.yScale();i.forEach(function(c,l){var u=r(e,l,i);c.context(t).xScale(o).yScale(a);var s=c.decorate();c.decorate(function(t,r,i){n.decorate()(t,e,l),s(t,r,i)}),c(u),c.decorate(s)})};return e.context=function(){return arguments.length?(t=arguments.length<=0?void 0:arguments[0],e):t},s(e,n),e},j=function(t){if(Array.isArray(t)){for(var n=0,e=Array(t.length);n<t.length;n++)e[n]=t[n];return e}return Array.from(t)},z=function(t){return t},I=function(t,n){var i=[10],o=null,a=function(){},c=null,l=6,u=6,s=3,f=r.line(),d=v("g","tick").key(z),g=v("path","domain"),h=function(t,n){var e=0;return t.bandwidth&&(e=t.bandwidth()/2,t.round()&&(e=Math.round(e))),function(r){return n(t(r)+e,0)}},m=function(t,n){return p()?"translate("+n+", "+t+")":"translate("+t+", "+n+")"},y=function(t){return p()?t.map(function(t){return[t[1],t[0]]}):t},p=function(){return"left"===t||"right"===t},x=function(t,e,r){return n[t]?n[t].apply(n,e):r},w=function(r){r.selection&&(d.transition(r),g.transition(r)),r.each(function(r,v,w){var b=w[v],k=e.select(b);b.__scale__||k.attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor","right"===t?"start":"left"===t?"end":"middle");var S=b.__scale__||n;b.__scale__=n.copy();var A=null==o?x("ticks",i,n.domain()):o,_=null==c?x("tickFormat",i,z):c,O="bottom"===t||"right"===t?1:-1,j=n.range(),I=y([[j[0],O*l],[j[0],0],[j[1],0],[j[1],O*l]]);g(k,[r]).attr("d",f(I)).attr("stroke","#000");var P=d(k,A);P.enter().attr("transform",h(S,m)).append("path").attr("stroke","#000");var C=O*(u+s);P.enter().append("text").attr("transform",m(0,C)).attr("fill","#000"),P.exit().attr("transform",h(n,m)),P.select("path").attr("d",function(t){return f(y([[0,0],[0,O*u]]))}),P.select("text").attr("transform",m(0,C)).attr("dy",function(){var n="0em";return p()?n="0.32em":"bottom"===t&&(n="0.71em"),n}).text(_),P.attr("transform",h(n,m)),a(P,r,v)})};return w.tickFormat=function(){return arguments.length?(c=arguments.length<=0?void 0:arguments[0],w):c},w.tickSize=function(){return arguments.length?(u=l=Number(arguments.length<=0?void 0:arguments[0]),w):u},w.tickSizeInner=function(){return arguments.length?(u=Number(arguments.length<=0?void 0:arguments[0]),w):u},w.tickSizeOuter=function(){return arguments.length?(l=Number(arguments.length<=0?void 0:arguments[0]),w):l},w.tickPadding=function(){return arguments.length?(s=arguments.length<=0?void 0:arguments[0],w):s},w.decorate=function(){return arguments.length?(a=arguments.length<=0?void 0:arguments[0],w):a},w.scale=function(){return arguments.length?(n=arguments.length<=0?void 0:arguments[0],w):n},w.ticks=function(){for(var t=arguments.length,n=Array(t),e=0;e<t;e++)n[e]=arguments[e];return i=[].concat(n),w},w.tickArguments=function(){return arguments.length?(i=null==(arguments.length<=0?void 0:arguments[0])?[]:[].concat(j(arguments.length<=0?void 0:arguments[0])),w):i.slice()},w.tickValues=function(){return arguments.length?(o=null==(arguments.length<=0?void 0:arguments[0])?[]:[].concat(j(arguments.length<=0?void 0:arguments[0])),w):o.slice()},w},P=function(t){return I("top",t)},C=function(t){return I("bottom",t)},V=function(t){return I("left",t)},q=function(t){return I("right",t)},E=function(){for(var t=arguments.length,n=Array(t),e=0;e<t;e++)n[e]=arguments[e];var r={},i=function(t){var n=!0,e=!1,i=void 0;try{for(var o,a=Object.keys(r)[Symbol.iterator]();!(n=(o=a.next()).done);n=!0){var c=o.value;t[c](r[c])}}catch(t){e=!0,i=t}finally{try{!n&&a.return&&a.return()}finally{if(e)throw i}}return t},o=!0,a=!1,c=void 0;try{for(var l,u=n[Symbol.iterator]();!(o=(l=u.next()).done);o=!0){var s=l.value;!function(t){i[t]=function(){return arguments.length?(r[t]=arguments.length<=0?void 0:arguments[0],i):r[t]}}(s)}}catch(t){a=!0,c=t}finally{try{!o&&u.return&&u.return()}finally{if(a)throw c}}return i},F="d3fc-group.cartesian-chart{width:100%;height:100%;overflow:hidden;display:grid;display:-ms-grid;grid-template-columns:minmax(1em,max-content) auto 1fr auto minmax(1em,max-content);-ms-grid-columns:minmax(1em,max-content) auto 1fr auto minmax(1em,max-content);grid-template-rows:minmax(1em,max-content) auto 1fr auto minmax(1em,max-content);-ms-grid-rows:minmax(1em,max-content) auto 1fr auto minmax(1em,max-content);}\nd3fc-group.cartesian-chart>.top-label{align-self:center;-ms-grid-column-align:center;justify-self:center;-ms-grid-row-align:center;grid-column:3;-ms-grid-column:3;-ms-grid-row:1;-ms-grid-row:1;}\nd3fc-group.cartesian-chart>.top-axis{height:2em;grid-column:3;-ms-grid-column:3;grid-row:2;-ms-grid-row:2;}\nd3fc-group.cartesian-chart>.left-label{align-self:center;-ms-grid-column-align:center;justify-self:center;-ms-grid-row-align:center;grid-column:1;-ms-grid-column:1;grid-row:3;-ms-grid-row:3;}\nd3fc-group.cartesian-chart>.left-axis{width:3em;grid-column:2;-ms-grid-column:2;grid-row:3;-ms-grid-row:3;}\nd3fc-group.cartesian-chart>.plot-area{overflow:hidden;grid-column:3;-ms-grid-column:3;grid-row:3;-ms-grid-row:3;}\nd3fc-group.cartesian-chart>.right-axis{width:3em;grid-column:4;-ms-grid-column:4;grid-row:3;-ms-grid-row:3;}\nd3fc-group.cartesian-chart>.right-label{align-self:center;-ms-grid-column-align:center;justify-self:center;-ms-grid-row-align:center;grid-column:5;-ms-grid-column:5;grid-row:3;-ms-grid-row:3;}\nd3fc-group.cartesian-chart>.bottom-axis{height:2em;grid-column:3;-ms-grid-column:3;grid-row:4;-ms-grid-row:4;}\nd3fc-group.cartesian-chart>.bottom-label{align-self:center;-ms-grid-column-align:center;justify-self:center;-ms-grid-row-align:center;grid-column:3;-ms-grid-column:3;grid-row:5;-ms-grid-row:5;}",N=document.createElement("style");N.setAttribute("type","text/css"),document.querySelector("head").appendChild(N),N.styleSheet?N.styleSheet.cssText+=F:N.textContent+=F;var L=function(t){return"function"==typeof t?t:function(){return t}},X=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:n.scaleIdentity(),r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n.scaleIdentity(),i=L(""),o=L(""),a=L(null),c=L(null),l=L("right"),u=L("bottom"),f=O(),g=_(),h=E("tickFormat","ticks","tickArguments","tickSize","tickSizeInner","tickSizeOuter","tickValues","tickPadding"),y=function(){},p=E("tickFormat","ticks","tickArguments","tickSize","tickSizeInner","tickSizeOuter","tickValues","tickPadding"),x=function(){},w=function(){},b=v("d3fc-group","cartesian-chart"),k=v("d3fc-svg","x-axis").key(function(t){return t}),S=v("d3fc-svg","y-axis").key(function(t){return t}),A=v("div","x-label").key(function(t){return t}),j=v("div","y-label").key(function(t){return t}),z=function(t){return function(n){return t.selection?n.transition(t):n}},I=function(n){var s=z(n);n.each(function(n,d,m){var v=b(e.select(m[d]),[n]);v.enter().attr("auto-resize","").html('<d3fc-svg class="plot-area"></d3fc-svg><d3fc-canvas class="plot-area"></d3fc-canvas>'),A(v,[u(n)]).attr("class",function(t){return"x-label "+t+"-label"}).text(i(n)),j(v,[l(n)]).attr("class",function(t){return"y-label "+t+"-label"}).text(o(n)),k(v,[u(n)]).attr("class",function(t){return"x-axis "+t+"-axis"}).style("height",a(n)).on("measure",function(n,r,i){var o=e.event.detail,a=o.width,c=o.height;"top"===n&&e.select(i[r]).select("svg").attr("viewBox","0 "+-c+" "+a+" "+c),t.range([0,a])}).on("draw",function(n,r,i){var o="top"===n?P(t):C(t);o.decorate(y),s(e.select(i[r])).select("svg").call(h(o))}),S(v,[l(n)]).attr("class",function(t){return"y-axis "+t+"-axis"}).style("width",c(n)).on("measure",function(t,n,i){var o=e.event.detail,a=o.width,c=o.height;"left"===t&&e.select(i[n]).select("svg").attr("viewBox",-a+" 0 "+a+" "+c),r.range([c,0])}).on("draw",function(t,n,i){var o="left"===t?V(r):q(r);o.decorate(x),s(e.select(i[n])).select("svg").call(p(o))}),v.select("d3fc-canvas.plot-area").on("draw",function(n,i,o){var a=e.select(o[i]).select("canvas").node();f.context(a.getContext("2d")).xScale(t).yScale(r),f(n)}),v.select("d3fc-svg.plot-area").on("draw",function(n,i,o){g.xScale(t).yScale(r),s(e.select(o[i])).select("svg").call(g)}),v.each(function(t,n,e){return e[n].requestRedraw()}),w(v,n,d)})},F=d(/range\w*/,/tickFormat/);return s(I,t,F,m("x")),s(I,r,F,m("y")),s(I,h,m("x")),s(I,p,m("y")),I.xOrient=function(){return arguments.length?(u=L(arguments.length<=0?void 0:arguments[0]),I):u},I.yOrient=function(){return arguments.length?(l=L(arguments.length<=0?void 0:arguments[0]),I):l},I.xDecorate=function(){return arguments.length?(y=arguments.length<=0?void 0:arguments[0],I):y},I.yDecorate=function(){return arguments.length?(x=arguments.length<=0?void 0:arguments[0],I):x},I.xLabel=function(){return arguments.length?(i=L(arguments.length<=0?void 0:arguments[0]),I):i},I.yLabel=function(){return arguments.length?(o=L(arguments.length<=0?void 0:arguments[0]),I):o},I.xAxisHeight=function(){return arguments.length?(a=L(arguments.length<=0?void 0:arguments[0]),I):a},I.yAxisWidth=function(){return arguments.length?(c=L(arguments.length<=0?void 0:arguments[0]),I):c},I.canvasPlotArea=function(){return arguments.length?(f=arguments.length<=0?void 0:arguments[0],I):f},I.svgPlotArea=function(){return arguments.length?(g=arguments.length<=0?void 0:arguments[0],I):g},I.decorate=function(){return arguments.length?(w=arguments.length<=0?void 0:arguments[0],I):w},I},Y=function(t){return"function"==typeof t?t:function(){return t}},B=function(t,e){return function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:n.scaleIdentity(),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n.scaleIdentity(),o=Y(""),a=Y(""),c=e,l=function(){},u=X(r,i),f=function(n){t(u,c),u.decorate(function(t,n,e){t.enter().select(".x-label").style("height","1em").style("line-height","1em");var r=u.yOrient()(n);t.enter().append("div").attr("class","y-label-container").style("grid-column","left"===r?1:5).style("-ms-grid-column","left"===r?1:5).style("grid-row",3).style("-ms-grid-row",3).style("width","1em").style("display","flex").style("align-items","center").style("justify-content","center").append("div").attr("class","y-label").style("transform","rotate(-90deg)"),t.select(".y-label-container>.y-label").text(a),t.select(".top-label").style("margin-top","2em"),t.enter().append("div").attr("class","chart-label").style("grid-column",3).style("-ms-grid-column",3).style("grid-row",1).style("-ms-grid-row",1).style("height","2em").style("line-height","2em").style("text-align","center"),t.select(".chart-label").text(o(n)),l(t,n,e)}),n.call(u)};return s(f,u,g(/^x/,/^y/)),f.chartLabel=function(){return arguments.length?(o=Y(arguments.length<=0?void 0:arguments[0]),f):o},f.yLabel=function(){return arguments.length?(a=Y(arguments.length<=0?void 0:arguments[0]),f):a},f.plotArea=function(){return arguments.length?(c=arguments.length<=0?void 0:arguments[0],f):c},f.decorate=function(){return arguments.length?(l=arguments.length<=0?void 0:arguments[0],f):l},f}},D=B(function(t,n){return t.svgPlotArea(n)},k),M=B(function(t,n){return t.canvasPlotArea(n)},S);t.chartSvgCartesian=D,t.chartCanvasCartesian=M,t.chartCartesian=X,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("d3-scale"),require("d3-selection"),require("d3-shape"),require("d3-path"),require("d3-array")):"function"==typeof define&&define.amd?define(["exports","d3-scale","d3-selection","d3-shape","d3-path","d3-array"],n):n(t.fc=t.fc||{},t.d3,t.d3,t.d3,t.d3,t.d3)}(this,function(t,n,e,r,i,a){"use strict";function o(){var t=arguments;return function(n,e){for(var r=0,i=t.length;r<i;r++)if(null==t[r](n,e))return!1;return!0}}var c=function(t,n,e){var r=n[e];if("function"!=typeof r)throw new Error("Attempt to rebind "+e+" which isn't a function on the source object");return function(){for(var e=arguments.length,i=Array(e),a=0;a<e;a++)i[a]=arguments[a];var o=r.apply(n,i);return o===n?t:o}},l=function(t,n){for(var e=arguments.length,r=Array(e>2?e-2:0),i=2;i<e;i++)r[i-2]=arguments[i];var a=!0,o=!1,l=void 0;try{for(var u,s=r[Symbol.iterator]();!(a=(u=s.next()).done);a=!0){var f=u.value;t[f]=c(t,n,f)}}catch(t){o=!0,l=t}finally{try{!a&&s.return&&s.return()}finally{if(o)throw l}}return t},u=function(t){return function(n){return t.reduce(function(t,n){return t&&n(t)},n)}},s=function(t,n){for(var e=arguments.length,r=Array(e>2?e-2:0),i=2;i<e;i++)r[i-2]=arguments[i];var a=u(r),o=!0,l=!1,s=void 0;try{for(var f,d=Object.keys(n)[Symbol.iterator]();!(o=(f=d.next()).done);o=!0){var g=f.value,h=a(g);h&&(t[h]=c(t,n,g))}}catch(t){l=!0,s=t}finally{try{!o&&d.return&&d.return()}finally{if(l)throw s}}return t},f=function(t){return t.map(function(t){return"string"==typeof t?new RegExp("^"+t+"$"):t})},d=function(){for(var t=arguments.length,n=Array(t),e=0;e<t;e++)n[e]=arguments[e];return n=f(n),function(t){return n.every(function(n){return!n.test(t)})&&t}},g=function(){for(var t=arguments.length,n=Array(t),e=0;e<t;e++)n[e]=arguments[e];return n=f(n),function(t){return n.some(function(n){return n.test(t)})&&t}},h=function(t){return t[0].toUpperCase()+t.slice(1)},m=function(t){return function(n){return t+h(n)}},v=function(t,n){t=t||"g";var e=function(t,n){return n},r=null,i=function(i,a){a=a||function(t){return t};var o=i.selection?i:null;o&&(i=i.selection());var c=i.selectAll(function(t,n,e){return Array.from(e[n].childNodes).filter(function(t){return 1===t.nodeType})}).filter(null==n?t:t+"."+n),l=c.data(a,e),u=l.enter().append(t).attr("class",n),s=l.exit();l=l.merge(u);var f=o||r;return f&&(l=l.transition(f).style("opacity",1),u.style("opacity",1e-6),s=s.transition(f).style("opacity",1e-6)),s.remove(),l.enter=function(){return u},l.exit=function(){return s},l};return i.element=function(){return arguments.length?(t=arguments.length<=0?void 0:arguments[0],i):t},i.className=function(){return arguments.length?(n=arguments.length<=0?void 0:arguments[0],i):n},i.key=function(){return arguments.length?(e=arguments.length<=0?void 0:arguments[0],i):e},i.transition=function(){return arguments.length?(r=arguments.length<=0?void 0:arguments[0],i):r},i},y=function(t){return"function"==typeof t?t:function(){return t}},p=function(t,n){switch(t){case"left":return n/2;case"right":return-n/2;default:return 0}},x=function(t){var n=Object.assign({},t),e=function(){};return Object.keys(n).forEach(function(t){e[t]=function(){return arguments.length?(n[t]=arguments.length<=0?void 0:arguments[0],e):n[t]}}),e},b=function(){var t=function(){return 0},e=function(t){return t.x},r=function(t){return t.y},i="center",a=function(){return 5},c="vertical",l=x({decorate:function(){},defined:function(n,i){return o(t,e,r)(n,i)},xScale:n.scaleIdentity(),yScale:n.scaleIdentity()});return l.values=function(n,o){var u=a(n,o),s=p(i,u),f=l.xScale(),d=l.yScale();if("vertical"===c){var g=d(r(n,o),o),h=d(t(n,o),o),m=f(e(n,o),o)+s;return{d:n,x:m,y:g,y0:h,width:u,height:g-h,origin:[m,g],baseOrigin:[m,h],transposedX:m,transposedY:g}}var v=f(r(n,o),o),y=f(t(n,o),o),x=d(e(n,o),o)+s;return{d:n,x:x,y:v,y0:y,width:u,height:v-y,origin:[v,x],baseOrigin:[y,x],transposedX:v,transposedY:x}},l.baseValue=function(){return arguments.length?(t=y(arguments.length<=0?void 0:arguments[0]),l):t},l.crossValue=function(){return arguments.length?(e=y(arguments.length<=0?void 0:arguments[0]),l):e},l.mainValue=function(){return arguments.length?(r=y(arguments.length<=0?void 0:arguments[0]),l):r},l.bandwidth=function(){return arguments.length?(a=y(arguments.length<=0?void 0:arguments[0]),l):a},l.align=function(){return arguments.length?(i=arguments.length<=0?void 0:arguments[0],l):i},l.orient=function(){return arguments.length?(c=arguments.length<=0?void 0:arguments[0],l):c},l},w={red:"#c60",green:"#6c0",black:"#000",gray:"#ddd",darkGray:"#999"},k=function(){var t=b(),n=r.line().x(function(n,e){return t.values(n,e).transposedX}).y(function(n,e){return t.values(n,e).transposedY}),i=v("path","line"),a=function(r){r.selection&&i.transition(r),n.defined(t.defined()),r.each(function(r,a,o){var c=i(e.select(o[a]),[r]);c.enter().attr("fill","none").attr("stroke",w.black),c.attr("d",n),t.decorate()(c,r,a)})};return s(a,t,d("baseValue","bandwidth","align")),l(a,i,"key"),l(a,n,"curve"),a},S=function(){var t=b(),n=r.line().x(function(n,e){return t.values(n,e).transposedX}).y(function(n,e){return t.values(n,e).transposedY}),e=function(e){var r=n.context();r.beginPath(),n.defined(t.defined())(e),r.strokeStyle=w.black,r.fillStyle="transparent",t.decorate()(r,e),r.fill(),r.stroke(),r.closePath()};return s(e,t,d("baseValue","bandwidth","align")),l(e,n,"curve","context"),e},A=function(){var t=[],e=function(t){return t},r=function(t,n){return n},i=x({decorate:function(){},xScale:n.scaleIdentity(),yScale:n.scaleIdentity()});return i.mapping=function(){return arguments.length?(e=arguments.length<=0?void 0:arguments[0],i):e},i.key=function(){return arguments.length?(r=arguments.length<=0?void 0:arguments[0],i):r},i.series=function(){return arguments.length?(t=arguments.length<=0?void 0:arguments[0],i):t},i},O=function(){var t=A(),n=v("g"),r=v("g","multi"),i=function(i){i.selection&&(r.transition(i),n.transition(i));var a=t.mapping(),o=t.series(),c=t.xScale(),l=t.yScale();i.each(function(i,u,s){var f=r(e.select(s[u]),o);f.each(function(t,r,u){t.xScale(c).yScale(l);var s=a(i,r,o);n(e.select(u[r]),[s]).call(t)}),(f.selection?f.selection():f).order(),t.decorate()(f,i,u)})};return s(i,t),l(i,r,"key"),i},j=function(){var t=null,n=A(),e=function(e){var r=n.mapping(),i=n.series(),a=n.xScale(),o=n.yScale();i.forEach(function(c,l){var u=r(e,l,i);c.context(t).xScale(a).yScale(o);var s=c.decorate();c.decorate(function(t,r,i){n.decorate()(t,e,l),s(t,r,i)}),c(u),c.decorate(s)})};return e.context=function(){return arguments.length?(t=arguments.length<=0?void 0:arguments[0],e):t},s(e,n),e},_=function(t){if(Array.isArray(t)){for(var n=0,e=Array(t.length);n<t.length;n++)e[n]=t[n];return e}return Array.from(t)},z=function(t){return t},P=function(t,n){var i=[10],a=null,o=function(){},c=null,l=6,u=6,s=3,f=r.line(),d=v("g","tick").key(z),g=v("path","domain"),h=function(t,n){var e=0;return t.bandwidth&&(e=t.bandwidth()/2,t.round()&&(e=Math.round(e))),function(r){return n(t(r)+e,0)}},m=function(t,n){return p()?"translate("+n+", "+t+")":"translate("+t+", "+n+")"},y=function(t){return p()?t.map(function(t){return[t[1],t[0]]}):t},p=function(){return"left"===t||"right"===t},x=function(t,e,r){return n[t]?n[t].apply(n,e):r},b=function(r){r.selection&&(d.transition(r),g.transition(r)),r.each(function(r,v,b){var w=b[v],k=e.select(w);w.__scale__||k.attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor","right"===t?"start":"left"===t?"end":"middle");var S=w.__scale__||n;w.__scale__=n.copy();var A=null==a?x("ticks",i,n.domain()):a,O=null==c?x("tickFormat",i,z):c,j="bottom"===t||"right"===t?1:-1,_=n.range(),P=y([[_[0],j*l],[_[0],0],[_[1],0],[_[1],j*l]]);g(k,[r]).attr("d",f(P)).attr("stroke","#000");var I=d(k,A);I.enter().attr("transform",h(S,m)).append("path").attr("stroke","#000");var C=j*(u+s);I.enter().append("text").attr("transform",m(0,C)).attr("fill","#000"),I.exit().attr("transform",h(n,m)),I.select("path").attr("d",function(t){return f(y([[0,0],[0,j*u]]))}),I.select("text").attr("transform",m(0,C)).attr("dy",function(){var n="0em";return p()?n="0.32em":"bottom"===t&&(n="0.71em"),n}).text(O),I.attr("transform",h(n,m)),o(I,r,v)})};return b.tickFormat=function(){return arguments.length?(c=arguments.length<=0?void 0:arguments[0],b):c},b.tickSize=function(){return arguments.length?(u=l=Number(arguments.length<=0?void 0:arguments[0]),b):u},b.tickSizeInner=function(){return arguments.length?(u=Number(arguments.length<=0?void 0:arguments[0]),b):u},b.tickSizeOuter=function(){return arguments.length?(l=Number(arguments.length<=0?void 0:arguments[0]),b):l},b.tickPadding=function(){return arguments.length?(s=arguments.length<=0?void 0:arguments[0],b):s},b.decorate=function(){return arguments.length?(o=arguments.length<=0?void 0:arguments[0],b):o},b.scale=function(){return arguments.length?(n=arguments.length<=0?void 0:arguments[0],b):n},b.ticks=function(){for(var t=arguments.length,n=Array(t),e=0;e<t;e++)n[e]=arguments[e];return i=[].concat(n),b},b.tickArguments=function(){return arguments.length?(i=null==(arguments.length<=0?void 0:arguments[0])?[]:[].concat(_(arguments.length<=0?void 0:arguments[0])),b):i.slice()},b.tickValues=function(){return arguments.length?(a=null==(arguments.length<=0?void 0:arguments[0])?[]:[].concat(_(arguments.length<=0?void 0:arguments[0])),b):a.slice()},b},I=function(t){return P("top",t)},C=function(t){return P("bottom",t)},V=function(t){return P("left",t)},q=function(t){return P("right",t)},E=function(){for(var t=arguments.length,n=Array(t),e=0;e<t;e++)n[e]=arguments[e];var r={},i=function(t){var n=!0,e=!1,i=void 0;try{for(var a,o=Object.keys(r)[Symbol.iterator]();!(n=(a=o.next()).done);n=!0){var c=a.value;t[c](r[c])}}catch(t){e=!0,i=t}finally{try{!n&&o.return&&o.return()}finally{if(e)throw i}}return t},a=!0,o=!1,c=void 0;try{for(var l,u=n[Symbol.iterator]();!(a=(l=u.next()).done);a=!0){var s=l.value;!function(t){i[t]=function(){return arguments.length?(r[t]=arguments.length<=0?void 0:arguments[0],i):r[t]}}(s)}}catch(t){o=!0,c=t}finally{try{!a&&u.return&&u.return()}finally{if(o)throw c}}return i},F="d3fc-group.cartesian-chart{width:100%;height:100%;overflow:hidden;display:grid;display:-ms-grid;grid-template-columns:minmax(1em,max-content) auto 1fr auto minmax(1em,max-content);-ms-grid-columns:minmax(1em,max-content) auto 1fr auto minmax(1em,max-content);grid-template-rows:minmax(1em,max-content) auto 1fr auto minmax(1em,max-content);-ms-grid-rows:minmax(1em,max-content) auto 1fr auto minmax(1em,max-content);}\nd3fc-group.cartesian-chart>.top-label{align-self:center;-ms-grid-column-align:center;justify-self:center;-ms-grid-row-align:center;grid-column:3;-ms-grid-column:3;-ms-grid-row:1;-ms-grid-row:1;}\nd3fc-group.cartesian-chart>.top-axis{height:2em;grid-column:3;-ms-grid-column:3;grid-row:2;-ms-grid-row:2;}\nd3fc-group.cartesian-chart>.left-label{align-self:center;-ms-grid-column-align:center;justify-self:center;-ms-grid-row-align:center;grid-column:1;-ms-grid-column:1;grid-row:3;-ms-grid-row:3;}\nd3fc-group.cartesian-chart>.left-axis{width:3em;grid-column:2;-ms-grid-column:2;grid-row:3;-ms-grid-row:3;}\nd3fc-group.cartesian-chart>.plot-area{overflow:hidden;grid-column:3;-ms-grid-column:3;grid-row:3;-ms-grid-row:3;}\nd3fc-group.cartesian-chart>.right-axis{width:3em;grid-column:4;-ms-grid-column:4;grid-row:3;-ms-grid-row:3;}\nd3fc-group.cartesian-chart>.right-label{align-self:center;-ms-grid-column-align:center;justify-self:center;-ms-grid-row-align:center;grid-column:5;-ms-grid-column:5;grid-row:3;-ms-grid-row:3;}\nd3fc-group.cartesian-chart>.bottom-axis{height:2em;grid-column:3;-ms-grid-column:3;grid-row:4;-ms-grid-row:4;}\nd3fc-group.cartesian-chart>.bottom-label{align-self:center;-ms-grid-column-align:center;justify-self:center;-ms-grid-row-align:center;grid-column:3;-ms-grid-column:3;grid-row:5;-ms-grid-row:5;}",N=document.createElement("style");N.setAttribute("type","text/css"),document.querySelector("head").appendChild(N),N.styleSheet?N.styleSheet.cssText+=F:N.textContent+=F;var L=function(t){return"function"==typeof t?t:function(){return t}},X=function(){for(var t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];var i=Y.apply(void 0,n),a=i.xScale,o=i.yScale,c=i.xAxis,l=i.yAxis,u=L(""),f=L(""),g=L(null),h=L(null),y=L("right"),p=L("bottom"),x=j(),b=O(),w=E("tickFormat","ticks","tickArguments","tickSize","tickSizeInner","tickSizeOuter","tickValues","tickPadding"),k=function(){},S=E("tickFormat","ticks","tickArguments","tickSize","tickSizeInner","tickSizeOuter","tickValues","tickPadding"),A=function(){},_=function(){},z=v("d3fc-group","cartesian-chart"),P=v("d3fc-svg","x-axis").key(function(t){return t}),I=v("d3fc-svg","y-axis").key(function(t){return t}),C=v("div","x-label").key(function(t){return t}),V=v("div","y-label").key(function(t){return t}),q=function(t){return function(n){return t.selection?n.transition(t):n}},F=function(t){var n=q(t);t.each(function(t,r,i){var s=z(e.select(i[r]),[t]);s.enter().attr("auto-resize","").html('<d3fc-svg class="plot-area"></d3fc-svg><d3fc-canvas class="plot-area"></d3fc-canvas>'),C(s,[p(t)]).attr("class",function(t){return"x-label "+t+"-label"}).text(u(t)),V(s,[y(t)]).attr("class",function(t){return"y-label "+t+"-label"}).text(f(t)),P(s,[p(t)]).attr("class",function(t){return"x-axis "+t+"-axis"}).style("height",g(t)).on("measure",function(t,n,r){var i=e.event.detail,o=i.width,c=i.height;"top"===t&&e.select(r[n]).select("svg").attr("viewBox","0 "+-c+" "+o+" "+c),a.range([0,o])}).on("draw",function(t,r,i){var o="top"===t?c.top(a):c.bottom(a);o.decorate(k),n(e.select(i[r])).select("svg").call(w(o))}),I(s,[y(t)]).attr("class",function(t){return"y-axis "+t+"-axis"}).style("width",h(t)).on("measure",function(t,n,r){var i=e.event.detail,a=i.width,c=i.height;"left"===t&&e.select(r[n]).select("svg").attr("viewBox",-a+" 0 "+a+" "+c),o.range([c,0])}).on("draw",function(t,r,i){var a="left"===t?l.left(o):l.right(o);a.decorate(A),n(e.select(i[r])).select("svg").call(S(a))}),s.select("d3fc-canvas.plot-area").on("draw",function(t,n,r){var i=e.select(r[n]).select("canvas").node();x.context(i.getContext("2d")).xScale(a).yScale(o),x(t)}),s.select("d3fc-svg.plot-area").on("draw",function(t,r,i){b.xScale(a).yScale(o),n(e.select(i[r])).select("svg").call(b)}),s.each(function(t,n,e){return e[n].requestRedraw()}),_(s,t,r)})},N=d(/range\w*/,/tickFormat/);return s(F,a,N,m("x")),s(F,o,N,m("y")),s(F,w,m("x")),s(F,S,m("y")),F.xOrient=function(){return arguments.length?(p=L(arguments.length<=0?void 0:arguments[0]),F):p},F.yOrient=function(){return arguments.length?(y=L(arguments.length<=0?void 0:arguments[0]),F):y},F.xDecorate=function(){return arguments.length?(k=arguments.length<=0?void 0:arguments[0],F):k},F.yDecorate=function(){return arguments.length?(A=arguments.length<=0?void 0:arguments[0],F):A},F.xLabel=function(){return arguments.length?(u=L(arguments.length<=0?void 0:arguments[0]),F):u},F.yLabel=function(){return arguments.length?(f=L(arguments.length<=0?void 0:arguments[0]),F):f},F.xAxisHeight=function(){return arguments.length?(g=L(arguments.length<=0?void 0:arguments[0]),F):g},F.yAxisWidth=function(){return arguments.length?(h=L(arguments.length<=0?void 0:arguments[0]),F):h},F.canvasPlotArea=function(){return arguments.length?(x=arguments.length<=0?void 0:arguments[0],F):x},F.svgPlotArea=function(){return arguments.length?(b=arguments.length<=0?void 0:arguments[0],F):b},F.decorate=function(){return arguments.length?(_=arguments.length<=0?void 0:arguments[0],F):_},F},Y=function(){for(var t=arguments.length,e=Array(t),r=0;r<t;r++)e[r]=arguments[r];var i={xScale:n.scaleIdentity(),yScale:n.scaleIdentity(),xAxis:{bottom:C,top:I},yAxis:{right:q,left:V}};return 1!==e.length||e[0].domain||e[0].range?Object.assign(i,{xScale:e[0]||i.xScale,yScale:e[1]||i.yScale}):Object.assign(i,e[0])},B=function(t){return"function"==typeof t?t:function(){return t}},D=function(t,n){return function(){for(var e=arguments.length,r=Array(e),i=0;i<e;i++)r[i]=arguments[i];var a=B(""),o=B(""),c=n,l=function(){},u=X.apply(void 0,r),f=function(n){t(u,c),u.decorate(function(t,n,e){t.enter().select(".x-label").style("height","1em").style("line-height","1em");var r=u.yOrient()(n);t.enter().append("div").attr("class","y-label-container").style("grid-column","left"===r?1:5).style("-ms-grid-column","left"===r?1:5).style("grid-row",3).style("-ms-grid-row",3).style("width","1em").style("display","flex").style("align-items","center").style("justify-content","center").append("div").attr("class","y-label").style("transform","rotate(-90deg)"),t.select(".y-label-container>.y-label").text(o),t.select(".top-label").style("margin-top","2em"),t.enter().append("div").attr("class","chart-label").style("grid-column",3).style("-ms-grid-column",3).style("grid-row",1).style("-ms-grid-row",1).style("height","2em").style("line-height","2em").style("text-align","center"),t.select(".chart-label").text(a(n)),l(t,n,e)}),n.call(u)};return s(f,u,g(/^x/,/^y/)),f.chartLabel=function(){return arguments.length?(a=B(arguments.length<=0?void 0:arguments[0]),f):a},f.yLabel=function(){return arguments.length?(o=B(arguments.length<=0?void 0:arguments[0]),f):o},f.plotArea=function(){return arguments.length?(c=arguments.length<=0?void 0:arguments[0],f):c},f.decorate=function(){return arguments.length?(l=arguments.length<=0?void 0:arguments[0],f):l},f}},M=D(function(t,n){return t.svgPlotArea(n)},k),R=D(function(t,n){return t.canvasPlotArea(n)},S);t.chartSvgCartesian=M,t.chartCanvasCartesian=R,t.chartCartesian=X,Object.defineProperty(t,"__esModule",{value:!0})}); |
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="2.4.0"></a> | ||
# [2.4.0](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-chart@2.3.0...@d3fc/d3fc-chart@2.4.0) (2019-03-11) | ||
### Features | ||
* Allow custom axis components in cartesian chart ([5373133](https://github.com/d3fc/d3fc/commit/5373133)) | ||
<a name="2.3.0"></a> | ||
@@ -8,0 +19,0 @@ # [2.3.0](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-chart@2.2.0...@d3fc/d3fc-chart@2.3.0) (2019-03-07) |
{ | ||
"name": "@d3fc/d3fc-chart", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "A simple Cartesian chart component that renders to canvas or SVG.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -160,2 +160,25 @@ # d3fc-chart | ||
#### Using custom axis components | ||
By default the chart uses d3fc-axis for the axis component. This example shows how to specify which axis components to use for the X and Y axis. | ||
```javascript | ||
var chart = fc.chartCartesian({ | ||
xScale: d3.scaleLinear(), | ||
yScale: d3.scaleLinear(), | ||
xAxis: { | ||
bottom: myCustomAxis | ||
}, | ||
yAxis: { | ||
left: fc.axisLeft | ||
} | ||
}) | ||
.xLabel('Value') | ||
.yLabel('Sine / Cosine') | ||
.yOrient('left') | ||
.yDomain(yExtent(data)) | ||
.xDomain(xExtent(data)) | ||
.canvasPlotArea(series); | ||
``` | ||
#### Adding a Second Axis | ||
@@ -232,2 +255,10 @@ | ||
<a name="chartCartesianSettings" href="#chartCartesianSettings">#</a> fc.**chartCartesian**({ xScale: *xScale*, yScale: *yScale*, xAxis: axisFactory, yAxis: axisFactory }) | ||
Constructs a new Cartesian chart with the given scales and axis components. | ||
If *xAxis* is specified, it must be an object with the required x-axis factory function (*left* if *yOrient*="left" or *right* if *yOrient*="right"). | ||
If *yAxis* is specified, it must be an object with the required y-axis factory function (*top* if *xOrient*="top" or *bottom* if *xOrient*="bottom"). | ||
<a name="cartesian_svgPlotArea" href="#cartesian_svgPlotArea">#</a> *cartesian*.**svgPlotArea**(*component*) | ||
@@ -234,0 +265,0 @@ <a name="cartesian_canvasPlotArea" href="#cartesian_canvasPlotArea">#</a> *cartesian*.**canvasPlotArea**(*component*) |
@@ -13,3 +13,4 @@ import { select, event } from 'd3-selection'; | ||
export default (xScale = scaleIdentity(), yScale = scaleIdentity()) => { | ||
export default (...args) => { | ||
const { xScale, yScale, xAxis, yAxis } = getArguments(...args); | ||
@@ -78,7 +79,7 @@ let xLabel = functor(''); | ||
.on('draw', (d, i, nodes) => { | ||
const xAxis = d === 'top' ? axisTop(xScale) : axisBottom(xScale); | ||
xAxis.decorate(xDecorate); | ||
const xAxisComponent = d === 'top' ? xAxis.top(xScale) : xAxis.bottom(xScale); | ||
xAxisComponent.decorate(xDecorate); | ||
transitionPropagator(select(nodes[i])) | ||
.select('svg') | ||
.call(xAxisStore(xAxis)); | ||
.call(xAxisStore(xAxisComponent)); | ||
}); | ||
@@ -99,7 +100,7 @@ | ||
.on('draw', (d, i, nodes) => { | ||
const yAxis = d === 'left' ? axisLeft(yScale) : axisRight(yScale); | ||
yAxis.decorate(yDecorate); | ||
const yAxisComponent = d === 'left' ? yAxis.left(yScale) : yAxis.right(yScale); | ||
yAxisComponent.decorate(yDecorate); | ||
transitionPropagator(select(nodes[i])) | ||
.select('svg') | ||
.call(yAxisStore(yAxis)); | ||
.call(yAxisStore(yAxisComponent)); | ||
}); | ||
@@ -223,1 +224,21 @@ | ||
}; | ||
const getArguments = (...args) => { | ||
const defaultSettings = { | ||
xScale: scaleIdentity(), | ||
yScale: scaleIdentity(), | ||
xAxis: { bottom: axisBottom, top: axisTop }, | ||
yAxis: { right: axisRight, left: axisLeft } | ||
}; | ||
if (args.length === 1 && !args[0].domain && !args[0].range) { | ||
// Settings object | ||
return Object.assign(defaultSettings, args[0]); | ||
} | ||
// xScale/yScale parameters | ||
return Object.assign(defaultSettings, { | ||
xScale: args[0] || defaultSettings.xScale, | ||
yScale: args[1] || defaultSettings.yScale | ||
}); | ||
}; |
@@ -9,3 +9,3 @@ import { scaleIdentity } from 'd3-scale'; | ||
export default (setPlotArea, defaultPlotArea) => | ||
(xScale = scaleIdentity(), yScale = scaleIdentity()) => { | ||
(...args) => { | ||
@@ -17,3 +17,3 @@ let chartLabel = functor(''); | ||
const cartesian = cartesianChart(xScale, yScale); | ||
const cartesian = cartesianChart(...args); | ||
@@ -20,0 +20,0 @@ const cartesianBase = (selection) => { |
129827
31
1821
318