From d2df89151eb35bf039a140c5548d8cf9410dbc42 Mon Sep 17 00:00:00 2001 From: Adarsh R Date: Tue, 14 Nov 2017 17:33:52 +0530 Subject: [PATCH] Update gauge directive to accept extents function to format min and max labels --- src/controller.js | 9 +++++++++ src/gauge-directive.js | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/controller.js b/src/controller.js index f579335..90cac16 100644 --- a/src/controller.js +++ b/src/controller.js @@ -58,6 +58,7 @@ function ChartController($scope, $timeout) { this.addGauge = addGauge; this.addGaugeLabelFormatFunction = addGaugeLabelFormatFunction; + this.addGaugeLabelExtentsFunction = addGaugeLabelExtentsFunction; this.addBar = addBar; @@ -280,6 +281,10 @@ function ChartController($scope, $timeout) { config.gauge.label = config.gauge.label || {}; config.gauge.label.format = $scope.gaugeLabelFormatFunction; } + if ($scope.gaugeLabelExtentsFunction) { + config.gauge.label = config.gauge.label || {}; + config.gauge.label.extents = $scope.gaugeLabelExtentsFunction; + } if ($scope.point != null) { config.point = $scope.point; } @@ -603,6 +608,10 @@ function ChartController($scope, $timeout) { $scope.gaugeLabelFormatFunction = gaugeLabelFormatFunction; } + function addGaugeLabelExtentsFunction(gaugeLabelExtentsFunction) { + $scope.gaugeLabelExtentsFunction = gaugeLabelExtentsFunction; + } + function addBar(bar) { $scope.bar = bar; } diff --git a/src/gauge-directive.js b/src/gauge-directive.js index 5c5eb91..4521058 100644 --- a/src/gauge-directive.js +++ b/src/gauge-directive.js @@ -74,13 +74,17 @@ function ChartGauge () { if (attrs.labelFormatFunction) { chartCtrl.addGaugeLabelFormatFunction(scope.labelFormatFunction()); } + if (attrs.labelExtentsFunction) { + chartCtrl.addGaugeLabelExtentsFunction(scope.labelExtentsFunction()); + } }; return { require: '^c3chart', restrict: 'E', scope: { - 'labelFormatFunction': "&" + 'labelFormatFunction': "&", + 'labelExtentsFunction': "&" }, replace: true, link: gaugeLinker