Skip to content

Commit 50e0793

Browse files
committed
Make route services pie chart responsive
Fix problems on mobile and with long names
1 parent 8a5a5f1 commit 50e0793

File tree

4 files changed

+47
-25
lines changed

4 files changed

+47
-25
lines changed

app/scripts/directives/routeServicePie.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ angular.module('openshiftConsole')
1010
template: '<div ng-show="totalWeight" ng-attr-id="{{chartId}}"></div>',
1111
link: function($scope) {
1212
var chart, config;
13+
var mobile = window.matchMedia("(max-width: 400px)").matches;
1314

1415
$scope.chartId = _.uniqueId('route-service-chart-');
1516

@@ -20,16 +21,23 @@ angular.module('openshiftConsole')
2021
},
2122
legend: {
2223
show: true,
23-
position: 'right'
24+
position: mobile ? 'bottom' : 'right'
2425
},
2526
pie: {
2627
label: {
2728
show: false
2829
}
2930
},
3031
size: {
31-
height: 115,
32-
width: 260
32+
height: mobile ? 150 : 115
33+
},
34+
tooltip: {
35+
format: {
36+
name: function(name, ratio, id) {
37+
// Show the full name on hover, even if name is truncated for the legend.
38+
return id;
39+
}
40+
}
3341
},
3442
data: {
3543
type: "pie",
@@ -69,14 +77,17 @@ angular.module('openshiftConsole')
6977

7078
function updateChart() {
7179
var data = {
72-
columns: []
80+
columns: [],
81+
names: {}
7382
};
7483

7584
if ($scope.route) {
7685
data.columns.push(getData($scope.route.spec.to));
86+
data.names[$scope.route.spec.to.name] = _.trunc($scope.route.spec.to.name, { length: 30 });
7787
$scope.totalWeight = $scope.route.spec.to.weight;
7888
_.each($scope.route.spec.alternateBackends, function(routeTarget) {
7989
data.columns.push(getData(routeTarget));
90+
data.names[routeTarget.name] = _.trunc(routeTarget.name, { length: 30 });
8091
$scope.totalWeight += routeTarget.weight;
8192
});
8293
}

app/views/browse/route.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ <h4>Traffic</h4>
124124
This route splits traffic across multiple services.
125125
</div>
126126
</div>
127-
<div class="col-sm-5 col-sm-push-7 mar-bottom-lg">
127+
<div class="col-sm-12 col-md-5 col-md-push-7 mar-bottom-lg">
128128
<route-service-pie route="route"></route-service-pie>
129129
</div>
130-
<div class="col-sm-7 col-sm-pull-5">
130+
<div class="cold-sm-12 col-md-7 col-md-pull-5">
131131
<table class="table table-bordered">
132132
<thead>
133133
<tr>

dist/scripts/scripts.js

+28-17
Original file line numberDiff line numberDiff line change
@@ -12389,30 +12389,41 @@ template:'<div ng-show="totalWeight" ng-attr-id="{{chartId}}"></div>',
1238912389
link:function(a) {
1239012390
function b() {
1239112391
var b = {
12392-
columns:[]
12393-
};
12394-
a.route && (b.columns.push(f(a.route.spec.to)), a.totalWeight = a.route.spec.to.weight, _.each(a.route.spec.alternateBackends, function(c) {
12395-
b.columns.push(f(c)), a.totalWeight += c.weight;
12396-
})), a.totalWeight && (c ? (h(b), c.load(b)) :(d.data.columns = b.columns, c = c3.generate(d)), e = b);
12397-
}
12398-
var c, d;
12392+
columns:[],
12393+
names:{}
12394+
};
12395+
a.route && (b.columns.push(g(a.route.spec.to)), b.names[a.route.spec.to.name] = _.trunc(a.route.spec.to.name, {
12396+
length:30
12397+
}), a.totalWeight = a.route.spec.to.weight, _.each(a.route.spec.alternateBackends, function(c) {
12398+
b.columns.push(g(c)), b.names[c.name] = _.trunc(c.name, {
12399+
length:30
12400+
}), a.totalWeight += c.weight;
12401+
})), a.totalWeight && (c ? (i(b), c.load(b)) :(d.data.columns = b.columns, c = c3.generate(d)), f = b);
12402+
}
12403+
var c, d, e = window.matchMedia("(max-width: 400px)").matches;
1239912404
a.chartId = _.uniqueId("route-service-chart-"), d = {
1240012405
bindto:"#" + a.chartId,
1240112406
color:{
1240212407
pattern:[ $.pfPaletteColors.blue, $.pfPaletteColors.orange, $.pfPaletteColors.green, $.pfPaletteColors.red ]
1240312408
},
1240412409
legend:{
1240512410
show:!0,
12406-
position:"right"
12411+
position:e ? "bottom" :"right"
1240712412
},
1240812413
pie:{
1240912414
label:{
1241012415
show:!1
1241112416
}
1241212417
},
1241312418
size:{
12414-
height:115,
12415-
width:260
12419+
height:e ? 150 :115
12420+
},
12421+
tooltip:{
12422+
format:{
12423+
name:function(a, b, c) {
12424+
return c;
12425+
}
12426+
}
1241612427
},
1241712428
data:{
1241812429
type:"pie",
@@ -12422,21 +12433,21 @@ enabled:!1
1242212433
}
1242312434
}
1242412435
};
12425-
var e, f = function(a) {
12436+
var f, g = function(a) {
1242612437
return [ a.name, a.weight ];
12427-
}, g = function(a) {
12428-
return _.head(a);
1242912438
}, h = function(a) {
12439+
return _.head(a);
12440+
}, i = function(a) {
1243012441
var b = {};
1243112442
_.each(a.columns, function(a) {
12432-
var c = g(a);
12443+
var c = h(a);
1243312444
b[c] = !0;
1243412445
});
12435-
var c = _.get(e, "columns", []);
12446+
var c = _.get(f, "columns", []);
1243612447
a.unload = _.chain(c).reject(function(a) {
12437-
var c = g(a);
12448+
var c = h(a);
1243812449
return _.has(b, [ c ]);
12439-
}).map(g).value();
12450+
}).map(h).value();
1244012451
};
1244112452
a.$watch("route", b), a.$on("destroy", function() {
1244212453
c && (c = c.destroy());

dist/scripts/templates.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3708,10 +3708,10 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
37083708
"This route splits traffic across multiple services.\n" +
37093709
"</div>\n" +
37103710
"</div>\n" +
3711-
"<div class=\"col-sm-5 col-sm-push-7 mar-bottom-lg\">\n" +
3711+
"<div class=\"col-sm-12 col-md-5 col-md-push-7 mar-bottom-lg\">\n" +
37123712
"<route-service-pie route=\"route\"></route-service-pie>\n" +
37133713
"</div>\n" +
3714-
"<div class=\"col-sm-7 col-sm-pull-5\">\n" +
3714+
"<div class=\"cold-sm-12 col-md-7 col-md-pull-5\">\n" +
37153715
"<table class=\"table table-bordered\">\n" +
37163716
"<thead>\n" +
37173717
"<tr>\n" +

0 commit comments

Comments
 (0)