UNPKG

vue-chart-engine

Version:

chart components built with Vue.js

125 lines (103 loc) 3.75 kB
export default class GenreMaker { constructor(state) { this.chart = null; this.data = null; this.is3D = state.is3D; this.isSeries = state.chartInfo.subChart.isSeries; this.subGenre = state.chartInfo.subChart.genre; this.genre = state.chartInfo.chart.genre; } static factory(type,state) { return new GenreMaker[type](state); } ifSeries(){ //return state.chartInfo.subChart.isSeries; return this.isSeries; } getGenre(){ return this.genre; } getSubGenre(state){ //return state.chartInfo.subChart.genre; return this.subGenre; } ifIncluded(type){ return this.subGenre.includes(type); } isBasic(){ return this.subGenre.includes("basic"); } setData(state){ var genre = this.getGenre(state); var subGenre = this.getSubGenre(state); var dataInit = state.chartInfo.data; // if(this.genre=="bubble"){ // if(this.isSeries){ // var data1 = anychart.data.set(totalData.bubble1); // var data2 = anychart.data.set(totalData.bubble2); // data = [data1,data2]; // }else{ // data = totalData.bubble1; // } // }else var data = []; if(this.genre=="heatmap"){ //if(dataInit[0]){ //var dataSet = anychart.data.set(dataInit[num]); var dataSet = anychart.data.set(dataInit); data = dataSet.mapAs({x: [0], y: [1],heat:[2]}); //} }else if(this.genre=="marker"){ for(var num=0;num<dataInit.length;num++){ var dataSet = anychart.data.set(dataInit[num]); data[num] = dataSet.mapAs({x: 0, value: 1}); } }else if(this.genre.indexOf("range")!=-1){ data = totalData.rangeData; }else if(this.genre=="pyramid"){ var dataSet = anychart.data.set(dataInit); data = dataSet.mapAs({name: 0, value: 1}); }else if(this.ifIncluded("bubble")){ for(var num=0;num<dataInit.length;num++){ var dataSet = anychart.data.set(dataInit[num]); data[num] = dataSet.mapAs({x: 0, value: 1,size:2}); } }else{ // switch(isSeries){ // case "simple": // data = totalData.normalData; // break; // case "stacked": // case "percent_stacked": // case "series": // var seriesData = anychart.data.set(totalData.stackedData); // var seriesData_1 = seriesData.mapAs({x: 0, value: 1}); // var seriesData_2 = seriesData.mapAs({x: 0, value: 2}); // var seriesData_3 = seriesData.mapAs({x: 0, value: 3}); // data = [seriesData_1,seriesData_2,seriesData_3]; // break; // default: var dataSet = anychart.data.set(dataInit); if(dataInit[0]){ for(var num=0;num<dataInit[0].length-1;num++){ data[num] = dataSet.mapAs({x: 0, value: num+1}); } } } this.data = data; } getChart(state){ var subGenre = state.chartInfo.subChart.genre; var chart = this.createChart(); if(this.ifIncluded("stacked")){ // this.getSeriesChart(chart,data); if(subGenre.indexOf("percent")!=-1){ chart.yScale().stackMode("percent"); }else if(subGenre.indexOf("stacked")!=-1){ chart.yScale().stackMode("value"); } } this.chart = chart; return chart; }; }