@@ -1173,9 +1173,10 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
11731173 * <ul style='list-style-type: none'>
11741174 * <li>.chartId - the unique id of this trends chart
11751175 * <li>.title - (optional) title of the Trends chart
1176+ * <li>.layout - the layout and sizes of titles and chart. Values are 'large' (default), and 'small'
11761177 * <li>.timeFrame - (optional) the time frame for the data in the pfSparklineChart, ex: 'Last 30 Days'
11771178 * <li>.units - unit label for values, ex: 'MHz','GB', etc..
1178- * <li>.valueType - the format of the latest data point which is shown in the title. Values are 'actual' or 'percentage'
1179+ * <li>.valueType - the format of the latest data point which is shown in the title. Values are 'actual'(default) or 'percentage'
11791180 * </ul>
11801181 *
11811182 * @param {object } chartData the data to be shown in the sparkline charts<br/>
@@ -1193,7 +1194,7 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
11931194 <file name="index.html">
11941195 <div ng-controller="ChartCtrl" class="row" style="display:inline-block; width: 100%;">
11951196 <div class="col-md-12">
1196- <div pf-trends-chart config="config" chart-data="data" chart-height="custChartHeight"
1197+ <div pf-trends-chart config="config" chart-data="data"
11971198 show-x-axis="custShowXAxis" show-y-axis="custShowYAxis"></div>
11981199 </div>
11991200 <hr class="col-md-12">
@@ -1215,18 +1216,21 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
12151216 <div class="col-md-3">
12161217 <form role="form" >
12171218 <div class="form-group">
1218- <label>Chart Height</label></br>
1219- <input style="height:25px; width:60px;" type="number" ng-model="custChartHeight"></input>
1219+ <label>Title Value Type</label></br>
1220+ <select pf-select style="height:25px; width:120px;" ng-model="valueType" id="valueType">
1221+ <option value="actual" ng-selected="true" selected>Actual</option>
1222+ <option value="percentage">Percentage</option>
1223+ </select>
12201224 </div>
12211225 </form>
12221226 </div>
12231227 <div class="col-md-3">
12241228 <form role="form" >
12251229 <div class="form-group">
1226- <label>Title Value Type </label></br>
1227- <select pf-select style="height:25px; width:120px;" ng-model="valueType " id="valueType ">
1228- <option value="actual " ng-selected="true" selected>Actual </option>
1229- <option value="percentage">Percentage </option>
1230+ <label>Layout </label></br>
1231+ <select pf-select style="height:25px; width:120px;" ng-model="layout " id="layout ">
1232+ <option value="large " ng-selected="true" selected>Large </option>
1233+ <option value="small">Small </option>
12301234 </select>
12311235 </div>
12321236 </form>
@@ -1243,6 +1247,7 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
12431247 $scope.config = {
12441248 'chartId' : 'exampleTrendsChart',
12451249 'title' : 'Network Utilization Trends',
1250+ 'layout' : 'large',
12461251 'valueType' : 'actual',
12471252 'timeFrame' : 'Last 15 Minutes',
12481253 'units' : 'MHz',
@@ -1263,15 +1268,18 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["c3ChartDefau
12631268
12641269 $scope.custShowXAxis = false;
12651270 $scope.custShowYAxis = false;
1266- $scope.custChartHeight = 60;
12671271
12681272 $scope.addDataPoint = function () {
12691273 $scope.data.xData.push(new Date($scope.data.xData[$scope.data.xData.length - 1].getTime() + (24 * 60 * 60 * 1000)));
12701274 $scope.data.yData.push(Math.round(Math.random() * 100));
12711275 };
12721276
12731277 $scope.$watch('valueType', function (newValue) {
1274- $scope.config.valueType = newValue;
1278+ $scope.config.valueType = newValue;
1279+ });
1280+
1281+ $scope.$watch('layout', function (newValue) {
1282+ $scope.config.layout = newValue;
12751283 });
12761284
12771285 });
@@ -1294,11 +1302,31 @@ angular.module('patternfly.charts').directive('pfTrendsChart',
12941302 templateUrl : 'charts/trends/trends-chart.html' ,
12951303 controller : [ '$scope' ,
12961304 function ( $scope ) {
1297- $scope . getPercentage = function ( ) {
1298- return Math . round ( $scope . chartData . yData [ $scope . chartData . yData . length - 1 ] / $scope . chartData . total * 100.0 ) ;
1305+ $scope . getPercentageValue = function ( ) {
1306+ return Math . round ( $scope . getLatestValue ( ) / $scope . chartData . total * 100.0 ) ;
1307+ } ;
1308+ $scope . getLatestValue = function ( ) {
1309+ return $scope . chartData . yData [ $scope . chartData . yData . length - 1 ] ;
1310+ } ;
1311+ $scope . getChartHeight = function ( ) {
1312+ var retValue = 60 ;
1313+ if ( $scope . chartHeight ) {
1314+ retValue = $scope . chartHeight ;
1315+ } else if ( $scope . config . layout === 'small' ) {
1316+ retValue = 30 ;
1317+ }
1318+ return retValue ;
12991319 } ;
13001320 }
1301- ]
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+ }
13021330 } ;
13031331 }
13041332) ;
@@ -4006,7 +4034,7 @@ angular.module('patternfly.views').directive('pfDataToolbar',
40064034
40074035
40084036 $templateCache . put ( 'charts/trends/trends-chart.html' ,
4009- "<div><span class=trend-header-pf ng-if=config.title>{{config.title}}</span> <span ng-if=\"!config.valueType || config.valueType === 'actual'\" ><span class=trend-title-big-pf>{{chartData.yData[chartData.yData.length-1] }}</span> <span class=trend-title-small-pf>{{config.units}}</span></span> <span ng-if=\"config.valueType === 'percentage'\" ><span class=trend-title-big-pf>{{getPercentage () + '%'}}</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=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 >"
40104038 ) ;
40114039
40124040
0 commit comments