UNPKG

billboard.js

Version:

Re-usable easy interface JavaScript chart library, based on D3 v4+

12 lines 9.44 kB
/*! * Copyright (c) 2017 ~ present NAVER Corp. * billboard.js project is licensed under the MIT license * * billboard.js, JavaScript chart library * https://naver.github.io/billboard.js/ * * @version 3.3.3 * @requires billboard.js * @summary billboard.js plugin */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("d3-selection"),require("d3-brush")):"function"==typeof define&&define.amd?define("bb",["d3-selection","d3-brush"],t):"object"==typeof exports?exports.bb=t(require("d3-selection"),require("d3-brush")):(e.bb=e.bb||{},e.bb.plugin=e.bb.plugin||{},e.bb.plugin.sparkline=t(e.d3,e.d3))}(this,(function(e,t){return function(){"use strict";var n=[,function(t){t.exports=e},,function(e){e.exports=t}],r={};function i(e){var t=r[e];if(void 0!==t)return t.exports;var o=r[e]={exports:{}};return n[e](o,o.exports,i),o.exports}i.d=function(e,t){for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var o={};return function(){function e(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function t(e,n){return t=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},t(e,n)}function n(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t,i=1;i<arguments.length;i++)t=null!=arguments[i]?arguments[i]:{},i%2?r(Object(t),!0).forEach((function(r){n(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):r(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}));return e}i.d(o,{default:function(){return f}});var c={button:"bb-button",chart:"bb-chart",empty:"bb-empty",main:"bb-main",target:"bb-target",EXPANDED:"_expanded_"},l=(a(a(a(a(a(a(a(a(a(a(a(a(a(a(a(a(a(a(a(a(a(a(a({},c),{arc:"bb-arc",arcLabelLine:"bb-arc-label-line",arcs:"bb-arcs",chartArc:"bb-chart-arc",chartArcs:"bb-chart-arcs",chartArcsBackground:"bb-chart-arcs-background",chartArcsTitle:"bb-chart-arcs-title"}),{area:"bb-area",areas:"bb-areas"}),{axis:"bb-axis",axisX:"bb-axis-x",axisXLabel:"bb-axis-x-label",axisY:"bb-axis-y",axisY2:"bb-axis-y2",axisY2Label:"bb-axis-y2-label",axisYLabel:"bb-axis-y-label"}),{bar:"bb-bar",bars:"bb-bars",chartBar:"bb-chart-bar",chartBars:"bb-chart-bars"}),{candlestick:"bb-candlestick",candlesticks:"bb-candlesticks",chartCandlestick:"bb-chart-candlestick",chartCandlesticks:"bb-chart-candlesticks",valueDown:"bb-value-down",valueUp:"bb-value-up"}),{chartCircles:"bb-chart-circles",circle:"bb-circle",circles:"bb-circles"}),{colorPattern:"bb-color-pattern",colorScale:"bb-colorscale"}),{dragarea:"bb-dragarea",INCLUDED:"_included_"}),{chartArcsGaugeMax:"bb-chart-arcs-gauge-max",chartArcsGaugeMin:"bb-chart-arcs-gauge-min",chartArcsGaugeUnit:"bb-chart-arcs-gauge-unit",chartArcsGaugeTitle:"bb-chart-arcs-gauge-title",gaugeValue:"bb-gauge-value"}),{legend:"bb-legend",legendBackground:"bb-legend-background",legendItem:"bb-legend-item",legendItemEvent:"bb-legend-item-event",legendItemHidden:"bb-legend-item-hidden",legendItemPoint:"bb-legend-item-point",legendItemTile:"bb-legend-item-tile"}),{chartLine:"bb-chart-line",chartLines:"bb-chart-lines",line:"bb-line",lines:"bb-lines"}),{eventRect:"bb-event-rect",eventRects:"bb-event-rects",eventRectsMultiple:"bb-event-rects-multiple",eventRectsSingle:"bb-event-rects-single"}),{focused:"bb-focused",defocused:"bb-defocused",legendItemFocused:"bb-legend-item-focused",xgridFocus:"bb-xgrid-focus",ygridFocus:"bb-ygrid-focus"}),{grid:"bb-grid",gridLines:"bb-grid-lines",xgrid:"bb-xgrid",xgridLine:"bb-xgrid-line",xgridLines:"bb-xgrid-lines",xgrids:"bb-xgrids",ygrid:"bb-ygrid",ygridLine:"bb-ygrid-line",ygridLines:"bb-ygrid-lines",ygrids:"bb-ygrids"}),{chartRadar:"bb-chart-radar",chartRadars:"bb-chart-radars",level:"bb-level",levels:"bb-levels"}),{region:"bb-region",regions:"bb-regions"}),{selectedCircle:"bb-selected-circle",selectedCircles:"bb-selected-circles",SELECTED:"_selected_"}),{shape:"bb-shape",shapes:"bb-shapes"}),{brush:"bb-brush",subchart:"bb-subchart"}),{chartText:"bb-chart-text",chartTexts:"bb-chart-texts",text:"bb-text",texts:"bb-texts",title:"bb-title",TextOverlapping:"text-overlapping"}),{tooltip:"bb-tooltip",tooltipContainer:"bb-tooltip-container",tooltipName:"bb-tooltip-name"}),{buttonZoomReset:"bb-zoom-reset",zoomBrush:"bb-zoom-brush"}),function(){function e(e){void 0===e&&(e={}),this.$$=void 0,this.options=void 0,this.options=e}var t=e.prototype;return t.$beforeInit=function(){},t.$init=function(){},t.$afterInit=function(){},t.$redraw=function(){},t.$willDestroy=function(){var e=this;Object.keys(this).forEach((function(t){e[t]=null,delete e[t]}))},e}());l.version="3.3.3";var b=function(){return{selector:void 0}},s=(i(1),i(3),"object"==typeof globalThis&&null!==globalThis&&globalThis.Object===Object&&globalThis||"object"==typeof global&&null!==global&&global.Object===Object&&global||"object"==typeof self&&null!==self&&self.Object===Object&&self||Function("return this")());s.requestIdleCallback=s.requestIdleCallback||function(e){return setTimeout(e,1)},s.cancelIdleCallback=s.cancelIdleCallback||function(e){return clearTimeout(e)};var u=null==s?void 0:s.document;var d=function(e){return void 0!==e},h=function(e){return"object"==typeof e};!function(){try{new MouseEvent("t")}catch(e){return function(e,t,n){void 0===n&&(n={bubbles:!1,cancelable:!1,screenX:0,screenY:0,clientX:0,clientY:0});var r=u.createEvent("MouseEvent");r.initMouseEvent(t,n.bubbles,n.cancelable,s,0,n.screenX,n.screenY,n.clientX,n.clientY,!1,!1,!1,!1,0,null),e.dispatchEvent(r)}}}();function g(e){var t,n,r,i=this.config,o=function(){var e=n.shift();return e&&t&&h(t)&&e in t?(t=t[e],o()):e?void 0:t};Object.keys(i).forEach((function(a){t=e,n=a.split("_"),r=o(),d(r)&&(i[a]=r)}))}var f=function(n){var r,i;function o(t){var r=n.call(this,t)||this;return r.config=void 0,r.element=void 0,r.config=new b,e(r)||e(r)}i=n,(r=o).prototype=Object.create(i.prototype),r.prototype.constructor=r,t(r,i);var a=o.prototype;return a.$beforeInit=function(){g.call(this,this.options),this.validate(),this.element=[].slice.call(document.querySelectorAll(this.config.selector)),this.overrideInternals(),this.overrideOptions(),this.overHandler=this.overHandler.bind(this),this.moveHandler=this.moveHandler.bind(this),this.outHandler=this.outHandler.bind(this)},a.validate=function(){var e=this.$$,t=this.config,n="";if(t.selector&&document.querySelector(t.selector)||(n="No holder elements found from given selector option."),(e.hasType("bubble")||e.hasType("scatter")||e.hasArcType(e.data.targets))&&(n="Contains non supported chart types."),n)throw new Error("[Sparkline plugin] "+n)},a.overrideInternals=function(){var e=this.$$,t=e.getBarW,n=e.getIndices;e.getIndices=function(e,t,r){return"getShapeX"===r?{}:n.call(this,e,t)},e.getBarW=function(e,n){return t.call(this,e,n,1)}},a.overrideOptions=function(){var e=this.$$.config;e.legend_show=!1,e.resize_auto=!1,e.axis_x_show=!1,e.axis_x_padding={left:15,right:15,unit:"px"},e.axis_y_show=!1,e.axis_y_padding=5,e.tooltip_position||(e.tooltip_position=function(e,t,n){var r=this.internal.state.event,i=r.pageY-1.35*n,o=r.pageX-t/2;return i<0&&(i=0),o<0&&(o=0),{top:i,left:o}})},a.$init=function(){var e=this.$$.$el;e.chart.style("width","0").style("height","0").style("pointer-events","none"),document.body.appendChild(e.tooltip.node())},a.$afterInit=function(){this.$$.$el.svg.attr("style",null).style("width","0").style("height","0"),this.bindEvents(!0)},a.bindEvents=function(e){var t=this;if(void 0===e&&(e=!0),this.$$.config.interaction_enabled){var n=(e?"add":"remove")+"EventListener";this.element.forEach((function(e){var r=e.querySelector("svg");r[n]("mouseover",t.overHandler),r[n]("mousemove",t.moveHandler),r[n]("mouseout",t.outHandler)}))}},a.overHandler=function(e){this.$$.state.eventReceiver.rect=e.target.getBoundingClientRect()},a.moveHandler=function(e){var t,n,r,i=this.$$,o=i.getDataIndexFromEvent(e),a=null==(t=i.api.data(e.target.__id))?void 0:t[0],c=null==(n=a)||null==(r=n.values)?void 0:r[o];c&&!c.name&&(c.name=c.id),i.state.event=e,i.setExpand(o,a.id,!0),i.showTooltip([c],e.target)},a.outHandler=function(e){var t=this.$$;t.state.event=e,t.unexpandCircles(),t.hideTooltip()},a.$redraw=function(){var e,t=this.$$,n=t.$el,r=this.element,i=t.api.data(),o=null==(e=n.chart.html().match(/<svg[^>]*>/))?void 0:e[0];if(r.length<i.length){for(var a=n.chart.node(),l=i.length-r.length;l>0;l--)a.parentNode.insertBefore(r[0].cloneNode(),a.nextSibling);this.element=document.querySelectorAll(this.config.selector),r=this.element}i.map((function(e){return e.id})).forEach((function(e,t){var i="."+c.target+"-"+e,a=n.main.selectAll(i),l=r[t].querySelector("svg");l||(r[t].innerHTML=o+"</svg>",(l=r[t].querySelector("svg")).__id=e),l.querySelector(i)||a.style("opacity",null),a.style("fill","none").style("opacity",null),l.innerHTML="",l.appendChild(a.node())}))},a.$willDestroy=function(){this.bindEvents(!1),this.element.forEach((function(e){e.innerHTML=""}))},o}(l);f.version="0.0.1"}(),o=o.default}()}));