diff --git a/src/charts/donut/donut-pct-chart-component.js b/src/charts/donut/donut-pct-chart-component.js index a9a54eb4d..3b7aff881 100644 --- a/src/charts/donut/donut-pct-chart-component.js +++ b/src/charts/donut/donut-pct-chart-component.js @@ -7,12 +7,14 @@ angular.module('patternfly.charts').component('pfDonutPctChart', { onThresholdChange: '&' }, templateUrl: 'charts/donut/donut-pct-chart.html', - controller: function (pfUtils, $element, $timeout) { + controller: function (pfUtils, $scope) { 'use strict'; var ctrl = this, prevData; + ctrl.$id = $scope.$id; ctrl.$onInit = function () { - ctrl.donutChartId = 'donutPctChart'; + ctrl.donutChartId = 'donutPctChart' + ctrl.$id; + if (ctrl.config.chartId) { ctrl.donutChartId = ctrl.config.chartId + ctrl.donutChartId; } @@ -24,6 +26,10 @@ angular.module('patternfly.charts').component('pfDonutPctChart', { ctrl.data.available = ctrl.data.total - ctrl.data.used; }; + ctrl.updatePercentage = function () { + ctrl.data.percent = Math.round(ctrl.data.used / ctrl.data.total * 100.0); + }; + ctrl.getStatusColor = function (used, thresholds) { var threshold = "none"; var color = pfUtils.colorPalette.blue; @@ -127,6 +133,7 @@ angular.module('patternfly.charts').component('pfDonutPctChart', { ctrl.config = pfUtils.merge(patternfly.c3ChartDefaults().getDefaultDonutConfig(), ctrl.config); ctrl.updateAvailable(); + ctrl.updatePercentage(); ctrl.config.data = pfUtils.merge(ctrl.config.data, ctrl.getDonutData()); ctrl.config.color = ctrl.statusDonutColor(ctrl); ctrl.config.tooltip = ctrl.donutTooltip(); diff --git a/src/charts/donut/donut-pct-chart.html b/src/charts/donut/donut-pct-chart.html index 7c1aef3f3..c3da22e02 100644 --- a/src/charts/donut/donut-pct-chart.html +++ b/src/charts/donut/donut-pct-chart.html @@ -1,5 +1,22 @@ - - - + + + + + + + + {{$ctrl.config.labelConfig.title}} + + + {{$ctrl.data.available}} {{$ctrl.config.labelConfig.units}} available + {{$ctrl.data.percent}}% used + {{$ctrl.data.used}} {{$ctrl.config.labelConfig.units}} of {{$ctrl.data.total}} {{$ctrl.config.labelConfig.units}} used + + + + + + diff --git a/src/charts/donut/examples/donut-pct-chart.js b/src/charts/donut/examples/donut-pct-chart.js index 9f0df7f84..7deb0876d 100644 --- a/src/charts/donut/examples/donut-pct-chart.js +++ b/src/charts/donut/examples/donut-pct-chart.js @@ -26,11 +26,21 @@ *
  • .tooltipFn(d) - user defined function to customize the tool tip (optional) *
  • .centerLabelFn - user defined function to customize the text of the center label (optional) *
  • .onClickFn(d,i) - user defined function to handle when donut arc is clicked upon. + *
  • .labelConfig - object containing properties for external label (optional) - default: undefined + * + *
  • * * * @param {object} data the Total and Used values for the donut chart. Available is calculated as Total - Used.
    * @@ -62,19 +72,23 @@
    - +

    + +

    -
    +
    -
    +
    - - +

    + + +

    -
    +
    @@ -88,20 +102,45 @@
    - +
    - +
    - +
    + - +
    +
    + +
    +
    +
    +
    +
    + +
    +
    + +

    + +

    +
    +
    + + +
    +
    + +

    + +

    @@ -120,7 +159,7 @@
    -
    +