UNPKG

backbone-ng2-google-charts

Version:
1 lines 9.22 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@angular/core")):"function"==typeof define&&define.amd?define(["@angular/core"],t):"object"==typeof exports?exports["ng2-google-charts.umd.min"]=t(require("@angular/core")):e["ng2-google-charts.umd.min"]=t(e["@angular/core"])}(this,function(e){return function(e){function t(r){if(o[r])return o[r].exports;var n=o[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,t),n.l=!0,n.exports}var o={};return t.m=e,t.c=o,t.i=function(e){return e},t.d=function(e,o,r){t.o(e,o)||Object.defineProperty(e,o,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(o,"a",o),o},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/",t(t.s=5)}([function(t,o){t.exports=e},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e){this.tooltipDOMElement=e}return e.prototype.setPosition=function(t,o){this.tooltipDOMElement.nativeElement.style.left=t+e.PIXELS,this.tooltipDOMElement.nativeElement.style.top=o+e.PIXELS},e.prototype.getDOMElement=function(){return this.tooltipDOMElement},e}();r.PIXELS="px",t.ChartHTMLTooltip=r},function(e,t,o){"use strict";var r=this&&this.__decorate||function(e,t,o,r){var n,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,o,r);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(a=(i<3?n(a):i>3?n(t,o,a):n(t,o))||a);return i>3&&a&&Object.defineProperty(t,o,a),a},n=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0});var i=o(0),a=o(3),s=o(1),c=function(){function e(e,t){this.el=e,this.loaderService=t,this.chartSelect=new i.EventEmitter,this.chartReady=new i.EventEmitter,this.chartError=new i.EventEmitter,this.mouseOver=new i.EventEmitter,this.eventsLoaded=!1}return e.prototype.ngOnChanges=function(e){var t=this;if(e.data){if(!this.data)return void(this.wrapper=void 0);this.data.destroy&&(this.wrapper=void 0),this.options=this.data.options,this.loaderService.load(this.data.chartType).then(function(){void 0===t.wrapper?t.wrapper=new google.visualization.ChartWrapper(t.data):(t.unregisterChartEvents(),t.wrapper.setDataTable(t.data.dataTable),t.wrapper.setOptions(t.options)),t.eventsLoaded||(t.registerChartWrapperEvents(),t.eventsLoaded=!0),t.wrapper.draw(t.el.nativeElement.querySelector("div"))})}},e.prototype.getSelectorBySeriesType=function(e){return{bars:"bar#%s#%r",haxis:"hAxis#0#label",line:"point#%s#%r",legend:"legendentry#%s"}[e]},e.prototype.getSeriesByColumn=function(e){for(var t=0,o=this.wrapper.getDataTable(),r=e-1;r>=0;r--){var n=o.getColumnRole(r),i=o.getColumnType(r);"data"!==n&&"number"!==i||t++}return t},e.prototype.getBoundingBoxForItem=function(e){var t={top:0,left:0,width:0,height:0};if(this.cli){var o=e.column,r=this.getSeriesByColumn(o),n=(e.row,e.row),i=this.options.seriesType;if(this.options.series&&this.options.series[r]&&this.options.series[r].type&&(i=this.options.series[r].type),i){var a=this.getSelectorBySeriesType(i);if(a){a=a.replace("%s",r+"").replace("%c",o+"").replace("%r",n+"");var s=this.cli.getBoundingBox(a);s&&(t=s)}}}return t},e.prototype.getValueAtPosition=function(e){return this.wrapper.getDataTable().getValue(e.row,e.column)},e.prototype.getColumnTypeAtPosition=function(e){return this.wrapper.getDataTable().getColumnType(e.column)||""},e.prototype.getColumnLabelAtPosition=function(e){return this.wrapper.getDataTable().getColumnLabel(e.column)||""},e.prototype.getHTMLTooltip=function(){var e=new i.ElementRef(this.el.nativeElement.querySelector(".google-visualization-tooltip"));return new s.ChartHTMLTooltip(e)},e.prototype.parseDataPointHoveredEvent=function(e){return{position:e,boundingBox:this.getBoundingBoxForItem(e),value:this.getValueAtPosition(e),tooltip:this.getHTMLTooltip(),columnType:this.getColumnTypeAtPosition(e),columnLabel:this.getColumnLabelAtPosition(e)}},e.prototype.unregisterChartEvents=function(){var e=this.wrapper.getChart();google.visualization.events.removeAllListeners(e)},e.prototype.registerChartEvents=function(){var e=this;if(this.mouseOver.observers.length>0){var t=this.wrapper.getChart();this.cli=t.getChartLayoutInterface(),google.visualization.events.addListener(t,"onmouseover",function(t){var o=e.parseDataPointHoveredEvent(t);e.mouseOver.emit(o)})}},e.prototype.registerChartWrapperEvents=function(){var e=this;google.visualization.events.addListener(this.wrapper,"ready",function(){e.chartReady.emit({message:"Chart ready",chart:e.wrapper}),e.registerChartEvents()}),google.visualization.events.addListener(this.wrapper,"error",function(t){e.chartError.emit(t)}),google.visualization.events.addListener(this.wrapper,"select",function(){var t,o=e.wrapper.visualization.getSelection()[0];if(void 0!==o){var r=[];if(null!==o.row)for(var n=e.wrapper.getDataTable(),i=n.getNumberOfColumns(),a=0;a<i;a++)r.push(n.getValue(o.row,a));s={message:"select",row:o.row,column:o.column},s.selectedRowValues=r,t=s}else t={message:"deselect",row:null,column:null,selectedRowValues:[]};e.chartSelect.emit(t);var s})},e}();r([i.Input(),n("design:type",Object)],c.prototype,"data",void 0),r([i.Output(),n("design:type",i.EventEmitter)],c.prototype,"chartReady",void 0),r([i.Output(),n("design:type",i.EventEmitter)],c.prototype,"chartError",void 0),r([i.Output(),n("design:type",i.EventEmitter)],c.prototype,"chartSelect",void 0),r([i.Output(),n("design:type",i.EventEmitter)],c.prototype,"mouseOver",void 0),c=r([i.Component({selector:"google-chart",template:"<div></div>",changeDetection:i.ChangeDetectionStrategy.OnPush}),n("design:paramtypes",[i.ElementRef,a.GoogleChartsLoaderService])],c),t.GoogleChartComponent=c},function(e,t,o){"use strict";var r=this&&this.__decorate||function(e,t,o,r){var n,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,o,r);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(a=(i<3?n(a):i>3?n(t,o,a):n(t,o))||a);return i>3&&a&&Object.defineProperty(t,o,a),a},n=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0});var i=o(0),a=function(){function e(){this.chartPackage={AnnotationChart:"annotationchart",AreaChart:"corechart",Bar:"bar",BarChart:"corechart",BubbleChart:"corechart",Calendar:"calendar",CandlestickChart:"corechart",ColumnChart:"corechart",ComboChart:"corechart",PieChart:"corechart",Gantt:"gantt",Gauge:"gauge",GeoChart:"geochart",Histogram:"corechart",Line:"line",LineChart:"corechart",Map:"map",OrgChart:"orgchart",Sankey:"sankey",Scatter:"scatter",ScatterChart:"corechart",SteppedAreaChart:"corechart",Table:"table",Timeline:"timeline",TreeMap:"treemap",WordTree:"wordtree"},this.googleScriptLoadingNotifier=new i.EventEmitter,this.googleScriptIsLoading=!1}return e.prototype.load=function(e){var t=this;return new Promise(function(o,r){void 0===o&&(o=Function.prototype),void 0===r&&(r=Function.prototype),t.loadGoogleChartsScript().then(function(){google.charts.load("45",{packages:[t.chartPackage[e]],callback:o})}).catch(function(){console.error("Google charts script could not be loaded")})})},e.prototype.loadGoogleChartsScript=function(){var e=this;return new Promise(function(t,o){if(void 0===t&&(t=Function.prototype),void 0===o&&(o=Function.prototype),"undefined"!=typeof google&&google.charts)t();else if(e.googleScriptIsLoading)e.googleScriptLoadingNotifier.subscribe(function(e){e?t():o()});else{e.googleScriptIsLoading=!0;var r=document.createElement("script");r.type="text/javascript",r.src="https://www.gstatic.com/charts/loader.js",r.async=!0,r.defer=!0,r.onload=function(){e.googleScriptIsLoading=!1,e.googleScriptLoadingNotifier.emit(!0),t()},r.onerror=function(){e.googleScriptIsLoading=!1,e.googleScriptLoadingNotifier.emit(!1),o()},document.getElementsByTagName("head")[0].appendChild(r)}})},e}();a=r([i.Injectable(),n("design:paramtypes",[])],a),t.GoogleChartsLoaderService=a},function(e,t,o){"use strict";var r=this&&this.__decorate||function(e,t,o,r){var n,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,o,r);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(a=(i<3?n(a):i>3?n(t,o,a):n(t,o))||a);return i>3&&a&&Object.defineProperty(t,o,a),a};Object.defineProperty(t,"__esModule",{value:!0});var n=o(0),i=o(2),a=o(3),s=function(){function e(){}return e}();s=r([n.NgModule({declarations:[i.GoogleChartComponent],providers:[a.GoogleChartsLoaderService],exports:[i.GoogleChartComponent]})],s),t.Ng2GoogleChartsModule=s},function(e,t,o){"use strict";function r(e){for(var o in e)t.hasOwnProperty(o)||(t[o]=e[o])}Object.defineProperty(t,"__esModule",{value:!0}),r(o(2));var n=o(1);t.ChartHTMLTooltip=n.ChartHTMLTooltip;var i=o(4);t.Ng2GoogleChartsModule=i.Ng2GoogleChartsModule}])});