From cf4c16c2a0feede78b205dbf533b2172413087dd Mon Sep 17 00:00:00 2001 From: CD Cabrera Date: Thu, 27 Jul 2017 17:34:47 -0400 Subject: [PATCH] feat(chart): Utilization Donut Chart Component Enhancement for utilization donut chart component --- src/charts/donut/donut-pct-chart-component.js | 11 +- src/charts/donut/donut-pct-chart.html | 25 +++- src/charts/donut/examples/donut-pct-chart.js | 138 ++++++++++++++++-- test/charts/donut/donut-pct.spec.js | 16 +- 4 files changed, 170 insertions(+), 20 deletions(-) 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 + *
      + *
    • .orientation - string with possible values: 'left', 'right' (optional) - default: 'center' + *
    • .title - string representing a prefix or title (optional) - default: empty string + *
    • .label - the wording format to display, possible values: 'used', 'available', 'percent', 'none' (optional) - default: 'used' + *
    • .units - unit label for values, ex: 'MHz','GB', etc.. (optional) - default: empty string + *
    • .labelFn - function to customize the text of the external label. This callback returns no data. Updated display data can be accessed through the passed and updated parameter 'data'. (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 @@
    -
    +