@@ -588,21 +588,23 @@ angular.module('patternfly.card').directive('pfCard', function () {
588
588
*
589
589
* @param {string } id the ID of the container that the chart should bind to
590
590
* @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
591
592
*
592
593
* @example
593
594
594
595
<example module="patternfly.charts">
595
596
<file name="index.html">
596
597
<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>
598
599
599
600
<form role="form" style="width:300px">
600
601
Total = {{total}}, Used = {{used}}, Available = {{available}}
601
602
<div class="form-group">
602
603
<label>Used</label>
603
604
<input type="text" class="form-control" ng-model="newUsed">
604
605
</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" />
606
608
</form>
607
609
</div>
608
610
</file>
@@ -626,6 +628,14 @@ angular.module('patternfly.card').directive('pfCard', function () {
626
628
order: null
627
629
};
628
630
631
+ $scope.getChart = function (chart) {
632
+ $scope.chart = chart;
633
+ }
634
+
635
+ $scope.focusUsed = function () {
636
+ $scope.chart.focus("Used");
637
+ }
638
+
629
639
$scope.updateAvailable = function (val) {
630
640
$scope.available = $scope.total - $scope.used;
631
641
}
@@ -646,17 +656,23 @@ angular.module('patternfly.card').directive('pfCard', function () {
646
656
return {
647
657
restrict : 'A' ,
648
658
scope : {
649
- config : '='
659
+ config : '=' ,
660
+ getChartCallback : '='
650
661
} ,
651
662
template : '<div id=""></div>' ,
652
663
replace : true ,
653
664
link : function ( scope , element , attrs ) {
654
665
scope . $watch ( 'config' , function ( ) {
655
666
$timeout ( function ( ) {
667
+ // store the chart object
668
+ var chart ;
656
669
//generate c3 chart data
657
670
var chartData = scope . config ;
658
671
chartData . bindto = '#' + attrs . id ;
659
- c3 . generate ( chartData ) ;
672
+ chart = c3 . generate ( chartData ) ;
673
+ if ( scope . getChartCallback ) {
674
+ scope . getChartCallback ( chart ) ;
675
+ }
660
676
} ) ;
661
677
} , true ) ;
662
678
}
0 commit comments