Skip to content

Commit 17620fb

Browse files
committed
Merge pull request #205 from ammendonca/PTNFLY-204
Add callback param for accessing C3Chart object
2 parents 5ad6de2 + 3dc2e17 commit 17620fb

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

dist/angular-patternfly.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,21 +588,23 @@ angular.module('patternfly.card').directive('pfCard', function () {
588588
*
589589
* @param {string} id the ID of the container that the chart should bind to
590590
* @param {expression} config the c3 configuration options for the chart
591+
* @param {function (chart))=} getChartCallback the callback user function to be called once the chart is generated, containing the c3 chart object
591592
*
592593
* @example
593594
594595
<example module="patternfly.charts">
595596
<file name="index.html">
596597
<div ng-controller="ChartCtrl">
597-
<div pf-c3-chart id="chartId" config="chartConfig"></div>
598+
<div pf-c3-chart id="chartId" config="chartConfig" get-chart-callback="getChart"></div>
598599
599600
<form role="form" style="width:300px">
600601
Total = {{total}}, Used = {{used}}, Available = {{available}}
601602
<div class="form-group">
602603
<label>Used</label>
603604
<input type="text" class="form-control" ng-model="newUsed">
604605
</div>
605-
<input type="button" ng-click="submitform(newUsed)" value="Go" />
606+
<input type="button" ng-click="submitform(newUsed)" value="Set Used" />
607+
<input type="button" ng-click="focusUsed()" value="Focus Used" />
606608
</form>
607609
</div>
608610
</file>
@@ -626,6 +628,14 @@ angular.module('patternfly.card').directive('pfCard', function () {
626628
order: null
627629
};
628630
631+
$scope.getChart = function (chart) {
632+
$scope.chart = chart;
633+
}
634+
635+
$scope.focusUsed = function () {
636+
$scope.chart.focus("Used");
637+
}
638+
629639
$scope.updateAvailable = function (val) {
630640
$scope.available = $scope.total - $scope.used;
631641
}
@@ -646,17 +656,23 @@ angular.module('patternfly.card').directive('pfCard', function () {
646656
return {
647657
restrict: 'A',
648658
scope: {
649-
config: '='
659+
config: '=',
660+
getChartCallback: '='
650661
},
651662
template: '<div id=""></div>',
652663
replace: true,
653664
link: function (scope, element, attrs) {
654665
scope.$watch('config', function () {
655666
$timeout(function () {
667+
// store the chart object
668+
var chart;
656669
//generate c3 chart data
657670
var chartData = scope.config;
658671
chartData.bindto = '#' + attrs.id;
659-
c3.generate(chartData);
672+
chart = c3.generate(chartData);
673+
if (scope.getChartCallback) {
674+
scope.getChartCallback(chart);
675+
}
660676
});
661677
}, true);
662678
}

0 commit comments

Comments
 (0)