@@ -1171,10 +1171,12 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
11711171 *
11721172 * @param {object } config configuration settings for the trends chart:<br/>
11731173 * <ul style='list-style-type: none'>
1174- * <li>.chartId - the unique id of this trends chart
1175- * <li>.title - (optional) title of the Trends chart
1176- * <li>.timeFrame - (optional) the time frame for the data in the pfSparklineChart, ex: 'Last 30 Days'
1177- * <li>.units - unit label for values, ex: 'MHz','GB', etc..
1174+ * <li>.chartId - the unique id of this trends chart
1175+ * <li>.title - (optional) title of the Trends chart
1176+ * <li>.layout - (optional) the layout and sizes of titles and chart. Values are 'large' (default), and 'small'
1177+ * <li>.timeFrame - (optional) the time frame for the data in the pfSparklineChart, ex: 'Last 30 Days'
1178+ * <li>.units - unit label for values, ex: 'MHz','GB', etc..
1179+ * <li>.valueType - (optional) the format of the latest data point which is shown in the title. Values are 'actual'(default) or 'percentage'
11781180 * </ul>
11791181 *
11801182 * @param {object } chartData the data to be shown in the sparkline charts<br/>
@@ -1192,7 +1194,7 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
11921194 <file name="index.html">
11931195 <div ng-controller="ChartCtrl" class="row" style="display:inline-block; width: 100%;">
11941196 <div class="col-md-12">
1195- <div pf-trends-chart config="config" chart-data="data" chart-height="custChartHeight"
1197+ <div pf-trends-chart config="config" chart-data="data"
11961198 show-x-axis="custShowXAxis" show-y-axis="custShowYAxis"></div>
11971199 </div>
11981200 <hr class="col-md-12">
@@ -1211,15 +1213,29 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
12111213 </div>
12121214 </form>
12131215 </div>
1214- <div class="col-md-4 ">
1216+ <div class="col-md-3 ">
12151217 <form role="form" >
12161218 <div class="form-group">
1217- <label>Chart Height</label></br>
1218- <input style="height:25px; width:60px;" type="number" ng-model="custChartHeight"></input>
1219+ <label>Title Value Type</label></br>
1220+ <select pf-select class="pf-select-sm" ng-model="valueType" id="valueType">
1221+ <option value="actual" ng-selected="true" selected>Actual</option>
1222+ <option value="percentage">Percentage</option>
1223+ </select>
12191224 </div>
12201225 </form>
12211226 </div>
1222- <div class="col-md-4">
1227+ <div class="col-md-3">
1228+ <form role="form" >
1229+ <div class="form-group">
1230+ <label>Layout</label></br>
1231+ <select pf-select class="pf-select-sm" ng-model="layout" id="layout">
1232+ <option value="large" ng-selected="true" selected>Large</option>
1233+ <option value="small">Small</option>
1234+ </select>
1235+ </div>
1236+ </form>
1237+ </div>
1238+ <div class="col-md-2">
12231239 <button ng-click="addDataPoint()">Add Data Point</button>
12241240 </div>
12251241 </div>
@@ -1231,9 +1247,10 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
12311247 $scope.config = {
12321248 'chartId' : 'exampleTrendsChart',
12331249 'title' : 'Network Utilization Trends',
1250+ 'layout' : 'large',
1251+ 'valueType' : 'actual',
12341252 'timeFrame' : 'Last 15 Minutes',
12351253 'units' : 'MHz',
1236- 'showTopBorder': 'true',
12371254 'tooltipType' : 'percentage'
12381255 };
12391256
@@ -1244,19 +1261,27 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
12441261 }
12451262
12461263 $scope.data = {
1247- 'total': '100 ',
1264+ 'total': '250 ',
12481265 'xData': dates,
12491266 'yData': ['used', '10', '20', '30', '20', '30', '10', '14', '20', '25', '68', '54', '56', '78', '56', '67', '88', '76', '65', '87', '76']
12501267 };
12511268
12521269 $scope.custShowXAxis = false;
12531270 $scope.custShowYAxis = false;
1254- $scope.custChartHeight = 60;
12551271
12561272 $scope.addDataPoint = function () {
12571273 $scope.data.xData.push(new Date($scope.data.xData[$scope.data.xData.length - 1].getTime() + (24 * 60 * 60 * 1000)));
12581274 $scope.data.yData.push(Math.round(Math.random() * 100));
12591275 };
1276+
1277+ $scope.$watch('valueType', function (newValue) {
1278+ $scope.config.valueType = newValue;
1279+ });
1280+
1281+ $scope.$watch('layout', function (newValue) {
1282+ $scope.config.layout = newValue;
1283+ });
1284+
12601285 });
12611286 </file>
12621287 </example>
@@ -1274,7 +1299,34 @@ angular.module('patternfly.charts').directive('pfTrendsChart',
12741299 showYAxis : '=?'
12751300 } ,
12761301 replace : true ,
1277- templateUrl : 'charts/trends/trends-chart.html'
1302+ templateUrl : 'charts/trends/trends-chart.html' ,
1303+ controller : [ "$scope" , function ( $scope ) {
1304+ var SMALL = 30 , LARGE = 60 ;
1305+
1306+ $scope . getPercentageValue = function ( ) {
1307+ return Math . round ( $scope . getLatestValue ( ) / $scope . chartData . total * 100.0 ) ;
1308+ } ;
1309+ $scope . getLatestValue = function ( ) {
1310+ return $scope . chartData . yData [ $scope . chartData . yData . length - 1 ] ;
1311+ } ;
1312+ $scope . getChartHeight = function ( ) {
1313+ var retValue = LARGE ;
1314+ if ( $scope . chartHeight ) {
1315+ retValue = $scope . chartHeight ;
1316+ } else if ( $scope . config . layout === 'small' ) {
1317+ retValue = SMALL ;
1318+ }
1319+ return retValue ;
1320+ } ;
1321+ } ] ,
1322+ link : function ( scope ) {
1323+ scope . $watch ( 'config' , function ( ) {
1324+ scope . showLargeCardLayout = ( ! scope . config . layout || scope . config . layout === 'large' ) ;
1325+ scope . showSmallCardLayout = ( scope . config . layout === 'small' ) ;
1326+ scope . showActualValue = ( ! scope . config . valueType || scope . config . valueType === 'actual' ) ;
1327+ scope . showPercentageValue = ( scope . config . valueType === 'percentage' ) ;
1328+ } , true ) ;
1329+ }
12781330 } ;
12791331 }
12801332) ;
@@ -3982,7 +4034,7 @@ angular.module('patternfly.views').directive('pfDataToolbar',
39824034
39834035
39844036 $templateCache . put ( 'charts/trends/trends-chart.html' ,
3985- "<div><span class=trend-header-pf ng-if=config.title>{{config.title}}</span> <span class=trend-title-big-pf>{{chartData.yData[chartData.yData.length-1] }}</span> <span class=trend-title-small-pf>{{ config.units}}</span><div pf-sparkline-chart config=config chart-data=chartData chart-height=chartHeight show-x-axis=showXAxis show-y-axis=showYAxis></div><span class=trend-footer-pf ng-if=config.timeFrame>{{config.timeFrame}}</span></div>"
4037+ "<span>< div ng-class=\"{'trend-card-large-pf': showLargeCardLayout,'trend-card-small-pf': showSmallCardLayout}\" ><span class=trend-header-pf ng-if=config.title>{{config.title}}</span> <span ng-if=showActualValue><span class=trend-title-big-pf>{{getLatestValue()}}</span> <span class=trend-title-small-pf>{{config.units}}</span></span> <span ng-if=showPercentageValue><span class=trend-title-big-pf>{{getPercentageValue() + '%' }}</span> <span class=trend-title-small-pf>of {{chartData.total + ' ' + config.units}}</span></span>< div pf-sparkline-chart config=config chart-data=chartData chart-height=getChartHeight() show-x-axis=showXAxis show-y-axis=showYAxis></div><span class=trend-footer-pf ng-if=config.timeFrame>{{config.timeFrame}}</span></div></span >"
39864038 ) ;
39874039
39884040
0 commit comments