<template>
</template>
<script>
  import ChartMaker from './factory/gbasechart'
  import AnyChart from './factory/anychart'
  import HighChart from './factory/highchart'
  import EChart from './factory/echart'
  import anychart from 'anychart'
  import jQuery from 'jquery'
  window.$ = window.jQuery = jQuery
  import * as DataCollection from '../static/genreCollection'; 
  export default {
        name : 'Home',

        props:{
        	branch:{
        	 type:String,
        	 default:"AnyChart"
        	},
          genre:{
             type:String,
              default:"column"
          },
          container:{
            type:String,
            default:"container0"
          },
          dataInit:{
            type:Array,
            default:function(){
              return []
            }
          }
        },
    created: function() {
      this.drawChart();
    },


    methods: {

      drawChart:function(){
//var properties = {"title":{"cname":"主标题","name":"title","value":"图形预览1"},
//    "subtitle":{"cname":"副标题","name":"subtitle","value":"subtitle1"}}

        var state =   {"chartInfo":{
                        "chart":
                          {
                          "genre":this.genre.split("_")[0]
                          },
                          "subChart":{
                            "genre":this.genre.split("_")
                          },
                          "data":this.dataInit,
                          //"properties":properties
                        },
                        "container":this.container
                    };

        var defaultBranch = this.branch;
        if(""==defaultBranch){
          defaultBranch = "AnyChart";
        }

        var genreValue = DataCollection.fetchGenre(this.genre);

        if(genreValue){
           if(genreValue instanceof Array){
               if(!genreValue.includes(defaultBranch)){
                  defaultBranch = genreValue[0];
               }
           }else if(genreValue instanceof Object){
               //todo 用于定制化图形
           }

        }else{
          console.log("no such genre name.");
        }
        

        var chart = ChartMaker.factory(defaultBranch);
        //chart.initial(state);
        chart.draw(state);
      }
    }
  }


</script>
