console: ensure "Other" is last when returning data

This commit is contained in:
Vincent Bernat
2022-05-10 17:08:57 +02:00
parent d2cc5f1953
commit 31aca4c73b
3 changed files with 24 additions and 11 deletions

View File

@@ -185,10 +185,16 @@ watch([fetchedData, isDark], ([data, isDark]) => {
itemStyle: {
color: color(idx, false, theme),
},
lineStyle: {
color: color(idx, false, theme),
width: 1,
},
lineStyle:
idx == data.rows.length - 1
? {
color: isDark ? "#ddd" : "#111",
width: 2,
}
: {
color: color(idx, false, theme),
width: 1,
},
areaStyle: {
opacity: 0.95,
color: new graphic.LinearGradient(0, 0, 0, 1, [

View File

@@ -481,7 +481,14 @@ func (c *Component) graphHandlerFunc(gc *gin.Context) {
rows[i] = k
i++
}
// Sort by sum, except we want "Other" to be last
sort.Slice(rows, func(i, j int) bool {
if rowKeys[rows[i]][0] == "Other" {
return false
}
if rowKeys[rows[j]][0] == "Other" {
return true
}
return rowSums[rows[i]] > rowSums[rows[j]]
})
output.Rows = make([][]string, len(rows))

View File

@@ -418,11 +418,11 @@ func TestGraphHandler(t *testing.T) {
// Sorted by sum of bps
"rows": [][]string{
{"router1", "provider2"}, // 10000
{"Other", "Other"}, // 2100
{"router1", "provider1"}, // 1600
{"router2", "provider2"}, // 1200
{"router2", "provider3"}, // 1100
{"router2", "provider4"}, // 1000
{"Other", "Other"}, // 2100
},
"t": []string{
"2009-11-10T23:00:00Z",
@@ -431,35 +431,35 @@ func TestGraphHandler(t *testing.T) {
},
"points": [][]int{
{2000, 5000, 3000},
{1900, 100, 100},
{1000, 500, 100},
{1200, 0, 0},
{1100, 0, 0},
{0, 900, 100},
{1900, 100, 100},
},
"min": []int{
2000,
100,
0,
0,
0,
100,
0,
0,
0,
},
"max": []int{
5000,
1900,
1000,
1200,
1100,
900,
1900,
},
"average": []int{
3333,
700,
533,
400,
366,
333,
700,
},
}
mockConn.EXPECT().