-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboula.min.js
2 lines (2 loc) · 22.5 KB
/
boula.min.js
1
2
// https://facette.io/ Version 0.4.2. Copyright 2019 Vincent Batoufflet.
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("d3")):"function"==typeof define&&define.amd?define(["d3"],e):t.boula=e(t.d3)}(this,function(o){"use strict";var n={axes:{x:{max:null,min:null,ticks:{count:10,font:{size:10},size:6}},y:{center:!1,label:{size:12,text:null},lines:[],max:null,min:null,stack:!1,ticks:{count:3,font:{size:10},format:o.format(".2r")}}},background:{color:null},colors:["#64b5f6","#455a64","#aed581","#ffb74d","#9575cd","#f06292","#ffd54f","#4db6ac","#4dd0e1","#e57373","#7986cb","#a1887f"],events:{afterDraw:null,handleEvent:null},font:{color:null,family:null},margin:24,titles:{main:{size:16,text:null},subtitle:{size:12,text:null}},type:"area"};var t=function(){this.__data__=[],this.size=0};var r=function(t,e){return t===e||t!=t&&e!=e};var a=function(t,e){for(var n=t.length;n--;)if(r(t[n][0],e))return n;return-1},i=Array.prototype.splice;var e=function(t){var e=this.__data__,n=a(e,t);return!(n<0||(n==e.length-1?e.pop():i.call(e,n,1),--this.size,0))};var c=function(t){var e=this.__data__,n=a(e,t);return n<0?void 0:e[n][1]};var s=function(t){return-1<a(this.__data__,t)};var f=function(t,e){var n=this.__data__,i=a(n,t);return i<0?(++this.size,n.push([t,e])):n[i][1]=e,this};function h(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}h.prototype.clear=t,h.prototype.delete=e,h.prototype.get=c,h.prototype.has=s,h.prototype.set=f;var l=h;var u=function(){this.__data__=new l,this.size=0};var g=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n};var v=function(t){return this.__data__.get(t)};var d=function(t){return this.__data__.has(t)},x="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function p(t,e){return t(e={exports:{}},e.exports),e.exports}var y="object"==typeof x&&x&&x.Object===Object&&x,m="object"==typeof self&&self&&self.Object===Object&&self,b=y||m||Function("return this")(),_=b.Symbol,j=Object.prototype,w=j.hasOwnProperty,O=j.toString,S=_?_.toStringTag:void 0;var k=function(t){var e=w.call(t,S),n=t[S];try{t[S]=void 0}catch(t){}var i=O.call(t);return e?t[S]=n:delete t[S],i},z=Object.prototype.toString;var A=function(t){return z.call(t)},T=_?_.toStringTag:void 0;var E=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":T&&T in Object(t)?k(t):A(t)};var F=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)};var P,B=function(t){if(!F(t))return!1;var e=E(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e},D=b["__core-js_shared__"],M=(P=/[^.]+$/.exec(D&&D.keys&&D.keys.IE_PROTO||""))?"Symbol(src)_1."+P:"";var R=function(t){return!!M&&M in t},C=Function.prototype.toString;var L=function(t){if(null!=t){try{return C.call(t)}catch(t){}try{return t+""}catch(t){}}return""},G=/^\[object .+?Constructor\]$/,q=Function.prototype,I=Object.prototype,U=q.toString,$=I.hasOwnProperty,W=RegExp("^"+U.call($).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var H=function(t){return!(!F(t)||R(t))&&(B(t)?W:G).test(L(t))};var N=function(t,e){return null==t?void 0:t[e]};var Y=function(t,e){var n=N(t,e);return H(n)?n:void 0},V=Y(b,"Map"),J=Y(Object,"create");var K=function(){this.__data__=J?J(null):{},this.size=0};var Q=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},X=Object.prototype.hasOwnProperty;var Z=function(t){var e=this.__data__;if(J){var n=e[t];return"__lodash_hash_undefined__"===n?void 0:n}return X.call(e,t)?e[t]:void 0},tt=Object.prototype.hasOwnProperty;var et=function(t){var e=this.__data__;return J?void 0!==e[t]:tt.call(e,t)};var nt=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=J&&void 0===e?"__lodash_hash_undefined__":e,this};function it(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}it.prototype.clear=K,it.prototype.delete=Q,it.prototype.get=Z,it.prototype.has=et,it.prototype.set=nt;var rt=it;var ot=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var at=function(t,e){var n=t.__data__;return ot(e)?n["string"==typeof e?"string":"hash"]:n.map};var ct=function(t){var e=at(this,t).delete(t);return this.size-=e?1:0,e};var st=function(t){return at(this,t).get(t)};var ft=function(t){return at(this,t).has(t)};var ht=function(t,e){var n=at(this,t),i=n.size;return n.set(t,e),this.size+=n.size==i?0:1,this};function lt(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var i=t[e];this.set(i[0],i[1])}}lt.prototype.clear=function(){this.size=0,this.__data__={hash:new rt,map:new(V||l),string:new rt}},lt.prototype.delete=ct,lt.prototype.get=st,lt.prototype.has=ft,lt.prototype.set=ht;var ut=lt;var gt=function(t,e){var n=this.__data__;if(n instanceof l){var i=n.__data__;if(!V||i.length<199)return i.push([t,e]),this.size=++n.size,this;n=this.__data__=new ut(i)}return n.set(t,e),this.size=n.size,this};function vt(t){var e=this.__data__=new l(t);this.size=e.size}vt.prototype.clear=u,vt.prototype.delete=g,vt.prototype.get=v,vt.prototype.has=d,vt.prototype.set=gt;var dt=vt,xt=function(){try{var t=Y(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();var pt=function(t,e,n){"__proto__"==e&&xt?xt(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n};var yt=function(t,e,n){(void 0===n||r(t[e],n))&&(void 0!==n||e in t)||pt(t,e,n)};var mt=function(s){return function(t,e,n){for(var i=-1,r=Object(t),o=n(t),a=o.length;a--;){var c=o[s?a:++i];if(!1===e(r[c],c,r))break}return t}}(),bt=p(function(t,e){var n=e&&!e.nodeType&&e,i=n&&t&&!t.nodeType&&t,r=i&&i.exports===n?b.Buffer:void 0,o=r?r.allocUnsafe:void 0;t.exports=function(t,e){if(e)return t.slice();var n=t.length,i=o?o(n):new t.constructor(n);return t.copy(i),i}}),_t=b.Uint8Array;var jt=function(t){var e=new t.constructor(t.byteLength);return new _t(e).set(new _t(t)),e};var wt=function(t,e){var n=e?jt(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)};var Ot=function(t,e){var n=-1,i=t.length;for(e||(e=Array(i));++n<i;)e[n]=t[n];return e},St=Object.create,kt=function(){function n(){}return function(t){if(!F(t))return{};if(St)return St(t);n.prototype=t;var e=new n;return n.prototype=void 0,e}}();var zt=function(e,n){return function(t){return e(n(t))}}(Object.getPrototypeOf,Object),At=Object.prototype;var Tt=function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||At)};var Et=function(t){return"function"!=typeof t.constructor||Tt(t)?{}:kt(zt(t))};var Ft=function(t){return null!=t&&"object"==typeof t};var Pt=function(t){return Ft(t)&&"[object Arguments]"==E(t)},Bt=Object.prototype,Dt=Bt.hasOwnProperty,Mt=Bt.propertyIsEnumerable,Rt=Pt(function(){return arguments}())?Pt:function(t){return Ft(t)&&Dt.call(t,"callee")&&!Mt.call(t,"callee")},Ct=Array.isArray;var Lt=function(t){return"number"==typeof t&&-1<t&&t%1==0&&t<=9007199254740991};var Gt=function(t){return null!=t&&Lt(t.length)&&!B(t)};var qt=function(t){return Ft(t)&&Gt(t)};var It=function(){return!1},Ut=p(function(t,e){var n=e&&!e.nodeType&&e,i=n&&t&&!t.nodeType&&t,r=i&&i.exports===n?b.Buffer:void 0,o=(r?r.isBuffer:void 0)||It;t.exports=o}),$t=Function.prototype,Wt=Object.prototype,Ht=$t.toString,Nt=Wt.hasOwnProperty,Yt=Ht.call(Object);var Vt=function(t){if(!Ft(t)||"[object Object]"!=E(t))return!1;var e=zt(t);if(null===e)return!0;var n=Nt.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&Ht.call(n)==Yt},Jt={};Jt["[object Float32Array]"]=Jt["[object Float64Array]"]=Jt["[object Int8Array]"]=Jt["[object Int16Array]"]=Jt["[object Int32Array]"]=Jt["[object Uint8Array]"]=Jt["[object Uint8ClampedArray]"]=Jt["[object Uint16Array]"]=Jt["[object Uint32Array]"]=!0,Jt["[object Arguments]"]=Jt["[object Array]"]=Jt["[object ArrayBuffer]"]=Jt["[object Boolean]"]=Jt["[object DataView]"]=Jt["[object Date]"]=Jt["[object Error]"]=Jt["[object Function]"]=Jt["[object Map]"]=Jt["[object Number]"]=Jt["[object Object]"]=Jt["[object RegExp]"]=Jt["[object Set]"]=Jt["[object String]"]=Jt["[object WeakMap]"]=!1;var Kt=function(t){return Ft(t)&&Lt(t.length)&&!!Jt[E(t)]};var Qt=function(e){return function(t){return e(t)}},Xt=p(function(t,e){var n=e&&!e.nodeType&&e,i=n&&t&&!t.nodeType&&t,r=i&&i.exports===n&&y.process,o=function(){try{var t=i&&i.require&&i.require("util").types;return t||r&&r.binding&&r.binding("util")}catch(t){}}();t.exports=o}),Zt=Xt&&Xt.isTypedArray,te=Zt?Qt(Zt):Kt;var ee=function(t,e){if("__proto__"!=e)return t[e]},ne=Object.prototype.hasOwnProperty;var ie=function(t,e,n){var i=t[e];ne.call(t,e)&&r(i,n)&&(void 0!==n||e in t)||pt(t,e,n)};var re=function(t,e,n,i){var r=!n;n||(n={});for(var o=-1,a=e.length;++o<a;){var c=e[o],s=i?i(n[c],t[c],c,n,t):void 0;void 0===s&&(s=t[c]),r?pt(n,c,s):ie(n,c,s)}return n};var oe=function(t,e){for(var n=-1,i=Array(t);++n<t;)i[n]=e(n);return i},ae=/^(?:0|[1-9]\d*)$/;var ce=function(t,e){var n=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==n||"symbol"!=n&&ae.test(t))&&-1<t&&t%1==0&&t<e},se=Object.prototype.hasOwnProperty;var fe=function(t,e){var n=Ct(t),i=!n&&Rt(t),r=!n&&!i&&Ut(t),o=!n&&!i&&!r&&te(t),a=n||i||r||o,c=a?oe(t.length,String):[],s=c.length;for(var f in t)!e&&!se.call(t,f)||a&&("length"==f||r&&("offset"==f||"parent"==f)||o&&("buffer"==f||"byteLength"==f||"byteOffset"==f)||ce(f,s))||c.push(f);return c};var he=function(t){var e=[];if(null!=t)for(var n in Object(t))e.push(n);return e},le=Object.prototype.hasOwnProperty;var ue=function(t){if(!F(t))return he(t);var e=Tt(t),n=[];for(var i in t)("constructor"!=i||!e&&le.call(t,i))&&n.push(i);return n};var ge=function(t){return Gt(t)?fe(t,!0):ue(t)};var ve=function(t){return re(t,ge(t))};var de=function(t,e,n,i,r,o,a){var c=ee(t,n),s=ee(e,n),f=a.get(s);if(f)yt(t,n,f);else{var h=o?o(c,s,n+"",t,e,a):void 0,l=void 0===h;if(l){var u=Ct(s),g=!u&&Ut(s),v=!u&&!g&&te(s);h=s,u||g||v?h=Ct(c)?c:qt(c)?Ot(c):g?bt(s,!(l=!1)):v?wt(s,!(l=!1)):[]:Vt(s)||Rt(s)?Rt(h=c)?h=ve(c):F(c)&&!B(c)||(h=Et(s)):l=!1}l&&(a.set(s,h),r(h,s,i,o,a),a.delete(s)),yt(t,n,h)}};var xe=function i(r,o,a,c,s){r!==o&&mt(o,function(t,e){if(F(t))s||(s=new dt),de(r,o,e,a,i,c,s);else{var n=c?c(ee(r,e),t,e+"",r,o,s):void 0;void 0===n&&(n=t),yt(r,e,n)}},ge)};var pe=function(t){return t};var ye=function(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)},me=Math.max;var be=function(o,a,c){return a=me(void 0===a?o.length-1:a,0),function(){for(var t=arguments,e=-1,n=me(t.length-a,0),i=Array(n);++e<n;)i[e]=t[a+e];e=-1;for(var r=Array(a+1);++e<a;)r[e]=t[e];return r[a]=c(i),ye(o,this,r)}};var _e=function(t){return function(){return t}},je=xt?function(t,e){return xt(t,"toString",{configurable:!0,enumerable:!1,value:_e(e),writable:!0})}:pe,we=Date.now;var Oe=function(n){var i=0,r=0;return function(){var t=we(),e=16-(t-r);if(r=t,0<e){if(800<=++i)return arguments[0]}else i=0;return n.apply(void 0,arguments)}}(je);var Se=function(t,e){return Oe(be(t,e,pe),t+"")};var ke=function(t,e,n){if(!F(n))return!1;var i=typeof e;return!!("number"==i?Gt(n)&&ce(e,n.length):"string"==i&&e in n)&&r(n[e],t)};var ze=function(c){return Se(function(t,e){var n=-1,i=e.length,r=1<i?e[i-1]:void 0,o=2<i?e[2]:void 0;for(r=3<c.length&&"function"==typeof r?(i--,r):void 0,o&&ke(e[0],e[1],o)&&(r=i<3?void 0:r,i=1),t=Object(t);++n<i;){var a=e[n];a&&c(t,a,n,r)}return t})}(function(t,e,n){xe(t,e,n)});ze.merge;function Ae(t){return Ae.components.execute.call(this,"init"),this.update(t),this}Object.assign(Ae.prototype,{destroy:function(){Ae.components.execute.call(this,"destroy")},draw:function(){var e=this;this.ctx.save(),["update","layout","beforeDraw","draw","afterDraw"].forEach(function(t){return Ae.components.execute.call(e,t)}),this.ctx.restore(),this.config.events.afterDraw&&this.config.events.afterDraw()},update:function(t){this.config=ze({},n,t);var e=getComputedStyle(document.body);null===this.config.background.color&&(this.config.background.color=e.backgroundColor),null===this.config.font.color&&(this.config.font.color=e.color),null===this.config.font.family&&(this.config.font.family=e.fontFamily),this.height=this.config.bindTo.parentNode.clientHeight,this.width=this.config.bindTo.parentNode.clientWidth,this.canvas=o.select(this.config.bindTo).attr("height",this.height).attr("width",this.width).node(),this.ctx=this.canvas.getContext("2d"),Ae.helpers.hidpiScale(this)}});var Te,Ee,Fe,Pe,Be,De,Me,Re,Ce,Le={_components:[],execute:function(e){var n=this;Le._components.forEach(function(t){t.hasOwnProperty(e)&&t[e].call(n)})},register:function(t){Le._components.push(t)}};function Ge(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}return Ae.helpers={hidpiScale:function(t){var e=devicePixelRatio||1;if(1!=e){var n=t.canvas.height,i=t.canvas.width;t.canvas.height*=e,t.canvas.width*=e,Object.assign(t.canvas.style,{height:"".concat(n,"px"),width:"".concat(i,"px")}),t.ctx.scale(e,e)}},toRGBA:function(t,e){var n=o.rgb(t);return"rgba(".concat(n.r,", ").concat(n.g,", ").concat(n.b,", ").concat("number"==typeof e?e:1,")")}},Ae.colors=n.colors,Ae.components=Le,Ee={init:function(){Object.assign(this,{clear:Ee._clear})},layout:function(){Ee._clear.call(this),this.area={left:this.config.margin,top:this.config.margin,height:this.height-2*this.config.margin,width:this.width-2*this.config.margin},this.config.axes.y.label.text&&(this.area.left+=this.config.margin,this.area.width-=this.config.margin)},beforeDraw:function(){Object.assign(this.area,{left:this.width-this.area.width-this.config.margin,top:this.height-this.area.height-this.config.margin}),this.ctx.translate(this.area.left,this.area.top)},draw:function(){var n=this,t=this.yScale.ticks(this.config.axes.y.ticks.count);this.ctx.beginPath(),this.ctx.lineWidth=1,this.ctx.strokeStyle=Te.helpers.toRGBA(this.config.font.color,.1),t.forEach(function(t){var e=n.yScale(t);n.ctx.moveTo(0,e),n.ctx.lineTo(n.area.width,e)}),this.ctx.stroke()},_clear:function(){this.ctx.fillStyle=this.config.background.color,this.ctx.clearRect(0,0,this.width,this.height),this.ctx.rect(0,0,this.width,this.height),this.ctx.fill()}},(Te=Ae).components.register(Ee),(Fe=Ae).components.register({afterDraw:function(){var n=this;this.ctx.beginPath(),this.ctx.font="".concat(this.config.axes.x.ticks.font.size,"px ").concat(this.config.font.family),this.ctx.lineWidth=1,this.ctx.strokeStyle=Fe.helpers.toRGBA(this.config.font.color,.25),this.ctx.textAlign="center",this.ctx.textBaseline="hanging",this.xScale.ticks(this.config.axes.x.ticks.count).forEach(function(t){var e=n.xScale(t);n.ctx.moveTo(e,n.area.height),n.ctx.lineTo(e,n.area.height+n.config.axes.x.ticks.size),n.ctx.fillStyle=n.config.font.color,n.ctx.fillText(n.xFormat(t),e,n.area.height+1.35*n.config.axes.x.ticks.size)}),this.ctx.stroke(),this.ctx.moveTo(0,this.area.height),this.ctx.lineTo(this.area.width,this.area.height),this.ctx.stroke(),this.config.axes.y.label.text&&(this.ctx.save(),this.ctx.font="".concat(this.config.axes.y.label.size,"px ").concat(this.config.font.family),this.ctx.fillStyle=Fe.helpers.toRGBA(this.config.font.color,.65),this.ctx.textAlign="center",this.ctx.textBaseline="middle",this.ctx.translate(-this.area.left+this.config.margin,this.area.height/2),this.ctx.rotate(-Math.PI/2),this.ctx.fillText(this.config.axes.y.label.text,0,0),this.ctx.restore()),this.ctx.font="".concat(this.config.axes.y.ticks.font.size,"px ").concat(this.config.font.family),this.ctx.textAlign="right",this.ctx.textBaseline="middle",this.yScale.ticks(this.config.axes.y.ticks.count).forEach(function(t){n.ctx.fillStyle=n.config.font.color,n.ctx.fillText(n.yFormat(t),-n.config.axes.x.ticks.size,n.yScale(t))})}}),Ae.components.register({update:function(){switch(this.config.axes.y.stack){case"normal":case"percent":var i={},t=[];this.config.series.forEach(function(n){n.points&&n.points.forEach(function(t){if(!n.disabled){var e=1e3*t[0];i[e]||(i[e]={date:e}),i[e][n.name]=t[1]}}),t.push(n.name)}),"percent"==this.config.axes.y.stack&&Object.keys(i).forEach(function(n){var t=Object.keys(i[n]),e=t.reduce(function(t,e){return"date"!=e?t+i[n][e]:t},0);t.forEach(function(t){"date"!=t&&0!=e&&(i[n][t]/=e)})});var e=o.stack().keys(t).order(o.stackOrderReverse);this.data=e(Object.values(i)).map(function(t){return t.map(function(t){return{x:t.data.date,y0:t[0],y1:t[1]}})});break;default:this.data=this.config.series.map(function(t){return t.points?t.points.map(function(t){return{x:1e3*t[0],y1:t[1]}}):[]})}}}),Ae.components.register({destroy:function(){var e=this;this.config.events.handleEvent&&["mousedown","mouseup","mouseenter","mouseleave","mousemove"].forEach(function(t){e.canvas.removeEventListener(t,e.config.events.handleEvent)})},afterDraw:function(){var e=this;this.config.events.handleEvent&&["mousedown","mouseup","mouseenter","mouseleave","mousemove"].forEach(function(t){e.canvas.addEventListener(t,e.config.events.handleEvent.bind(e))})}}),Be={init:function(){Object.assign(this,{addLine:Be._add,removeLine:Be._remove})},afterDraw:function(){var s=this;this.ctx.save(),this.ctx.font="".concat(this.config.axes.y.ticks.font.size-2,"px ").concat(this.config.font.family),this.ctx.textAlign="right",this.ctx.textBaseline="middle",this.config.axes.y.lines.forEach(function(t){var e=s.yScale(t.y),n=0;if(!(e<0)){if(t.color||(t.color=s.config.font.color),t.label){var i="boolean"==typeof t.label?s.yFormat(t.y):t.label,r=s.ctx.measureText(i),o=Math.round(2),a=Math.round(4),c=-s.config.axes.x.ticks.size-r.width;s.ctx.save(),0<(n=Math.abs(c)-s.area.left+s.config.margin/2)&&s.ctx.translate(n,0),s.ctx.fillStyle=t.color,s.ctx.beginPath(),s.ctx.moveTo(c,e-6),s.ctx.lineTo(-s.config.axes.x.ticks.size,e-6),s.ctx.quadraticCurveTo(-a,e-6,0,e),s.ctx.quadraticCurveTo(-a,e+6,-s.config.axes.x.ticks.size,e+6),s.ctx.lineTo(c,e+6),s.ctx.quadraticCurveTo(c-o,e+6,c-o,e+a),s.ctx.lineTo(c-o,e-a),s.ctx.quadraticCurveTo(c-o,e-6,c,e-6),s.ctx.closePath(),s.ctx.fill(),s.ctx.fillStyle=Pe.helpers.toRGBA(s.config.background.color,.8),s.ctx.fillText(i,-s.config.axes.x.ticks.size,e),s.ctx.restore()}s.ctx.save(),s.ctx.lineWidth=1,s.ctx.strokeStyle=t.color,s.ctx.beginPath(),t.dashed&&s.ctx.setLineDash([4,4]),s.ctx.moveTo(0<n?n:0,e),s.ctx.lineTo(s.area.width,e),s.ctx.stroke(),s.ctx.restore()}}),this.ctx.restore()},_add:function(t,e){this.config.axes.y.lines.push(Object.assign(e,{id:t})),this.draw()},_remove:function(e){var t=this.config.axes.y.lines.length;this.config.axes.y.lines=this.config.axes.y.lines.filter(function(t){return t.id!==e}),this.config.axes.y.lines.length!==t&&this.draw()}},(Pe=Ae).components.register(Be),De={layout:function(){var e=this;this.yScale=o.scaleLinear().domain(De._getDomain.call(this,"y","y1")).range([this.area.height,0]).nice(),this.yFormat="percent"==this.config.axes.y.stack?o.format(".0%"):this.config.axes.y.ticks.format,this.ctx.font="".concat(this.config.axes.y.ticks.font.size,"px ").concat(this.config.font.family),this.area.width-=Math.max.apply(Math,Ge(this.yScale.ticks(this.config.axes.y.ticks.count).map(function(t){return e.ctx.measureText(e.yFormat(t)).width}))),this.xScale=o.scaleTime().domain(De._getDomain.call(this,"x","x")).range([0,this.area.width]),this.xFormat=function(t){return(o.timeSecond(t)<t?o.timeFormat(".%L"):o.timeMinute(t)<t?o.timeFormat(":%S"):o.timeHour(t)<t?o.timeFormat("%H:%M"):o.timeDay(t)<t?o.timeFormat("%H:00"):o.timeMonth(t)<t?o.timeFormat("%a %d"):o.timeYear(t)<t?o.timeFormat("%B"):o.timeFormat("%Y"))(t)}},_getDomain:function(t,n){var e,i,r=this;return e=null!==this.config.axes[t].min?this.config.axes[t].min:o.min(this.data,function(t,e){if(!r.config.series[e].disabled)return o.min(t,function(t){return t[n]})}),i=null!==this.config.axes[t].max?this.config.axes[t].max:o.max(this.data,function(t,e){if(!r.config.series[e].disabled)return o.max(t,function(t){return t[n]})}),"y"==t&&(0<e&&!this.config.axes.y.min?e=0:this.config.axes.y.center&&e<0&&(e=-1*(i=Math.max(i,Math.abs(e))))),[e||0,i||1]}},Ae.components.register(De),Re={init:function(){Object.assign(this,{selectSeries:Re._select})},draw:function(){var n,i=this;"area"==this.config.type&&(n=o.area().defined(function(t){return t.y1}).x(function(t){return i.xScale(t.x)}).y0(function(t){return i.yScale(t.y0||0)}).y1(function(t){return i.yScale(t.y1)}).context(this.ctx));var r=o.line().defined(function(t){return t.y1}).x(function(t){return i.xScale(t.x)}).y(function(t){return i.yScale(t.y1)}).context(this.ctx),t=this.config.axes.y.max?this.yScale(this.config.axes.y.max):0,e=(this.config.axes.y.min?this.yScale(this.config.axes.y.min):this.area.height)-t;this.ctx.save(),this.ctx.rect(0,t,this.area.width,e),this.ctx.clip(),this.data.forEach(function(t,e){i.config.series[e].disabled||(i.config.series[e].color||(i.config.series[e].color=i.config.colors[e%i.config.colors.length]),"area"!=i.config.type||i._highlight||(i.ctx.beginPath(),n(t),i.ctx.fillStyle=Me.helpers.toRGBA(i.config.series[e].color,.65),i.ctx.fill()),i.ctx.beginPath(),r(t),i.ctx.strokeStyle=i.config.series[e].color,i.ctx.lineWidth=1.5,i.ctx.stroke())}),this.ctx.restore()},_select:function(n){var t=1<arguments.length&&void 0!==arguments[1]&&arguments[1];if(!(n>=this.config.series.length)){if(t)this.config.series[n].disabled=!this.config.series[n].disabled;else{var i=null;1!=this.config.series.filter(function(t){return!t.disabled}).length||this.config.series[n].disabled||(i=!1),this.config.series.forEach(function(t,e){t.disabled=null!==i?i:e!==n})}this.draw()}}},(Me=Ae).components.register(Re),(Ce=Ae).components.register({layout:function(){var t=0;this.config.titles.main.text&&(t+=this.config.titles.main.size),this.config.titles.subtitle.text&&(t+=this.config.titles.subtitle.size),0<t&&(this.area.height-=t+.5*this.config.margin,this.yScale.range([this.area.height,0]))},draw:function(){if(this.config.titles.main.text||this.config.titles.subtitle.text){var t=-1.5*this.config.margin,e=0;this.ctx.save(),this.ctx.textAlign="center",this.config.titles.main.text&&(this.ctx.font="".concat(this.config.titles.main.size,"px ").concat(this.config.font.family),this.ctx.fillStyle=this.config.font.color,this.ctx.fillText(this.config.titles.main.text,this.area.width/2,t),e+=this.config.titles.main.size+.125*this.config.margin),this.config.titles.subtitle.text&&(this.ctx.font="".concat(this.config.titles.subtitle.size,"px ").concat(this.config.font.family),this.ctx.fillStyle=Ce.helpers.toRGBA(this.config.font.color,.5),this.ctx.fillText(this.config.titles.subtitle.text,this.area.width/2,t+e)),this.ctx.restore()}}}),Ae});