billboard.js
Version:
Re-usable easy interface JavaScript chart library, based on D3 v4+
12 lines • 6.37 kB
JavaScript
/*!
* 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(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("d3-selection"),require("d3-brush")):"function"==typeof define&&define.amd?define("bb",["d3-selection","d3-brush"],e):"object"==typeof exports?exports.bb=e(require("d3-selection"),require("d3-brush")):(t.bb=t.bb||{},t.bb.plugin=t.bb.plugin||{},t.bb.plugin.tableview=e(t.d3,t.d3))}(this,(function(t,e){return function(){"use strict";var n=[,function(e){e.exports=t},,function(t){t.exports=e}],r={};function o(t){var e=r[t];if(void 0!==e)return e.exports;var i=r[t]={exports:{}};return n[t](i,i.exports,o),i.exports}o.d=function(t,e){for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};var i={};return function(){function t(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function e(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function n(t,e){return n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(t,e)}o.d(i,{default:function(){return $}});var r=function(){function t(t){void 0===t&&(t={}),this.$$=void 0,this.options=void 0,this.options=t}var e=t.prototype;return e.$beforeInit=function(){},e.$init=function(){},e.$afterInit=function(){},e.$redraw=function(){},e.$willDestroy=function(){var t=this;Object.keys(this).forEach((function(e){t[e]=null,delete t[e]}))},t}();r.version="3.3.3";var c=function(){return{selector:void 0,categoryTitle:"Category",categoryFormat:function(t){var e=t;return this.$$.axis.isCategorized()?e=this.$$.categoryName(t):this.$$.axis.isTimeSeries()&&(e=t.toLocaleDateString()),e},class:void 0,style:!0,title:void 0,updateOnToggle:!0}},l="__tableview-style__",a="bb-tableview",u=".bb-tableview {\n\t\tborder-collapse:collapse;\n\t\tborder-spacing:0;\n\t\tbackground:#fff;\n\t\tmin-width:100%;\n\t\tmargin-top:10px;\n\t\tfont-family:sans-serif;\n\t\tfont-size:.9em;\n\t}\n\t.bb-tableview tr:hover {\n\t\tbackground:#eef7ff;\n\t}\n\t.bb-tableview thead tr {\n\t\tbackground:#f8f8f8;\n\t}\n\t.bb-tableview caption,.bb-tableview td,.bb-tableview th {\n\t\ttext-align: center;\n\t\tborder:1px solid silver;\n\t\tpadding:.5em;\n\t}\n\t.bb-tableview caption {\n\t\tfont-size:1.1em;\n\t\tfont-weight:700;\n\t\tmargin-bottom: -1px;\n\t}",s="<caption>{=title}</caption>\n\t\t<thead><tr>{=thead}</tr></thead>\n\t\t<tbody>{=tbody}</tbody>",f='<th scope="col">{=title}</th>',b='<th scope="row">{=value}</th>',d="<td>{=value}</td>",p=(o(1),o(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")());p.requestIdleCallback=p.requestIdleCallback||function(t){return setTimeout(t,1)},p.cancelIdleCallback=p.cancelIdleCallback||function(t){return clearTimeout(t)};var h=null==p?void 0:p.document;var v=function(t){return"number"==typeof t},g=function(t){return void 0!==t},y=function(t){return"object"==typeof t};!function(){try{new MouseEvent("t")}catch(t){return function(t,e,n){void 0===n&&(n={bubbles:!1,cancelable:!1,screenX:0,screenY:0,clientX:0,clientY:0});var r=h.createEvent("MouseEvent");r.initMouseEvent(e,n.bubbles,n.cancelable,p,0,n.screenX,n.screenY,n.clientX,n.clientY,!1,!1,!1,!1,0,null),t.dispatchEvent(r)}}}();function m(t,e){var n=t;for(var r in e)n=n.replace(new RegExp("{="+r+"}","g"),e[r]);return n}function O(t){var e,n,r,o=this.config,i=function(){var t=n.shift();return t&&e&&y(e)&&t in e?(e=e[t],i()):t?void 0:e};Object.keys(o).forEach((function(c){e=t,n=c.split("_"),r=i(),g(r)&&(o[c]=r)}))}function j(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function w(e){for(var n,r=1;r<arguments.length;r++)n=null!=arguments[r]?arguments[r]:{},r%2?j(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):j(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}));return e}var $=function(t){var r,o;function i(n){var r=t.call(this,n)||this;return r.config=void 0,r.element=void 0,r.config=new c,e(r)||e(r)}o=t,(r=i).prototype=Object.create(o.prototype),r.prototype.constructor=r,n(r,o);var p=i.prototype;return p.$beforeInit=function(){O.call(this,this.options)},p.$init=function(){var t,e=this.config,n=e.class,r=e.selector,o=e.style,i=document.querySelector(r||"."+(n||a));if(!i){var c=this.$$.$el.chart.node();i=document.createElement("table"),c.parentNode.insertBefore(i,c.nextSibling)}if("TABLE"!==i.tagName){var s=document.createElement("table");i.appendChild(s),i=s}if(o&&!document.getElementById(l)){var f=document.createElement("style");f.id=l,f.innerHTML=u,(document.head||document.getElementsByTagName("head")[0]).appendChild(f)}(t=i.classList).add.apply(t,[o&&a,n].filter(Boolean)),this.element=i},p.generateTable=function(){var t=this,e=this.$$,n=this.config,r=this.element,o=e.filterTargetsToShow(e.data.targets),i=m(f,{title:o.length?this.config.categoryTitle:""}),c="",l=[];o.forEach((function(t){i+=m(f,{title:t.id}),t.values.forEach((function(t,e){l[e]||(l[e]=[t.x]),l[e].push(t.value)}))})),l.forEach((function(e){c+="<tr>"+e.map((function(e,r){return m(r?d:b,{value:0===r?n.categoryFormat.bind(t)(e):v(e)?e.toLocaleString():""})})).join("")+"</tr>"}));var a=m(s,w(w({},n),{},{title:n.title||e.config.title_text||"",thead:i,tbody:c})).replace(/<[^>]+><\/[^>]+>/g,"");r.innerHTML=a},p.$redraw=function(){var t=this.$$.state;t.resizing||!this.config.updateOnToggle&&t.toggling||this.generateTable()},p.$willDestroy=function(){if(this.element.parentNode.removeChild(this.element),1===this.$$.charts.length){var t,e=document.getElementById(l);null==e||null==(t=e.parentNode)||t.removeChild(e)}},i}(r)}(),i=i.default}()}));