app.ng.controller("App.Controller.AsterPlot",
	["$scope", "$rootScope", "$http", "$element", "$location", "$window",
		function ($scope, $rootScope, $http, $element, $location, $window) {
			if ($rootScope.asterPlotChartId != null) {
				$rootScope.asterPlotChartId ++;
			} else {
				$rootScope.asterPlotChartId = 0;
			}
			$scope.asterPlotChartId = $rootScope.asterPlotChartId;
			var data = $scope.chartData;
			drawAsterPlot($($element).find("#asterPlotChart"), data, $scope.chartName, $scope.selectedId, $scope, $location, $window);

		}
	]);
app.ng.controller("App.Controller.BarChart", ["$scope", "$rootScope", "$http", function ($scope, $rootScope, $http) {

    $scope.getData = function () {


        var params = {};
        var url = "/Api/Data/" + $scope.url;
        $http.get(url, { params: params }).success(function (result) {
            $scope.data = result;
            $scope.setTotals();
        });

    }

    $scope.setTotals = function () {
        $scope.totals = {};
        for (var i = 0; i < $scope.data.Series.length; i++) {
            $scope.totals[$scope.data.Series[i]] = getTotal($scope.data.Values[i]);
        }
    }

    var getTotal = function (valueArray) {
        if ($scope.data.Cumulative) {
            return valueArray[valueArray.length - 1];
        }
        else {
            var result = 0;
            for (var i = 0; i < valueArray.length; i++) {
                result += valueArray[i];
            }
            return result;
        }
    }

    if ($scope.url) {
        $scope.getData();
    }
    else if ($scope.chartData) {
        $scope.data = $scope.chartData;
		$scope.data.Labels.forEach(function (label, index) {
			//$scope.data.Labels[index] = label.split(" ")[0];
		});
    }

    if ($scope.interval) {
        $interval($scope.getData, $scope.interval);
	}

	$scope.chartOptions = {
		animationSteps: 20,
		bezierCurveTension: 0.2,
		datasetFill: false,
		autoSkip: false,
		legend: {
			display: true,
			position: 'bottom'
		},
		scales: {
			xAxes: [{
				stacked: false,
				beginAtZero: true,
				ticks: {
					stepSize: 1,
					min: 0,
					autoSkip: false
				}
			}]
		}
	}

}]);
app.ng.controller("App.Controller.Gauge",
	[
		"$scope", "$rootScope", "$http", "$element", function($scope, $rootScope, $http, $element) {

			var gauge = function(container, configuration) {
				var that = {};
				var colors = ["#f38189", "#5ab1ef", "#2ec7c9"];
				var config = {
					size: 710,
					clipWidth: 200,
					clipHeight: 110,
					ringInset: 20,
					ringWidth: 20,

					pointerWidth: 10,
					pointerTailLength: 5,
					pointerHeadLengthPercent: 0.9,

					minValue: 0,
					maxValue: 100,

					minAngle: -90,
					maxAngle: 90,

					transitionMs: 750,

					majorTicks: 3,
					labelFormat: d3.format("d"),
					labelInset: 10
				};
				var range = undefined;
				var r = undefined;
				var pointerHeadLength = undefined;

				var svg = undefined;
				var arc = undefined;
				var scale = undefined;
				var ticks = undefined;
				var tickData = undefined;
				var pointer = undefined;

				d3.pie();

				function deg2rad(deg) {
					return deg * Math.PI / 180;
				}

				function configure(configuration) {
					for (var prop in configuration) {
						if (configuration.hasOwnProperty(prop)) {
							config[prop] = configuration[prop];
						}
					}

					range = config.maxAngle - config.minAngle;
					r = config.size / 2;
					pointerHeadLength = Math.round(r * config.pointerHeadLengthPercent);

					// a linear scale that maps domain values to a percent from 0..1
					scale = d3.scaleLinear()
						.range([0, 1])
						.domain([config.minValue, config.maxValue]);

					ticks = scale.ticks(config.majorTicks);
					tickData = d3.range(config.majorTicks).map(function() { return 1 / config.majorTicks; });

					arc = d3.arc()
						.innerRadius(r - config.ringWidth - config.ringInset)
						.outerRadius(r - config.ringInset)
						.startAngle(function(d, i) {
							var ratio = d * i;
							return deg2rad(config.minAngle + (ratio * range));
						})
						.endAngle(function(d, i) {
							var ratio = d * (i + 1);
							return deg2rad(config.minAngle + (ratio * range));
						});
				}

				that.configure = configure;

				function centerTranslation() {
					return "translate(" + r + "," + r + ")";
				}

				function isRendered() {
					return (svg !== undefined);
				}

				that.isRendered = isRendered;

				function render(newValue) {
					svg = d3.selectAll(container)
						.append("svg:svg")
						.attr("class", "gauge")
						.attr("width", config.clipWidth)
						.attr("height", config.clipHeight);

					var centerTx = centerTranslation();

					var arcs = svg.append("g")
						.attr("class", "arc")
						.attr("transform", centerTx);

					arcs.selectAll("path")
						.data(tickData)
						.enter().append("path")
						.attr("fill",
							function(d, i) {
								return colors[i];
							})
						.attr("d", arc);

					var lg = svg.append("g")
						.attr("class", "label")
						.attr("transform", centerTx);
					lg.selectAll("text")
						.data(ticks)
						.enter().append("text")
						.attr("transform",
							function(d) {
								var ratio = scale(d);
								var newAngle = config.minAngle + (ratio * range);
								return "rotate(" + newAngle + ") translate(0," + (config.labelInset - r) + ")";
							})
						.text(config.labelFormat);

					var lineData = [
						[config.pointerWidth / 2, 0],
						[0, -pointerHeadLength],
						[-(config.pointerWidth / 2), 0],
						[0, config.pointerTailLength],
						[config.pointerWidth / 2, 0]
					];
					var pointerLine = d3.line().curve(d3.curveLinear);
					var pg = svg.append("g").data([lineData])
						.attr("class", "pointer")
						.attr("transform", centerTx);

					pointer = pg.append("path")
						.attr("d", pointerLine /*function(d) { return pointerLine(d) +'Z';}*/)
						.attr("transform", "rotate(" + config.minAngle + ")");

					update(newValue === undefined ? 0 : newValue);
				}

				that.render = render;

				function update(newValue, newConfiguration) {
					if (newConfiguration !== undefined) {
						configure(newConfiguration);
					}
					var ratio = scale(newValue);
					var newAngle = config.minAngle + (ratio * range);
					pointer.transition()
						.duration(config.transitionMs)
						.ease(d3.easeElastic)
						.attr("transform", "rotate(" + newAngle + ")");
				}

				that.update = update;

				configure(configuration);

				return that;
			};


			function drawGauge() {
				var el = $($element).find("#power-gauge");
				var width = el.parent().width();
				var powerGauge = gauge(el,
					{
						size: width,
						clipWidth: width,
						clipHeight: width* 5 /7,
						ringWidth: 60,
						maxValue: 100,
						transitionMs: 4000
					});
				powerGauge.render();
				powerGauge.update($scope.chartValue);

			}

			drawGauge();

		}
	]);
app.ng.controller("App.Controller.LineChart", ["$scope", "$rootScope", "$http",  function ($scope, $rootScope, $http) {

  

    $scope.getData = function () {

        if ($scope.url) {
            var params = {};
            var url = $scope.url;
            $http.get(url, { params: params }).success(function (result) {
                $scope.data = result;
                //  $scope.setTotals();
            });
        }
        else if ($scope.staticKey) {
            $scope.data = window.chartData[$scope.staticKey];
        }
        else if($scope.chartData) {
            $scope.data = $scope.chartData;
        }
    }

    $scope.setTotals = function () {
        $scope.totals = {};
        for (var i = 0; i < $scope.data.Series.length; i++) {
            $scope.totals[$scope.data.Series[i]] = getTotal($scope.data.Values[i]);
        }
    }

    var getTotal = function (valueArray) {
        if ($scope.data.Cumulative) {
            return valueArray[valueArray.length - 1];
        }
        else {
            var result = 0;
            for (var i = 0; i < valueArray.length; i++) {
                result += valueArray[i];
            }
            return result;
        }
    }



    $scope.getData();


}]);
app.ng.controller("App.Controller.LiquidGauge",
	[
		"$scope", "$rootScope", "$http", "$element", function ($scope, $rootScope, $http, $element) {

			(function (d3) {
				var idGenerator = (function () {
					var count = 0;
					return function (prefix) {
						return prefix + "-" + count++;
					};
				})();

				var defaultConfig = {
					// Values
					minValue: 0, // The gauge minimum value.
					maxValue: 100, // The gauge maximum value.

					// Styles
					circleThickness: 0.05, // The outer circle thickness as a percentage of it's radius.
					circleFillGap: 0.05, // The size of the gap between the outer circle and wave circle as a percentage of the outer circles radius.
					circleColor: "#178BCA", // The color of the outer circle.
					backgroundColor: null, // The color of the background
					waveColor: "#178BCA", // The color of the fill wave.
					width: 0, // You might want to set the width and height if it is not detected properly by the plugin
					height: 0,

					// Gradient
					fillWithGradient: false, // Controls if the wave should be filled with gradient
					gradientPoints: [0, 0, 1., 1.], //  [x1, y1, x2, y2], coordinates for gradient start point(x1,y1) and final point(x2,y2)
					gradientFromColor: "#FFF",
					gradientToColor: "#000",

					// Waves
					waveHeight: 0.05, // The wave height as a percentage of the radius of the wave circle.
					waveCount: 1, // The number of full waves per width of the wave circle.
					waveOffset: 0, // The amount to initially offset the wave. 0 = no offset. 1 = offset of one full wave.

					// Animations
					waveRise: true, // Control if the wave should rise from 0 to it's full height, or start at it's full height.
					waveRiseTime: 1000, // The amount of time in milliseconds for the wave to rise from 0 to it's final height.
					waveRiseAtStart: true, // If set to false and waveRise at true, will disable only the initial animation
					waveAnimate: true, // Controls if the wave scrolls or is static.
					waveAnimateTime: 18000, // The amount of time in milliseconds for a full wave to enter the wave circle.
					waveHeightScaling: true, // Controls wave size scaling at low and high fill percentages. When true, wave height reaches it's maximum at 50% fill, and minimum at 0% and 100% fill. This helps to prevent the wave from making the wave circle from appear totally full or empty when near it's minimum or maximum fill.
					valueCountUp: true, // If true, the displayed value counts up from 0 to it's final value upon loading and updating. If false, the final value is displayed.
					valueCountUpAtStart: true, // If set to false and valueCountUp at true, will disable only the initial animation

					// Text
					textVertPosition: 0.5, // The height at which to display the percentage text withing the wave circle. 0 = bottom, 1 = top.
					textSize: 1, // The relative height of the text to display in the wave circle. 1 = 50%
					displayPercent: true, // If true, a % symbol is displayed after the value.
					textColor: "#045681", // The color of the value text when the wave does not overlap it.
					waveTextColor: "#A4DBf8" // The color of the value text when the wave overlaps it.
				};

				d3.liquidfillgauge = function (g, value, settings) {
					// Handle configuration
					var config = d3.map(defaultConfig);
					d3.map(settings).each(function (val, key) {
						config.set(key, val);
					});

					g.each(function (d) {
						var gauge = d3.select(this);
						var width = config.get("width") !== 0 ? config.get("width") : parseInt(gauge.style("width"));
						var height = config.get("height") !== 0 ? config.get("height") : parseInt(gauge.style("height"));
						var radius = Math.min(width, height) / 2;
						var locationX = width / 2 - radius;
						var locationY = height / 2 - radius;
						var fillPercent = Math.max(config.get("minValue"), Math.min(config.get("maxValue"), value)) / config.get("maxValue");

						var waveHeightScale;
						if (config.get("waveHeightScaling")) {
							waveHeightScale = d3.scaleLinear()
								.range([0, config.get("waveHeight"), 0])
								.domain([0, 50, 100]);
						} else {
							waveHeightScale = d3.scaleLinear()
								.range([config.get("waveHeight"), config.get("waveHeight")])
								.domain([0, 100]);
						}

						var textPixels = (config.get("textSize") * radius / 2);
						var textFinalValue = parseFloat(value).toFixed(2);
						var textStartValue = config.get("valueCountUp") ? config.get("minValue") : textFinalValue;
						var percentText = config.get("displayPercent") ? "%" : "";
						var circleThickness = config.get("circleThickness") * radius;
						var circleFillGap = config.get("circleFillGap") * radius;
						var fillCircleMargin = circleThickness + circleFillGap;
						var fillCircleRadius = radius - fillCircleMargin;
						var waveHeight = fillCircleRadius * waveHeightScale(fillPercent * 100);

						var waveLength = fillCircleRadius * 2 / config.get("waveCount");
						var waveClipCount = 1 + config.get("waveCount");
						var waveClipWidth = waveLength * waveClipCount;

						// Rounding functions so that the correct number of decimal places is always displayed as the value counts up.
						var textRounder = function (value) {
							return Math.round(value);
						};
						if (parseFloat(textFinalValue) != parseFloat(textRounder(textFinalValue))) {
							textRounder = function (value) {
								return parseFloat(value).toFixed(1);
							};
						}
						if (parseFloat(textFinalValue) != parseFloat(textRounder(textFinalValue))) {
							textRounder = function (value) {
								return parseFloat(value).toFixed(2);
							};
						}

						// Data for building the clip wave area.
						var data = [];
						for (var i = 0; i <= 40 * waveClipCount; i++) {
							data.push({
								x: i / (40 * waveClipCount),
								y: (i / (40))
							});
						}

						// Scales for drawing the outer circle.
						var gaugeCircleX = d3.scaleLinear().range([0, 2 * Math.PI]).domain([0, 1]);
						var gaugeCircleY = d3.scaleLinear().range([0, radius]).domain([0, radius]);

						// Scales for controlling the size of the clipping path.
						var waveScaleX = d3.scaleLinear().range([0, waveClipWidth]).domain([0, 1]);
						var waveScaleY = d3.scaleLinear().range([0, waveHeight]).domain([0, 1]);

						// Scales for controlling the position of the clipping path.
						var waveRiseScale = d3.scaleLinear()
							// The clipping area size is the height of the fill circle + the wave height, so we position the clip wave
							// such that the it will won't overlap the fill circle at all when at 0%, and will totally cover the fill
							// circle at 100%.
							.range([(fillCircleMargin + fillCircleRadius * 2 + waveHeight), (fillCircleMargin - waveHeight)])
							.domain([0, 1]);
						var waveAnimateScale = d3.scaleLinear()
							.range([0, waveClipWidth - fillCircleRadius * 2]) // Push the clip area one full wave then snap back.
							.domain([0, 1]);

						// Scale for controlling the position of the text within the gauge.
						var textRiseScaleY = d3.scaleLinear()
							.range([fillCircleMargin + fillCircleRadius * 2, (fillCircleMargin + textPixels * 0.7)])
							.domain([0, 1]);

						// Center the gauge within the parent
						var gaugeGroup = gauge.append("g")
							.attr('transform', 'translate(' + locationX + ',' + locationY + ')');

						// Draw the background circle
						if (config.get("backgroundColor")) {
							gaugeGroup.append("circle")
								.attr("r", radius)
								.style("fill", config.get("backgroundColor"))
								.attr('transform', 'translate(' + radius + ',' + radius + ')');
						}

						// Draw the outer circle.
						var gaugeCircleArc = d3.arc()
							.startAngle(gaugeCircleX(0))
							.endAngle(gaugeCircleX(1))
							.outerRadius(gaugeCircleY(radius))
							.innerRadius(gaugeCircleY(radius - circleThickness));
						gaugeGroup.append("path")
							.attr("d", gaugeCircleArc)
							.style("fill", config.get("circleColor"))
							.attr('transform', 'translate(' + radius + ',' + radius + ')');

						// Text where the wave does not overlap.
						var text1 = gaugeGroup.append("text")
							.attr("class", "liquidFillGaugeText")
							.attr("text-anchor", "middle")
							.attr("font-size", textPixels + "px")
							.style("fill", config.get("textColor"))
							.attr('transform', 'translate(' + radius + ',' + textRiseScaleY(config.get("textVertPosition")) + ')');

						// The clipping wave area.
						var clipArea = d3.area()
							.x(function (d) {
								return waveScaleX(d.x);
							})
							.y0(function (d) {
								return waveScaleY(Math.sin(Math.PI * 2 * config.get("waveOffset") * -1 + Math.PI * 2 * (1 - config.get("waveCount")) + d.y * 2 * Math.PI));
							})
							.y1(function (d) {
								return (fillCircleRadius * 2 + waveHeight);
							});

						var gaugeGroupDefs = gaugeGroup.append("defs");

						var clipId = idGenerator("clipWave");
						var waveGroup = gaugeGroupDefs
							.append("clipPath")
							.attr("id", clipId);
						var wave = waveGroup.append("path")
							.datum(data)
							.attr("d", clipArea);

						// The inner circle with the clipping wave attached.
						var fillCircleGroup = gaugeGroup.append("g")
							.attr("clip-path", "url(#" + clipId + ")");
						fillCircleGroup.append("circle")
							.attr("cx", radius)
							.attr("cy", radius)
							.attr("r", fillCircleRadius);

						if (config.get("fillWithGradient")) {
							var points = config.get("gradientPoints");
							var gradientId = idGenerator("linearGradient");
							var grad = gaugeGroupDefs.append("linearGradient")
								.attr("id", gradientId)
								.attr("x1", points[0])
								.attr("y1", points[1])
								.attr("x2", points[2])
								.attr("y2", points[3]);
							grad.append("stop")
								.attr("offset", "0")
								.attr("stop-color", config.get("gradientFromColor"));
							grad.append("stop")
								.attr("offset", "1")
								.attr("stop-color", config.get("gradientToColor"));

							fillCircleGroup.style("fill", "url(#" + gradientId + ")");
						} else {
							fillCircleGroup.style("fill", config.get("waveColor"));
						}

						// Text where the wave does overlap.
						var text2 = fillCircleGroup.append("text")
							.attr("class", "liquidFillGaugeText")
							.attr("text-anchor", "middle")
							.attr("font-size", textPixels + "px")
							.style("fill", config.get("waveTextColor"))
							.attr('transform', 'translate(' + radius + ',' + textRiseScaleY(config.get("textVertPosition")) + ')');

						// Make the wave rise. wave and waveGroup are separate so that horizontal and vertical movement can be controlled independently.
						var waveGroupXPosition = fillCircleMargin + fillCircleRadius * 2 - waveClipWidth;

						if (config.get("waveAnimate")) {
							var animateWave = function () {
								wave.transition()
									.duration(config.get("waveAnimateTime"))
									.ease(d3.easeLinear)
									.attr('transform', 'translate(' + waveAnimateScale(1) + ',0)')
									.on("end", function () {
										wave.attr('transform', 'translate(' + waveAnimateScale(0) + ',0)');
										animateWave();
									});
							};
							animateWave();
						}

						var transition = function (from, to, riseWave, animateText) {
							// Update texts and animate
							if (animateText) {
								var textTween = function () {
									var that = d3.select(this);
									var i = d3.interpolate(from, to);
									return function (t) {
										that.text(textRounder(i(t)) + percentText);
									};
								};
								text1.transition()
									.duration(config.get("waveRiseTime"))
									.tween("text", textTween);
								text2.transition()
									.duration(config.get("waveRiseTime"))
									.tween("text", textTween);
							} else {
								text1.text(textRounder(to) + percentText);
								text2.text(textRounder(to) + percentText);
							}

							// Update the wave
							toPercent = Math.max(config.get("minValue"), Math.min(config.get("maxValue"), to)) / config.get("maxValue");
							fromPercent = Math.max(config.get("minValue"), Math.min(config.get("maxValue"), from)) / config.get("maxValue");

							if (riseWave) {
								waveGroup.attr('transform', 'translate(' + waveGroupXPosition + ',' + waveRiseScale(fromPercent) + ')')
									.transition()
									.duration(config.get("waveRiseTime"))
									.attr('transform', 'translate(' + waveGroupXPosition + ',' + waveRiseScale(toPercent) + ')');
							} else {
								waveGroup.attr('transform', 'translate(' + waveGroupXPosition + ',' + waveRiseScale(toPercent) + ')');
							}
						};

						transition(
							textStartValue,
							textFinalValue,
							config.get("waveRise") && config.get("waveRiseAtStart"),
							config.get("valueCountUp") && config.get("valueCountUpAtStart")
						);

						// Event to update the value
						gauge.on("valueChanged", function (newValue) {
							transition(value, newValue, config.get("waveRise"), config.get("valueCountUp"));
							value = newValue;
						});

						gauge.on("destroy", function () {
							// Stop all the transitions
							text1.interrupt().transition();
							text2.interrupt().transition();
							waveGroup.interrupt().transition();
							wave.interrupt().transition();

							// Unattach events
							gauge.on("valueChanged", null);
							gauge.on("destroy", null);
						});
					});
				};
			})(d3);

			var el = $($element).find("#liquid-gauge");
			var width = el.parent().width();
			var configs = {
				circleThickness: 0.2,
				circleFillGap: 0.2,
				textVertPosition: 0.2,
				waveAnimateTime: 2000,
				valueCountUpAtStart: false,
				waveRiseAtStart: false,
				waveHeight: 0.3,
				waveCount: 1,
				width: width,
				height: width,
				textSize:0.8
			}

			if ($scope.chartValue <= 33) {
				configs.circleColor = "#FF7777";
				configs.textColor = "#FF4444";
				configs.waveTextColor = "#FF4444";
				configs.waveColor = "#FFDDDD";
			} else if ($scope.chartValue > 33 && $scope.chartValue <= 66) {
				configs.circleColor = "#5ab1ef";
				configs.textColor = "#3ea4ec";
				configs.waveTextColor = "#3ea4ec";
				configs.waveColor = "rgb(186, 225, 253)";
			}

			else if ($scope.chartValue > 66) {
				configs.circleColor = "rgb(46, 199, 201)";
				configs.textColor = "rgb(48, 170, 171)";
				configs.waveTextColor = "rgb(48, 170, 171)";
				configs.waveColor = "rgb(179, 246, 247)";
			}

			d3.selectAll(el)
				.attr("width", configs.width)
				.attr("height", configs.height)
				.call(d3.liquidfillgauge, $scope.chartValue, configs);
		}
	]);
app.ng.controller("App.Controller.MiniAsterPlot",
	["$scope", "$rootScope", "$http", "$element", "$location", "$window",
		function ($scope, $rootScope, $http, $element, $location, $window) {
			if ($rootScope.miniAsterPlotChartId != null) {
			    $rootScope.miniAsterPlotChartId++;
			} else {
			    $rootScope.miniAsterPlotChartId = 0;
			}
			$scope.miniAsterPlotChartId = $rootScope.miniAsterPlotChartId;
			var data = $scope.chartData;
			drawMiniAsterPlot($($element).find("#miniAsterPlotChart"), data, $scope.chartName, $scope.selectedId, $scope, $location, $window);

		}
	]);
app.ng.controller("App.Controller.PieChart", ["$scope", "$rootScope", "$http", function ($scope, $rootScope, $http) {

    $scope.getData = function () {
        var params = {};
        var url = "/Api/Data/" + $scope.url;
        $http.get(url, { params: params }).success(function (result) {
            $scope.data = result;
            $scope.setTotals();
        });

    }

    $scope.setTotals = function () {
        $scope.totals = {};
        for (var i = 0; i < $scope.data.Series.length; i++) {
            $scope.totals[$scope.data.Series[i]] = getTotal($scope.data.Values[i]);
        }
    }

    var getTotal = function (valueArray) {
        if ($scope.data.Cumulative) {
            return valueArray[valueArray.length - 1];
        }
        else {
            var result = 0;
            for (var i = 0; i < valueArray.length; i++) {
                result += valueArray[i];
            }
            return result;
        }
    }

    if ($scope.url) {
        $scope.getData();
    }
    else if ($scope.chartData) {
        $scope.data = $scope.chartData;
    }

    if ($scope.interval) {
        $interval($scope.getData, $scope.interval);
	}
	$scope.chartOptions = {
		animationSteps: 10,
		bezierCurveTension: 0.2,
		datasetFill: false,
		legend: { display: true, position: $scope.legendPosition != null ? $scope.legendPosition:"bottom" }
	}

}]);
app.ng.controller("App.Controller.RadarChart", ["$scope", "$rootScope", "$http", function ($scope, $rootScope, $http) {
    $scope.getData = function () {


        var params = {};
        var url = "/Api/Data/" + $scope.url;
        $http.get(url, { params: params }).success(function (result) {
            $scope.data = result;
            $scope.setTotals();
        });

    }

    $scope.setTotals = function () {
        $scope.totals = {};
        for (var i = 0; i < $scope.data.Series.length; i++) {
            $scope.totals[$scope.data.Series[i]] = getTotal($scope.data.Values[i]);
        }
    }

    var getTotal = function (valueArray) {
        if ($scope.data.Cumulative) {
            return valueArray[valueArray.length - 1];
        }
        else {
            var result = 0;
            for (var i = 0; i < valueArray.length; i++) {
                result += valueArray[i];
            }
            return result;
        }
    }

    if ($scope.url) {
        $scope.getData();
    }
    else if ($scope.chartData) {
        $scope.data = $scope.chartData;
        /*$scope.data = {
            Labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
            Values: [
              [65, 59, 90, 81, 56, 55, 40],
              [28, 48, 40, 19, 96, 27, 100]
            ]
        };*/
       
    }

    if ($scope.interval) {
        $interval($scope.getData, $scope.interval);
    }

    
    $scope.theOptions = {
        animationSteps: 20,
        bezierCurveTension: 0.2,
        elements: { line: { fill: false } },
        legend: {
            display: true,
            position: 'bottom'

        },
        scale: {
            ticks: {
                beginAtZero: true,
                max: 100,
				display: false
            }
        }
    }

}]);
