@@ -573,7 +573,8 @@ angular.module('patternfly.card').directive('pfCard', function () {
573
573
getDefaultSparklineLegend : patternflyDefaults . getDefaultSparklineLegend ,
574
574
getDefaultSparklinePoint : patternflyDefaults . getDefaultSparklinePoint ,
575
575
getDefaultSparklineTooltip : patternflyDefaults . getDefaultSparklineTooltip ,
576
- getDefaultSparklineConfig : patternflyDefaults . getDefaultSparklineConfig
576
+ getDefaultSparklineConfig : patternflyDefaults . getDefaultSparklineConfig ,
577
+ getDefaultLineConfig : patternflyDefaults . getDefaultLineConfig
577
578
} ) ;
578
579
} ) ( ) ;
579
580
; /**
@@ -942,14 +943,14 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["pfUtils", "$t
942
943
}
943
944
944
945
$scope . getStatusColor = function ( used , thresholds ) {
945
- var color = '#0088CE' ;
946
+ var color = pfUtils . colorPalette . blue ;
946
947
947
948
if ( thresholds ) {
948
- color = '#3f9c35' ;
949
+ color = pfUtils . colorPalette . green ;
949
950
if ( used >= thresholds . error ) {
950
- color = '#CC0000' ;
951
+ color = pfUtils . colorPalette . red ;
951
952
} else if ( used >= thresholds . warning ) {
952
- color = '#EC7A08' ;
953
+ color = pfUtils . colorPalette . orange ;
953
954
}
954
955
}
955
956
@@ -962,7 +963,7 @@ angular.module('patternfly.charts').directive('pfDonutPctChart', ["pfUtils", "$t
962
963
color = { pattern : [ ] } ;
963
964
percentUsed = scope . data . used / scope . data . total * 100.0 ;
964
965
color . pattern [ 0 ] = $scope . getStatusColor ( percentUsed , scope . config . thresholds ) ;
965
- color . pattern [ 1 ] = '#D1D1D1' ;
966
+ color . pattern [ 1 ] = pfUtils . colorPalette . black300 ;
966
967
return color ;
967
968
} ;
968
969
@@ -1463,6 +1464,225 @@ angular.module('patternfly.charts').directive('pfHeatmap', ["$compile", function
1463
1464
}
1464
1465
} ;
1465
1466
} ] ) ;
1467
+ ; /**
1468
+ * @ngdoc directive
1469
+ * @name patternfly.charts.directive:pfLineChart
1470
+ *
1471
+ * @description
1472
+ * Directive for rendering a line chart.
1473
+ * <br><br>
1474
+ * See http://c3js.org/reference.html for a full list of C3 chart options.
1475
+ *
1476
+ * @param {object } config configuration settings for the line chart:<br/>
1477
+ * <ul style='list-style-type: none'>
1478
+ * <li>.chartId - the ID of the container that the chart should bind to
1479
+ * <li>.units - unit label for values, ex: 'MHz','GB', etc..
1480
+ * <li>.tooltipFn - (optional) override the tooltip contents generation functions. Should take a data point and
1481
+ * return HTML markup for the tooltip contents. Setting this overrides the tooltipType value.
1482
+ * <li>.area - (optional) overrides the default Area properties of the C3 chart
1483
+ * <li>.size - (optional) overrides the default Size properties of the C3 chart
1484
+ * <li>.axis - (optional) overrides the default Axis properties of the C3 chart
1485
+ * <li>.color - (optional) overrides the default Color properties of the C3 chart
1486
+ * <li>.legend - (optional) overrides the default Legend properties of the C3 chart
1487
+ * <li>.point - (optional) overrides the default Point properties of the C3 chart
1488
+ * </ul>
1489
+ *
1490
+ * @param {object } chartData the data to be shown as an area chart<br/>
1491
+ * First and second Array elements, xData and yData, must exist, next data arrays are optional.<br/>
1492
+ * <ul style='list-style-type: none'>
1493
+ * <li>.xData - Array, X values for the data points, first element must be the name of the data
1494
+ * <li>.yData - Array, Y Values for the data points, first element must be the name of the data
1495
+ * <li>.yData1 - Array, Y Values for the data points, first element must be the name of the data
1496
+ * <li>.[...] - Array, Y Values for the data points, first element must be the name of the data
1497
+ * </ul>
1498
+ *
1499
+ * @param {boolean= } showXAxis override config settings for showing the X Axis
1500
+ * @param {boolean= } showYAxis override config settings for showing the Y Axis
1501
+ * @param {boolean= } setAreaChart override config settings for showing area type chart
1502
+
1503
+ * @example
1504
+ <example module="patternfly.charts">
1505
+ <file name="index.html">
1506
+ <div ng-controller="ChartCtrl" class="row" style="display:inline-block; width: 100%;">
1507
+ <div class="col-md-12">
1508
+ <div pf-line-chart config="config" chart-data="data" set-area-chart="custAreaChart" show-x-axis="custShowXAxis" show-y-axis="custShowYAxis"></div>
1509
+ </div>
1510
+ <hr class="col-md-12">
1511
+ <div class="col-md-12">
1512
+ <div class="row">
1513
+ <div class="col-md-6">
1514
+ <form role="form"">
1515
+ <div class="form-group">
1516
+ <label class="checkbox-inline">
1517
+ <input type="checkbox" ng-model="custShowXAxis">X Axis</input>
1518
+ </label>
1519
+ <label class="checkbox-inline">
1520
+ <input type="checkbox" ng-model="custShowYAxis">Y Axis</input>
1521
+ </label>
1522
+ <label class="checkbox-inline">
1523
+ <input type="checkbox" ng-model="custAreaChart">Area Chart</input>
1524
+ </label>
1525
+ </div>
1526
+ </form>
1527
+ </div>
1528
+ <div class="col-md-3">
1529
+ <button ng-click="addDataPoint()">Add Data Point</button>
1530
+ </div>
1531
+ </div>
1532
+ </div>
1533
+ </div>
1534
+ </file>
1535
+
1536
+ <file name="script.js">
1537
+ angular.module( 'patternfly.charts' ).controller( 'ChartCtrl', function( $scope, pfUtils ) {
1538
+
1539
+ $scope.config = {
1540
+ chartId: 'exampleLine',
1541
+ grid: {y: {show: false}},
1542
+ point: {r: 1},
1543
+ color: {pattern: [pfUtils.colorPalette.blue, pfUtils.colorPalette.green]}
1544
+ };
1545
+
1546
+ var today = new Date();
1547
+ var dates = ['dates'];
1548
+ for (var d = 20 - 1; d >= 0; d--) {
1549
+ dates.push(new Date(today.getTime() - (d * 24 * 60 * 60 * 1000)));
1550
+ }
1551
+
1552
+ $scope.data = {
1553
+ xData: dates,
1554
+ yData0: ['Created', 12, 10,10, 62, 17, 10, 15, 13, 17, 10, 12, 10, 10, 12, 17, 16, 15, 13, 17, 10],
1555
+ yData1: ['Deleted', 10, 17, 76,14, 10, 10, 10, 10, 10, 10, 10, 17, 17, 14, 10, 10, 10, 10, 10, 10]
1556
+ };
1557
+
1558
+ $scope.custShowXAxis = false;
1559
+ $scope.custShowYAxis = false;
1560
+ $scope.custAreaChart = false;
1561
+
1562
+ $scope.addDataPoint = function () {
1563
+ $scope.data.xData.push(new Date($scope.data.xData[$scope.data.xData.length - 1].getTime() + (24 * 60 * 60 * 1000)));
1564
+ $scope.data.yData0.push(Math.round(Math.random() * 100));
1565
+ $scope.data.yData1.push(Math.round(Math.random() * 100));
1566
+ };
1567
+ });
1568
+ </file>
1569
+ </example>
1570
+ */
1571
+ angular . module ( 'patternfly.charts' ) . directive ( 'pfLineChart' , [ "pfUtils" , function ( pfUtils ) {
1572
+ 'use strict' ;
1573
+ return {
1574
+ restrict : 'A' ,
1575
+ scope : {
1576
+ config : '=' ,
1577
+ chartData : '=' ,
1578
+ showXAxis : '=?' ,
1579
+ showYAxis : '=?' ,
1580
+ setAreaChart : '=?'
1581
+ } ,
1582
+ replace : true ,
1583
+ templateUrl : 'charts/line/line-chart.html' ,
1584
+ controller : [ '$scope' ,
1585
+ function ( $scope ) {
1586
+
1587
+ // Create an ID for the chart based on the chartId in the config if given
1588
+ $scope . lineChartId = 'lineChart' ;
1589
+ if ( $scope . config . chartId ) {
1590
+ $scope . lineChartId = $scope . config . chartId + $scope . lineChartId ;
1591
+ }
1592
+
1593
+ /*
1594
+ * Convert the config data to C3 Data
1595
+ */
1596
+ $scope . getLineData = function ( chartData ) {
1597
+ var lineData = {
1598
+ type : $scope . setAreaChart ? "area" : "line"
1599
+ } ;
1600
+
1601
+ if ( chartData && chartData . dataAvailable !== false && chartData . xData ) {
1602
+ lineData . x = chartData . xData [ 0 ] ;
1603
+ // Convert the chartData dictionary into a C3 columns data arrays
1604
+ lineData . columns = Object . keys ( chartData ) . map ( function ( key ) {
1605
+ return chartData [ key ] ;
1606
+ } ) ;
1607
+ }
1608
+
1609
+ return lineData ;
1610
+ } ;
1611
+
1612
+ /*
1613
+ * Setup Axis options. Default is to not show either axis. This can be overridden in two ways:
1614
+ * 1) in the config, setting showAxis to true will show both axes
1615
+ * 2) in the attributes showXAxis and showYAxis will override the config if set
1616
+ *
1617
+ * By default only line and the tick marks are shown, no labels. This is a line and should be used
1618
+ * only to show a brief idea of trending. This can be overridden by setting the config.axis options per C3
1619
+ */
1620
+
1621
+ if ( $scope . showXAxis === undefined ) {
1622
+ $scope . showXAxis = ( $scope . config . showAxis !== undefined ) && $scope . config . showAxis ;
1623
+ }
1624
+
1625
+ if ( $scope . showYAxis === undefined ) {
1626
+ $scope . showYAxis = ( $scope . config . showAxis !== undefined ) && $scope . config . showAxis ;
1627
+ }
1628
+
1629
+ $scope . defaultConfig = $ ( ) . c3ChartDefaults ( ) . getDefaultLineConfig ( ) ;
1630
+ $scope . defaultConfig . axis = {
1631
+ x : {
1632
+ show : $scope . showXAxis === true ,
1633
+ type : 'timeseries' ,
1634
+ tick : {
1635
+ format : function ( ) {
1636
+ return '' ;
1637
+ }
1638
+ }
1639
+ } ,
1640
+ y : {
1641
+ show : $scope . showYAxis === true ,
1642
+ tick : {
1643
+ format : function ( ) {
1644
+ return '' ;
1645
+ }
1646
+ }
1647
+ }
1648
+ } ;
1649
+
1650
+ /*
1651
+ * Setup Chart type option. Default is Line Chart.
1652
+ */
1653
+ if ( $scope . setAreaChart === undefined ) {
1654
+ $scope . setAreaChart = ( $scope . config . setAreaChart !== undefined ) && $scope . config . setAreaChart ;
1655
+ }
1656
+
1657
+ // Convert the given data to C3 chart format
1658
+ $scope . config . data = pfUtils . merge ( $scope . config . data , $scope . getLineData ( $scope . chartData ) ) ;
1659
+
1660
+ // Override defaults with callers specifications
1661
+ $scope . defaultConfig = pfUtils . merge ( $scope . defaultConfig , $scope . config ) ;
1662
+ }
1663
+ ] ,
1664
+
1665
+ link : function ( scope ) {
1666
+ scope . $watch ( 'config' , function ( ) {
1667
+ scope . config . data = pfUtils . merge ( scope . config . data , scope . getLineData ( scope . chartData ) ) ;
1668
+ scope . chartConfig = pfUtils . merge ( scope . config , scope . defaultConfig ) ;
1669
+ } , true ) ;
1670
+ scope . $watch ( 'showXAxis' , function ( ) {
1671
+ scope . chartConfig . axis . x . show = scope . showXAxis === true ;
1672
+ } ) ;
1673
+ scope . $watch ( 'showYAxis' , function ( ) {
1674
+ scope . chartConfig . axis . y . show = scope . showYAxis === true ;
1675
+ } ) ;
1676
+ scope . $watch ( 'setAreaChart' , function ( ) {
1677
+ scope . chartConfig . data . type = scope . setAreaChart ? "area" : "line" ;
1678
+ } ) ;
1679
+ scope . $watch ( 'chartData' , function ( ) {
1680
+ scope . chartConfig . data = pfUtils . merge ( scope . chartConfig . data , scope . getLineData ( scope . chartData ) ) ;
1681
+ } , true ) ;
1682
+ }
1683
+ } ;
1684
+ } ]
1685
+ ) ;
1466
1686
; /**
1467
1687
* @ngdoc directive
1468
1688
* @name patternfly.charts.directive:pfSparklineChart
@@ -4470,7 +4690,9 @@ angular
4470
4690
} ,
4471
4691
mergeDeep : function ( source1 , source2 ) {
4472
4692
return mergeDeep ( { } , angular . copy ( source1 ) , angular . copy ( source2 ) ) ;
4473
- }
4693
+ } ,
4694
+
4695
+ colorPalette : $ . pfPaletteColors
4474
4696
} ) ;
4475
4697
} ) ( ) ;
4476
4698
@@ -5568,6 +5790,11 @@ angular.module('patternfly.views').directive('pfListView', ["$timeout", "$window
5568
5790
) ;
5569
5791
5570
5792
5793
+ $templateCache . put ( 'charts/line/line-chart.html' ,
5794
+ "<span><div pf-c3-chart id={{lineChartId}} config=chartConfig></div></span>"
5795
+ ) ;
5796
+
5797
+
5571
5798
$templateCache . put ( 'charts/sparkline/sparkline-chart.html' ,
5572
5799
"<span><div pf-c3-chart id={{sparklineChartId}} config=chartConfig></div></span>"
5573
5800
) ;
@@ -5647,7 +5874,7 @@ angular.module('patternfly.views').directive('pfListView', ["$timeout", "$window
5647
5874
'use strict' ;
5648
5875
5649
5876
$templateCache . put ( 'sort/sort.html' ,
5650
- "<div class=sort-pf><form><div class=form-group><div class=\"dropdown btn-group\"><button type=button class=\"btn btn-default dropdown-toggle\" data-toggle=dropdown aria-haspopup=true aria-expanded=false tooltip=\"Sort by\" tooltip-placement=bottom>{{config.currentField.title}} <span class=caret></span></button><ul class=dropdown-menu><li ng-repeat=\"item in config.fields\" ng-class=\"{'selected': item === config.currentField}\"><a class=sort-field role=menuitem tabindex=-1 ng-click=selectField(item)>{{item.title}}</a></li></ul></div><button class=\"btn btn-link\" type=button ng-click=changeDirection()><span class=sort-direction ng-class=getSortIconClass()></span></button></div></form></div>"
5877
+ "<div class=sort-pf><form><div class=form-group><div class=\"dropdown btn-group\"><button type=button class=\"btn btn-default dropdown-toggle\" data-toggle=dropdown aria-haspopup=true aria-expanded=false tooltip=\"Sort by\" tooltip-placement=bottom>{{config.currentField.title}} <span class=caret></span></button><ul class=dropdown-menu><li ng-repeat=\"item in config.fields\" ng-class=\"{'selected': item === config.currentField}\"><a href=javascript:void(0); class=sort-field role=menuitem tabindex=-1 ng-click=selectField(item)>{{item.title}}</a></li></ul></div><button class=\"btn btn-link\" type=button ng-click=changeDirection()><span class=sort-direction ng-class=getSortIconClass()></span></button></div></form></div>"
5651
5878
) ;
5652
5879
5653
5880
} ] ) ;
0 commit comments