Moved charts to directive

This commit is contained in:
2017-03-18 12:13:25 +05:30
parent 875e71b12d
commit d5342afc86
9 changed files with 463 additions and 98 deletions
+2 -36
View File
@@ -1,4 +1,4 @@
var app = angular.module("chart-builder",["ngDrag","chart-builder.filters"]);
var app = angular.module("chart-builder",["ngDrag","chart-builder.filters","chart-builder.directives"]);
app.value("allData",{
"values":{
@@ -41,19 +41,14 @@ app.value("allData",{
"measures": ["Sales","Orders","Revenue"]
});
app.value("chartTypes",["column","bar","pie"]);
app.controller("mainController", ["allData","chartTypes","$scope",function (allData,chartTypes,$scope) {
app.controller("mainController", ["allData","$scope",function (allData,$scope) {
$scope.data = {};
$scope.data.chooserDimensions = allData.dimensions;
$scope.data.chosenDimension = undefined;
$scope.data.chooserMeasures = allData.measures;
$scope.data.chosenMeasure = undefined;
$scope.chartTypes = chartTypes;
$scope.chartTypeChosen = chartTypes[0];
$scope.data.values = allData.values;
$scope.allowDrop = function(ev,location) {
@@ -133,33 +128,4 @@ app.controller("mainController", ["allData","chartTypes","$scope",function (allD
}
}
$scope.$watchGroup(["data.values","data.chosenDimension","data.chosenMeasure","chartTypeChosen"],function(){
if ($scope.data.chosenMeasure && $scope.data.chosenDimension){
var tmpData = $scope.data.values[$scope.data.chosenDimension][$scope.data.chosenMeasure];
var chartData = [];
var keys = Object.keys(tmpData);
var axisLabel;
if ($scope.chartTypeChosen.toLowerCase() === "bar")
{
for (var i = keys.length - 1; i >= 0; i--) {
chartData.push({"y":keys[i],"x":tmpData[keys[i]]});
}
axisLabel = [$scope.data.chosenMeasure,$scope.data.chosenDimension];
}
else
{
for (var i = keys.length - 1; i >= 0; i--) {
chartData.push({"x":keys[i],"y":tmpData[keys[i]]});
}
axisLabel = [$scope.data.chosenDimension,$scope.data.chosenMeasure];
}
drawChart($scope.chartTypeChosen,chartData,axisLabel);
}
else
{
cleanChart();
}
});
}]);