frameworkModule.directive("dashboardDeferredTaxAnalysis", [function () {
    'use strict';

    return {
        restrict: "A",
        templateUrl: "/app/dashboard/deferred-tax-analysis/deferred-tax-analysis.html",
        replace: true,
        scope: true,
        controller: "dashboardDeferredTaxAnalysisController",
        link: function ($scope, $element, $attr) {

            var colourArray = ['#a32020', '#eb8c00', '#db536a', '#dc6900', '#e0301e', '#602320', '#3f3f40', '#968c6d'];

            var pieLegend = ["递延收益", "公允价值变动", "预提性质费用", "预计负债", "折旧 / 摊销", "准备金或减值准备", "特殊事项", "税务亏损", "其他", "未实现内部交易(合并层面)"];

            var chartsContainer = $($element).find(".charts-container");

            // display
            //  1 资产构成
            //  2 负债构成
            //  3 资产/负债变动数分析
            if ($scope.widget.dataModel.chartConfig.display === 1) {
                chartsContainer.css("height", 350);
                var assetStructure = echarts.init(chartsContainer[0], 'vintage');
                assetStructure.setOption({
                    color: colourArray,
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: (assetStructure.getWidth() * 0.55 - assetStructure.getHeight() * 0.5 - 300),
                        data: pieLegend
                    },
                    toolbox: {
                        show: false,
                        feature: {
                            mark: {show: true},
                            dataView: {show: true, readOnly: false},
                            restore: {show: true},
                            saveAsImage: {show: true}
                        }
                    },
                    series: [
                        {
                            name: '期末数',
                            type: 'pie',
                            center: ['55%', '50%'],
                            radius: ['40%', "80%"],
                            itemStyle: {
                                normal: {
                                    label: {
                                        show: true
                                    },
                                    labelLine: {
                                        show: true
                                    }
                                },
                                emphasis: {
                                    label: {
                                        show: true,
                                        position: 'center',
                                        textStyle: {
                                            fontSize: '20',
                                            fontWeight: 'bold'
                                        }
                                    }
                                }
                            },
                            minAngle: 5,
                            data: $scope.assetStructureDEMOData
                        }
                    ]
                });
            }

            if ($scope.widget.dataModel.chartConfig.display === 2) {
                chartsContainer.css("height", 350);
                var taxStructure = echarts.init(chartsContainer[0], 'vintage');
                taxStructure.setOption({
                    color: colourArray,
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: (taxStructure.getWidth() * 0.55 - taxStructure.getHeight() * 0.5 - 300),
                        data: pieLegend
                    },
                    toolbox: {
                        show: false,
                        feature: {
                            mark: {show: true},
                            dataView: {show: true, readOnly: false},
                            restore: {show: true},
                            saveAsImage: {show: true}
                        }
                    },
                    series: [
                        {
                            name: '期末数',
                            type: 'pie',
                            center: ['55%', '50%'],
                            radius: ['40%', "80%"],
                            itemStyle: {
                                normal: {
                                    label: {
                                        show: true
                                    },
                                    labelLine: {
                                        show: true
                                    }
                                },
                                emphasis: {
                                    label: {
                                        show: true,
                                        position: 'center',
                                        textStyle: {
                                            fontSize: '18',
                                            fontWeight: 'bold'
                                        }
                                    }
                                }
                            },
                            minAngle: 5,
                            data: $scope.taxStructureDEMOData
                        }
                    ]
                });
            }

            if ($scope.widget.dataModel.chartConfig.display === 3) {
                chartsContainer.css("height", 600);
                var variationAnalysis = echarts.init(chartsContainer[0], 'vintage');
                variationAnalysis.setOption({
                    color: colourArray,
                    grid: {
                        height: "380px",
                        bottom: "150px"
                    },
                    xAxis: [
                        {
                            axisLabel: {
                                rotate: 60
                            },
                            type: 'category',
                            data: pieLegend
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value',
                            name: '金额',
                            axisLabel: {
                                formatter: '{value}'
                            }
                        }
                    ],
                    series: [
                        {
                            name: 'data',
                            type: 'bar',
                            barWidth: 20,
                            yAxisIndex: 0,
                            itemStyle: {
                                normal: {
                                    label: {
                                        show: true,
                                        position: 'top'
                                    }
                                }
                            },
                            data: $scope.variationAnalysisData
                        }
                    ]
                });
            }
        }
    };
}]);