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: { itemStyle: {
color: color(idx, false, theme), color: color(idx, false, theme),
}, },
lineStyle: { lineStyle:
color: color(idx, false, theme), idx == data.rows.length - 1
width: 1, ? {
}, color: isDark ? "#ddd" : "#111",
width: 2,
}
: {
color: color(idx, false, theme),
width: 1,
},
areaStyle: { areaStyle: {
opacity: 0.95, opacity: 0.95,
color: new graphic.LinearGradient(0, 0, 0, 1, [ color: new graphic.LinearGradient(0, 0, 0, 1, [

View File

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

View File

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