Skip to content

Commit 4f9cabd

Browse files
dtaylor113dgutride
authored andcommitted
pfCharts: Component Conversion (#384)
* pfCharts: component conversion - pfChart, pfDonutPctChart * pfCharts: component conversion - min. unit test fixes * pfCharts: component conversion - refactor donut chart unit test * pfCharts: component conversion - API change! - switch to true Output(s) * pfCharts: component conversion - pfLineChart * pfCharts: component conversion - using $doCheck for deep watching objs. * pfCharts: component conversion - REVERT of API change sha:83d9c63 * pfCharts: component conversion - pfSparklineChart * pfCharts: component conversion - pfTrendsChart * pfCharts: component conversion - pfUtilizationBarChartpfTrendsChart * pfCharts: component conversion - pfUtilizationTrendChart * pfCharts: component conversion - pfHeatmap & pfHeatmapLegend * pfCharts: component conversion - pfEmptyChart * pfCharts: component conversion - udpated charts in cards examples * pfCharts: component conversion - addressed review issues
1 parent b4c5634 commit 4f9cabd

33 files changed

+1618
-1516
lines changed

src/card/basic/card.component.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
<div ng-controller="ChartCtrl">
3737
<label class="label-title">Card With Multiple Utilization Bars</label>
3838
<pf-card head-title="System Resources" show-top-border="true" style="width: 65%">
39-
<div pf-utilization-bar-chart chart-data=data2 chart-title=title2 layout=layoutInline units=units2 threshold-error="85" threshold-warning="60"></div>
40-
<div pf-utilization-bar-chart chart-data=data3 chart-title=title3 layout=layoutInline units=units3 threshold-error="85" threshold-warning="60"></div>
41-
<div pf-utilization-bar-chart chart-data=data4 chart-title=title4 layout=layoutInline units=units4 threshold-error="85" threshold-warning="60"></div>
42-
<div pf-utilization-bar-chart chart-data=data5 chart-title=title5 layout=layoutInline units=units5 threshold-error="85" threshold-warning="60"></div>
39+
<pf-utilization-bar-chart chart-data=data2 chart-title=title2 layout=layoutInline units=units2 threshold-error="85" threshold-warning="60"></pf-utilization-bar-chart>
40+
<pf-utilization-bar-chart chart-data=data3 chart-title=title3 layout=layoutInline units=units3 threshold-error="85" threshold-warning="60"></pf-utilization-bar-chart>
41+
<pf-utilization-bar-chart chart-data=data4 chart-title=title4 layout=layoutInline units=units4 threshold-error="85" threshold-warning="60"></pf-utilization-bar-chart>
42+
<pf-utilization-bar-chart chart-data=data5 chart-title=title5 layout=layoutInline units=units5 threshold-error="85" threshold-warning="60"></pf-utilization-bar-chart>
4343
</pf-card>
4444
</div>
4545
</file>

src/card/examples/card-trend.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
<div ng-controller="ChartCtrl">
3737
<label class="label-title">Card With Single Trend</label>
3838
<pf-card head-title="Cluster Utilization" show-top-border="true" footer="footerConfig" filter="filterConfig" style="width: 50%">
39-
<div pf-trends-chart config="configSingle" chart-data="dataSingle"></div>
39+
<pf-trends-chart config="configSingle" chart-data="dataSingle"></pf-trends-chart>
4040
</pf-card>
4141
<label class="label-title">Card with Multiple Trends</label>
4242
<pf-card head-title="Performance" sub-title="Last 30 Days" show-top-border="false"
4343
show-titles-separator="false" style="width: 65%" footer="actionBarConfig">
44-
<div pf-trends-chart config="configVirtual" chart-data="dataVirtual"></div>
45-
<div pf-trends-chart config="configPhysical" chart-data="dataPhysical"></div>
46-
<div pf-trends-chart config="configMemory" chart-data="dataMemory"></div>
44+
<pf-trends-chart config="configVirtual" chart-data="dataVirtual"></pf-trends-chart>
45+
<pf-trends-chart config="configPhysical" chart-data="dataPhysical"></pf-trends-chart>
46+
<pf-trends-chart config="configMemory" chart-data="dataMemory"></pf-trends-chart>
4747
</pf-card>
4848
</div>
4949
</div>

src/charts/c3/c3-chart.directive.js renamed to src/charts/c3/c3-chart.component.js

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
22
* @ngdoc directive
3-
* @name patternfly.charts.directive:pfC3Chart
3+
* @name patternfly.charts.component:pfC3Chart
4+
* @restrict E
45
*
56
* @description
6-
* Directive for wrapping c3 library
7+
* Component for wrapping c3 library
78
*
89
* Note: The 'patternfly.charts' module is not a dependency in the default angular 'patternfly' module.
910
* In order to use patternfly charts you must add 'patternfly.charts' as a dependency in your application.
@@ -12,13 +13,12 @@
1213
* @param {string} id the ID of the container that the chart should bind to
1314
* @param {expression} config the c3 configuration options for the chart
1415
* @param {function (chart))=} getChartCallback the callback user function to be called once the chart is generated, containing the c3 chart object
15-
*
1616
* @example
1717
1818
<example module="patternfly.charts">
1919
<file name="index.html">
2020
<div ng-controller="ChartCtrl">
21-
<div pf-c3-chart id="chartId" config="chartConfig" get-chart-callback="getChart"></div>
21+
<pf-c3-chart id="chartId" config="chartConfig" get-chart-callback="getChart"></pf-c3-chart>
2222
2323
<form role="form" style="width:300px">
2424
Total = {{total}}, Used = {{used}}, Available = {{available}}
@@ -64,6 +64,7 @@
6464
}
6565
6666
$scope.submitform = function (val) {
67+
console.log("submitform");
6768
$scope.used = val;
6869
$scope.updateAvailable();
6970
$scope.chartConfig.data.columns = [["Used",$scope.used],["Available",$scope.available]];
@@ -75,32 +76,39 @@
7576
(function () {
7677
'use strict';
7778

78-
angular.module('patternfly.charts').directive('pfC3Chart', function ($timeout) {
79-
return {
80-
restrict: 'A',
81-
scope: {
82-
config: '=',
83-
getChartCallback: '='
84-
},
85-
template: '<div id=""></div>',
86-
replace: true,
87-
link: function (scope, element, attrs) {
88-
scope.$watch('config', function () {
89-
$timeout(function () {
90-
// store the chart object
91-
var chart;
92-
//generate c3 chart data
93-
var chartData = scope.config;
94-
if (chartData) {
95-
chartData.bindto = '#' + attrs.id;
96-
chart = c3.generate(chartData);
97-
if (scope.getChartCallback) {
98-
scope.getChartCallback(chart);
99-
}
100-
}
101-
});
102-
}, true);
103-
}
104-
};
79+
angular.module('patternfly.charts').component('pfC3Chart', {
80+
bindings: {
81+
config: '<',
82+
getChartCallback: '<'
83+
},
84+
template: '<div id=""></div>',
85+
controller: function ($timeout, $attrs) {
86+
var ctrl = this, prevConfig;
87+
88+
ctrl.generateChart = function () {
89+
var chart;
90+
var chartData;
91+
92+
// Need to deep watch changes in chart config
93+
prevConfig = angular.copy(ctrl.config);
94+
95+
$timeout(function () {
96+
chartData = ctrl.config;
97+
if (chartData) {
98+
chartData.bindto = '#' + $attrs.id;
99+
chart = c3.generate(chartData);
100+
ctrl.getChartCallback(chart);
101+
prevConfig = angular.copy(ctrl.config);
102+
}
103+
});
104+
};
105+
106+
ctrl.$doCheck = function () {
107+
// do a deep compare on config
108+
if (!angular.equals(ctrl.config, prevConfig)) {
109+
ctrl.generateChart();
110+
}
111+
};
112+
}
105113
});
106114
}());

0 commit comments

Comments
 (0)