Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 55 additions & 15 deletions frontend/coprs_frontend/coprs/static/js/graphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,64 @@ function lineGraph(data, ticks, bind, format) {
};

function chrootGraph(data, bind) {
chart = graphConfig();
chart.axis.x = {show: false};
chart.bindto = bind;
chart.data = {
columns: data,
type: 'bar'
// distro specific colors for chroot bars
var osColors = { 'fedora': '#294172', 'centos': '#262f45', 'rhel': '#cc0000', 'epel': '#48759d', 'mageia': '#262f45',
'opensuse': '#73ba25', 'openmandriva': '#e06f00', 'amazon': '#f99d1c', 'alma': '#dadada', 'alien': '#333333' };
var getColor = function(name) {
if (!name) return osColors['alien'];
var lowerName = name.toLowerCase();
for (var os in osColors) {
if (lowerName.indexOf(os) !== -1) return osColors[os];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Iterating over an object with for...in can include inherited properties from the prototype chain. To make this loop more robust, it's best practice to check if the property belongs to the object itself using Object.prototype.hasOwnProperty.call().

Suggested change
if (lowerName.indexOf(os) !== -1) return osColors[os];
if (Object.prototype.hasOwnProperty.call(osColors, os) && lowerName.indexOf(os) !== -1) return osColors[os];

}
return osColors['alien'];
};
chart.size = {height: 800,
width: undefined};
chart.tooltip = {
format: {
title: function (x) {return ''}
data.sort(function(a, b) {
return b[1] - a[1];
});
var categories = [];
var columns = ['Builds'];
data.forEach(function(item) {
categories.push(item[0]);
columns.push(item[1]);
});
var chart = {
bindto: bind,
size: {
height: Math.max((categories.length * 25) + 50, 100)
},
data: {
columns: [columns],
type: 'bar',
color: function (color, d) {
if (d.index !== undefined) return getColor(categories[d.index]);
return color;
},
labels: true
},
position: function (data, width, height, element) {
return {top: 0, left: -150};
axis: {
rotated: true,
x: {
type: 'category',
categories: categories,
tick: {
multiline: false
}
},
y: {
show: false
}
},
legend: {
show: false
},
tooltip: {
show: false
},
grid: {
y: {show: false},
x: {show: false}
}
}
chart.zoom = {enabled: false};
};
var chrootsChart = c3.generate(chart);
};

Expand Down