UNPKG

14.7 kBJavaScriptView Raw
1/*!
2 * Copyright (c) 2017 ~ present NAVER Corp.
3 * billboard.js project is licensed under the MIT license
4 *
5 * billboard.js, JavaScript chart library
6 * http://naver.github.io/billboard.js/
7 *
8 * @version 1.12.1
9 * @requires billboard.js
10 * @summary billboard.js plugin
11 */
12!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("d3-selection"),require("d3-array"),require("d3-interpolate"),require("d3-color"),require("d3-scale"),require("d3-brush"),require("d3-axis"),require("d3-format")):"function"==typeof define&&define.amd?define("stanford",["d3-selection","d3-array","d3-interpolate","d3-color","d3-scale","d3-brush","d3-axis","d3-format"],e):"object"==typeof exports?exports.stanford=e(require("d3-selection"),require("d3-array"),require("d3-interpolate"),require("d3-color"),require("d3-scale"),require("d3-brush"),require("d3-axis"),require("d3-format")):(t.bb=t.bb||{},t.bb.plugin=t.bb.plugin||{},t.bb.plugin.stanford=e(t.d3,t.d3,t.d3,t.d3,t.d3,t.d3,t.d3,t.d3))}(this,(function(t,e,n,o,r,i,a,c){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=19)}([,function(t,e,n){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}n.d(e,"a",(function(){return o}))},function(t,e,n){"use strict";function o(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function r(t,e,n){return e&&o(t.prototype,e),n&&o(t,n),t}n.d(e,"a",(function(){return r}))},function(t,e,n){"use strict";n.d(e,"a",(function(){return i}));var o=n(4),r=n(5);function i(t,e){return!e||"object"!==Object(o.a)(e)&&"function"!=typeof e?Object(r.a)(t):e}},function(t,e,n){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}n.d(e,"a",(function(){return o}))},function(t,e,n){"use strict";function o(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}n.d(e,"a",(function(){return o}))},function(t,e,n){"use strict";function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}n.d(e,"a",(function(){return o}))},function(t,e,n){"use strict";function o(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}n.d(e,"a",(function(){return o}))},function(e,n){e.exports=t},function(t,e,n){"use strict";n.d(e,"a",(function(){return a}));var o=n(1),r=n(2),i=n(7),a=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};Object(o.a)(this,t),this.options=e}return Object(r.a)(t,[{key:"$beforeInit",value:function(){}},{key:"$init",value:function(){}},{key:"$afterInit",value:function(){}},{key:"$redraw",value:function(){}},{key:"$willDestroy",value:function(){var t=this;Object.keys(this).forEach((function(e){t[e]=null,delete t[e]}))}}]),t}();Object(i.a)(a,"version","1.12.1")},function(t,n){t.exports=e},function(t,e){t.exports=n},function(t,e){t.exports=o},function(t,e){t.exports=r},function(t,e){t.exports=i},function(t,e){t.exports=a},function(t,e){t.exports=c},,,function(t,e,n){"use strict";n.r(e),n.d(e,"default",(function(){return I}));var o=n(1),r=n(2),i=n(3),a=n(6),c=n(5),u=n(22),s=n(10),l=n(11),f=n(12),d=n(13),p="bb-tooltip",h="bb-tooltip-name";var y,b=n(4),g=(n(8),n(14),(y=function(t){return void 0!==t&&t})(self)||y(window)||y(global)||y(globalThis)||Function("return this")()),v=g&&g.document,x=function(t){return"function"==typeof t},m=function(t){return"string"==typeof t},j=function(t){return"number"==typeof t},O=function(t){return"object"===Object(b.a)(t)},S=function(t){return void 0===t||null===t||m(t)&&0===t.length||O(t)&&!(t instanceof Date)&&0===Object.keys(t).length||j(t)&&isNaN(t)},_=function(t){return t&&t.constructor===Array},w=function(t){return t&&!t.nodeType&&O(t)&&!_(t)},k=function(t){function e(){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];if(!n.length||1===n.length&&!n[0])return t;var r=n.shift();return w(t)&&w(r)&&Object.keys(r).forEach((function(e){var n=r[e];w(n)?(!t[e]&&(t[e]={}),t[e]=k(t[e],n)):t[e]=_(n)?n.concat():n})),k.apply(void 0,[t].concat(n))})),$=(function(){try{new MouseEvent("t")}catch(t){return function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{bubbles:!1,cancelable:!1,screenX:0,screenY:0,clientX:0,clientY:0},o=v.createEvent("MouseEvent");o.initMouseEvent(e,n.bubbles,n.cancelable,g,0,n.screenX,n.screenY,n.clientX,n.clientY,!1,!1,!1,!1,0,null),t.dispatchEvent(o)}}}(),n(9)),E=function t(){return Object(o.a)(this,t),{colors:void 0,epochs:[],lines:[],scale_min:void 0,scale_max:void 0,scale_width:20,scale_format:void 0,padding_top:0,padding_right:0,padding_bottom:0,padding_left:0,regions:[]}},C="bb-colorscale",M="bb-stanford-elements",q="bb-stanford-line",P="bb-stanford-lines",T="bb-stanford-region",D="bb-stanford-regions";function F(t,e){return t.epochs<e.epochs?-1:t.epochs>e.epochs?1:0}function N(t){for(var e,n=function(t){for(var e,n,o=0,r=0,i=t.length,a=i-1;r<i;a=r,r++)e=t[r],n=t[a],o+=e.x*n.y,o-=e.y*n.x;return o/=2}(t),o=0,r=0,i=0,a=t.length,c=a-1;i<a;c=i,i++){var u=t[i],s=t[c];e=u.x*s.y-s.x*u.y,o+=(u.x+s.x)*e,r+=(u.y+s.y)*e}return{x:o/(e=6*n),y:r/e}}var R=function(){function t(e){Object(o.a)(this,t),this.owner=e;var n=e.$$.main.select(".bb-chart").append("g").attr("class",M);n.append("g").attr("class",P),n.append("g").attr("class",D)}return Object(r.a)(t,[{key:"updateStanfordLines",value:function(t){var e=this.owner.$$,n=e.main,o=e.config.axis_rotated,r=this.xvCustom.bind(e),i=this.yvCustom.bind(e),a=n.select(".".concat(P)).style("shape-rendering","geometricprecision").selectAll(".".concat(q)).data(this.owner.config.lines);a.exit().transition().duration(t).style("opacity","0").remove();var c=a.enter().append("g");c.append("line").style("opacity","0"),c.merge(a).attr("class",(function(t){return q+(t.class?" ".concat(t.class):"")})).select("line").transition().duration(t).attr("x1",(function(t){return o?i(t,"y1"):r(t,"x1")})).attr("x2",(function(t){return o?i(t,"y2"):r(t,"x2")})).attr("y1",(function(t){return o?r(t,"x1"):i(t,"y1")})).attr("y2",(function(t){return o?r(t,"x2"):i(t,"y2")})).transition().style("opacity","1")}},{key:"updateStanfordRegions",value:function(t){var e=this.owner.$$,n=e.main,o=e.config.axis_rotated,r=this.xvCustom.bind(e),i=this.yvCustom.bind(e),a=this.owner.countEpochsInRegion.bind(e),c=n.select(".".concat(D)).selectAll(".".concat(T)).data(this.owner.config.regions);c.exit().transition().duration(t).style("opacity","0").remove();var u=c.enter().append("g");u.append("polygon").style("opacity","0"),u.append("text").attr("transform",o?"rotate(-90)":"").style("opacity","0"),(c=u.merge(c)).attr("class",(function(t){return T+(t.class?" ".concat(t.class):"")})).select("polygon").transition().duration(t).attr("points",(function(t){return t.points.map((function(t){return[o?i(t,"y"):r(t,"x"),o?r(t,"x"):i(t,"y")].join(",")})).join(" ")})).transition().style("opacity",(function(t){return(t.opacity?t.opacity:.2)+""})),c.select("text").transition().duration(t).attr("x",(function(t){return o?i(N(t.points),"y"):r(N(t.points),"x")})).attr("y",(function(t){return o?r(N(t.points),"x"):i(N(t.points),"y")})).text((function(t){if(t.text){var e=a(t.points),n=e.value,o=e.percentage;return t.text(n,o)}return""})).attr("text-anchor","middle").attr("dominant-baseline","middle").transition().style("opacity","1")}},{key:"updateStanfordElements",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.updateStanfordLines(t),this.updateStanfordRegions(t)}},{key:"xvCustom",value:function(t,e){var n=this,o=e?t[e]:n.getBaseValue(t);return n.isTimeSeries()?o=n.parseDate(o):n.isCategorized()&&m(o)&&(o=n.config.axis_x_categories.indexOf(t.value)),Math.ceil(n.x(o))}},{key:"yvCustom",value:function(t,e){var n=t.axis&&"y2"===t.axis?this.y2:this.y,o=e?t[e]:this.getBaseValue(t);return Math.ceil(n(o))}}]),t}(),L=n(15),A=n(16),B=function(){function t(e){Object(o.a)(this,t),this.owner=e}return Object(r.a)(t,[{key:"drawColorScale",value:function(){var t=this.owner.$$,e=this.owner.config,n=t.data.targets[0],o=t.height-e.padding_bottom-e.padding_top,r=e.scale_width,i=Object(s.range)(e.padding_bottom,o,5),a=Object(d.scaleSequential)(n.colors).domain([i[i.length-1],i[0]]);this.colorScale&&this.colorScale.remove(),this.colorScale=t.svg.append("g").attr("width",50).attr("height",o).attr("class",C),this.colorScale.append("g").attr("transform","translate(0, ".concat(e.padding_top,")")).selectAll("bars").data(i).enter().append("rect").attr("y",(function(t,e){return 5*e})).attr("x",0).attr("width",r).attr("height",5).attr("fill",(function(t){return a(t)}));var c=Object(d.scaleLog)().domain([n.minEpochs,n.maxEpochs]).range([i[0]+e.padding_top+i[i.length-1]+5-1,i[0]+e.padding_top]),u=Object(L.axisRight)(c),l=e.scale_format;"pow10"===l?u.tickValues([1,10,100,1e3,1e4,1e5,1e6,1e7]):x(l)?u.tickFormat(l):u.tickFormat(Object(A.format)("d"));var f=this.colorScale.append("g").attr("class","legend axis").attr("transform","translate(".concat(r,",0)")).call(u);"pow10"===l&&f.selectAll(".tick text").text(null).filter((function(t){return t/Math.pow(10,Math.ceil(Math.log(t)/Math.LN10-1e-12))==1})).text(10).append("tspan").attr("dy","-.7em").text((function(t){return Math.round(Math.log(t)/Math.LN10)})),this.colorScale.attr("transform","translate(".concat(t.currentWidth-this.xForColorScale(),", 0)"))}},{key:"xForColorScale",value:function(){return this.owner.config.padding_right+this.colorScale.node().getBBox().width}},{key:"getColorScalePadding",value:function(){return this.xForColorScale()+this.owner.config.padding_left+20}}]),t}(),I=function(t){function e(t){var n;return Object(o.a)(this,e),(n=Object(i.a)(this,Object(a.a)(e).call(this,t))).config=new E,Object(i.a)(n,Object(c.a)(n))}return Object(u.a)(e,t),Object(r.a)(e,[{key:"$beforeInit",value:function(){var t=this,e=this.$$;e.config.data_xSort=!1,e.isMultipleX=function(){return!0},e.showGridFocus=function(){},e.labelishData=function(t){return t.values},e.opacityForCircle=function(){return 1};var n=e.getCurrentPaddingRight.bind(e);e.getCurrentPaddingRight=function(){return n()+(t.colorScale?t.colorScale.getColorScalePadding():0)}}},{key:"$init",value:function(){var t=this.$$;t.loadConfig.bind(this)(this.options),t.color=this.getStanfordPointColor.bind(t),this.colorScale=new B(this),this.elements=new R(this),this.convertData(),this.initStanfordData(),this.setStanfordTooltip(),this.colorScale.drawColorScale(),this.$redraw()}},{key:"$redraw",value:function(t){this.colorScale&&this.colorScale.drawColorScale(),this.elements&&this.elements.updateStanfordElements(t)}},{key:"getOptions",value:function(){return new E}},{key:"convertData",value:function(){var t=this.$$.data.targets,e=this.options.epochs;t.forEach((function(t){t.values.forEach((function(t,n){t.epochs=e[n]})),t.minEpochs=void 0,t.maxEpochs=void 0,t.colors=void 0,t.colorscale=void 0}))}},{key:"xvCustom",value:function(t,e){var n=this,o=e?t[e]:n.getBaseValue(t);return n.isTimeSeries()?o=n.parseDate(o):n.isCategorized()&&m(o)&&(o=n.config.axis_x_categories.indexOf(t.value)),Math.ceil(n.x(o))}},{key:"yvCustom",value:function(t,e){var n=t.axis&&"y2"===t.axis?this.y2:this.y,o=e?t[e]:this.getBaseValue(t);return Math.ceil(n(o))}},{key:"initStanfordData",value:function(){var t=this.config,e=this.$$.data.targets[0];e.values.sort(F);var n=e.values.map((function(t){return t.epochs}));e.minEpochs=isNaN(t.scale_min)?Object(s.min)(n):t.scale_min,e.maxEpochs=isNaN(t.scale_max)?Object(s.max)(n):t.scale_max,e.colors=x(t.colors)?t.colors:Object(l.interpolateHslLong)(Object(f.hsl)(250,1,.5),Object(f.hsl)(0,1,.5)),e.colorscale=Object(d.scaleSequentialLog)(e.colors).domain([e.minEpochs,e.maxEpochs])}},{key:"getStanfordPointColor",value:function(t){return this.data.targets[0].colorscale(t.epochs)}},{key:"setStanfordTooltip",value:function(){var t=this.$$.config;S(t.tooltip_contents)&&(t.tooltip_contents=function(t,e,n,o){var r=this,i='<table class="'.concat(p,'"><tbody>');return t.forEach((function(t){i+="<tr>\n\t\t\t\t\t\t\t<th>".concat(e(r.config.data_x),'</th>\n\t\t\t\t\t\t\t<th class="value">').concat(n(t.x),"</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th>").concat(e(t.id),'</th>\n\t\t\t\t\t\t\t<th class="value">').concat(n(t.value),'</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class="').concat(h,"-").concat(t.id,'">\n\t\t\t\t\t\t\t<td class="name"><span style="background-color:').concat(o(t),'"></span>').concat(e("Epochs"),'</td>\n\t\t\t\t\t\t\t<td class="value">').concat(n(t.epochs),"</td>\n\t\t\t\t\t\t</tr>")})),"".concat(i,"</tbody></table>")})}},{key:"countEpochsInRegion",value:function(t){var e=this.data.targets[0],n=e.values.reduce((function(t,e){return t+ +e.epochs}),0),o=e.values.reduce((function(e,n){return function(t,e){for(var n=t.x,o=t.value,r=!1,i=0,a=e.length-1;i<e.length;a=i++){var c=e[i].x,u=e[i].y,s=e[a].x,l=e[a].y;u>o!=l>o&&n<(s-c)*(o-u)/(l-u)+c&&(r=!r)}return r}(n,t)?e+ +n.epochs:e}),0);return{value:o,percentage:0===o?0:+(o/n*100).toFixed(1)}}}]),e}($.a)},,,function(t,e,n){"use strict";function o(t,e){return(o=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&o(t,e)}n.d(e,"a",(function(){return r}))}]).default}));
\No newline at end of file