abbott_2024_event/bin/app.publish/BackEnd/assets/javascript/pages/chartjs-bar-demo.min.js

3 lines
7.5 KiB
JavaScript

"use strict";function _classCallCheck(a,t){if(!(a instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(a,r.key,r)}}function _createClass(a,t,o){return t&&_defineProperties(a.prototype,t),o&&_defineProperties(a,o),a}var ChartjsBarDemo=function(){function a(){_classCallCheck(this,a),this.init()}return _createClass(a,[{key:"init",value:function(){this.barChart(),this.barHorizontal(),this.barStacked(),this.barStackedGroup(),this.barMultiAxis()}},{key:"colors",value:function(){return{red:"#B76BA3",orange:"#EC935E",yellow:"#F7C46C",green:"#A7C796",teal:"#00A28A",blue:"#346CB0",purple:"#5F4B8B",gray:"#BEC1C4"}}},{key:"colorBrandNames",value:function(){return Object.keys(Looper.getColors("brand"))}},{key:"randomScalingFactor",value:function(){return(.5<Math.random()?1:-1)*Math.round(100*Math.random())}},{key:"months",value:function(){return["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}},{key:"barChart",value:function(){var r=this,n={labels:["Jan","Feb","Mar","Apr","May","Jun","Jul"],datasets:[{label:"Dataset 1",backgroundColor:Looper.colors.brand.purple,borderColor:Looper.colors.brand.purple,borderWidth:1,data:[this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor()]},{label:"Dataset 2",backgroundColor:Looper.colors.brand.teal,borderColor:Looper.colors.brand.teal,borderWidth:1,data:[this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor()]}]},a=$("#canvas-bar")[0].getContext("2d"),e=new Chart(a,{type:"bar",data:n,options:{title:{display:!0,text:"Bar Chart"},scales:{xAxes:[{ticks:{maxRotation:0,maxTicksLimit:5}}]}}});$("#randomizeData").on("click",function(a){a.preventDefault();var t=Math.random()<.2;n.datasets.forEach(function(a){a.data=a.data.map(function(){return t?0:r.randomScalingFactor()})}),e.update()}),$("#addData").on("click",function(a){if(a.preventDefault(),0<n.datasets.length){var t=r.months()[n.labels.length%r.months().length];n.labels.push(t);for(var o=0;o<n.datasets.length;++o)n.datasets[o].data.push(r.randomScalingFactor());e.update()}}),$("#removeData").on("click",function(a){a.preventDefault(),n.labels.splice(-1,1),n.datasets.forEach(function(a,t){a.data.pop()}),e.update()})}},{key:"barHorizontal",value:function(){var c=this,i={labels:["Jan","Feb","Mar","Apr","May","Jun","Jul"],datasets:[{label:"Dataset 1",backgroundColor:Looper.colors.brand.purple,borderColor:Looper.colors.brand.purple,borderWidth:1,data:[this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor()]},{label:"Dataset 2",backgroundColor:Looper.colors.brand.teal,borderColor:Looper.colors.brand.teal,data:[this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor()]}]},a=$("#canvas-horizontal-bar")[0].getContext("2d"),l=new Chart(a,{type:"horizontalBar",data:i,options:{elements:{rectangle:{borderWidth:2}},title:{display:!0,text:"Horizontal Bar Chart"}}});$("#randomizeDataHorizontalBar").on("click",function(a){a.preventDefault();var t=Math.random()<.2;i.datasets.forEach(function(a){a.data=a.data.map(function(){return t?0:c.randomScalingFactor()})}),l.update()}),$("#addDatasetHorizontalBar").on("click",function(a){if(a.preventDefault(),i.datasets.length<=6){for(var t=c.colorBrandNames(),o=t[i.datasets.length%t.length],r=Looper.getColors("brand")[o],n={label:"Dataset "+i.datasets.length,backgroundColor:r,borderColor:r,data:[]},e=0;e<i.labels.length;++e)n.data.push(c.randomScalingFactor());i.datasets.push(n),l.update()}}),$("#removeDatasetHorizontalBar").on("click",function(){i.datasets.splice(0,1),l.update()})}},{key:"barStacked",value:function(){var a={labels:["Jan","Feb","Mar","Apr","May","Jun","Jul"],datasets:[{label:"Dataset 1",backgroundColor:Looper.colors.brand.blue,data:[this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor()]},{label:"Dataset 2",backgroundColor:Looper.colors.brand.teal,data:[this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor()]},{label:"Dataset 3",backgroundColor:Looper.colors.brand.purple,data:[this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor()]}]},t=$("#canvas-stacked")[0].getContext("2d");new Chart(t,{type:"bar",data:a,options:{title:{display:!0,text:"Stacked"},tooltips:{mode:"index",intersect:!1},scales:{xAxes:[{stacked:!0}],yAxes:[{stacked:!0}]}}})}},{key:"barStackedGroup",value:function(){var a={labels:["Jan","Feb","Mar","Apr","May","Jun","Jul"],datasets:[{label:"Dataset 1",backgroundColor:Looper.colors.brand.purple,stack:"Stack 0",data:[this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor()]},{label:"Dataset 2",backgroundColor:Looper.colors.brand.teal,stack:"Stack 0",data:[this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor()]},{label:"Dataset 3",backgroundColor:Looper.colors.brand.teal,stack:"Stack 1",data:[this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor()]}]},t=$("#canvas-stacked-group")[0].getContext("2d");new Chart(t,{type:"bar",data:a,options:{title:{display:!0,text:"Stacked Group"},tooltips:{mode:"index",intersect:!1},scales:{xAxes:[{stacked:!0}],yAxes:[{stacked:!0}]}}})}},{key:"barMultiAxis",value:function(){var a={labels:["Jan","Feb","Mar","Apr","May","Jun","Jul"],datasets:[{label:"Dataset 1",backgroundColor:[Looper.colors.brand.purple,Looper.colors.brand.orange,Looper.colors.brand.green,Looper.colors.brand.teal,Looper.colors.brand.blue,Looper.colors.brand.pink,Looper.colors.brand.red],yAxisID:"y-axis-1",data:[this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor()]},{label:"Dataset 2",backgroundColor:Looper.colors.gray[400],yAxisID:"y-axis-2",data:[this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor(),this.randomScalingFactor()]}]},t=$("#canvas-multi-axis")[0].getContext("2d");new Chart(t,{type:"bar",data:a,options:{title:{display:!0,text:"Multi Axis"},tooltips:{mode:"index",intersect:!0},scales:{yAxes:[{type:"linear",display:!0,position:"left",id:"y-axis-1"},{type:"linear",display:!0,position:"right",id:"y-axis-2",gridLines:{drawOnChartArea:!1}}]}}})}}]),a}();$(document).on("theme:init",function(){new ChartjsBarDemo});
//# sourceMappingURL=../../sourcemaps/pages/chartjs-bar-demo.min.js.map