Multiple series support

This commit is contained in:
Gleb Koval 2021-07-19 02:26:37 +01:00
parent 7a4058ad0c
commit 3ca44334f6
No known key found for this signature in database
GPG Key ID: 120F2F6DA9D995FB
3 changed files with 65 additions and 10 deletions

View File

@ -229,7 +229,7 @@ export async function getGraph(
graph: string, graph: string,
profile: string, profile: string,
member: string member: string
): Promise<[number, number][]> { ): Promise<([number, number] | [string, number, number][])[]> {
let response = await request( let response = await request(
`/api/graphs/${graph}/${profile}/${member}`, `/api/graphs/${graph}/${profile}/${member}`,
token ? { headers: { Authorization: token } } : {} token ? { headers: { Authorization: token } } : {}

View File

@ -40,7 +40,44 @@ export async function get(
}) })
).all(); ).all();
res.writeHead(200); res.writeHead(200);
if (graph.data.style === "line") {
if (data[0].length === 2) {
res.end(
JSON.stringify(
data.filter((value, idx) => {
return (
idx === 0 ||
idx === data.length - 1 ||
data[idx - 1][1] !== value ||
data[idx + 1][1] !== value
);
})
)
);
} else {
let d: [string, number, number][][] = data;
res.end(
JSON.stringify(
d.map((values, idx) => {
return values.filter(value => {
return (
idx === 0 ||
idx === d.length - 1 ||
d[idx - 1].find(
v => v[0] === value[0]
)?.[2] !== value[2] ||
d[idx + 1].find(
v => v[0] === value[0]
)?.[2] !== value[2]
);
});
})
)
);
}
} else {
res.end(JSON.stringify(data)); res.end(JSON.stringify(data));
}
return; return;
default: default:
res.writeHead(404); res.writeHead(404);

View File

@ -25,7 +25,6 @@
getUsername getUsername
} from "../../../../../../lib/api"; } from "../../../../../../lib/api";
import { login, extraNav } from "../../../../../../components/stores"; import { login, extraNav } from "../../../../../../components/stores";
import type { Graph } from "../../../../../api/_types";
$extraNav; $extraNav;
@ -79,13 +78,32 @@
yAxis: g.data.y_axis || { yAxis: g.data.y_axis || {
type: "value" type: "value"
}, },
series: [ series:
data[0].length === 2
? [
{ {
name: g.data.name, name: g.data.name,
type: g.data.style, type: g.data.style,
data: data data: data
} }
], ]
: (<[string, number, number][]>data[0]).map(
([name]) => {
return {
name,
type: g?.data.style,
data: (<[string, number, number][][]>(
data
))
.map(is =>
is
.find(i => i[0] === name)
?.slice(1)
)
.filter(v => v !== undefined)
};
}
),
dataZoom: [ dataZoom: [
{ {
id: "dataZoomX", id: "dataZoomX",