reports: add non-timeseries charts.

Add bar charts for non-timeseries data. For example, a bar chart of the
top 10 uploaders overall in the last month, rather than a timeseries
chart of the number of uploads per day for the last month.
This commit is contained in:
evazion
2022-10-23 04:42:51 -05:00
parent 9ca76dd3be
commit 203067b5ed
7 changed files with 192 additions and 110 deletions

View File

@@ -1,70 +1,12 @@
import * as echarts from "echarts";
import startCase from "lodash/startCase";
import CurrentUser from "./current_user.js";
export default class TimeSeriesComponent {
constructor({ container = null, data = [], columns = [], theme = null } = {}) {
constructor({ container = null, options = {} } = {}) {
this.container = container;
this.data = data;
this.columns = columns;
this.options = options;
this.theme = CurrentUser.darkMode() ? "dark" : null;
this.options = {
dataset: {
dimensions: ["date", ...this.columns],
source: data,
},
tooltip: {
trigger: "axis",
axisPointer: {
type: "cross",
label: {
backgroundColor: '#6a7985'
}
}
},
toolbox: {
feature: {
dataView: {},
dataZoom: {
yAxisIndex: "none"
},
magicType: {
type: ["line", "bar"],
},
restore: {},
saveAsImage: {}
}
},
dataZoom: [
{ type: "inside" },
{ type: "slider" }
],
grid: {
left: "1%",
right: "1%",
containLabel: true
},
legend: {
data: this.columns.map(startCase),
},
xAxis: { type: "time" },
yAxis: this.columns.map(name => ({ type: "value" })),
series: this.columns.map(name => ({
name: startCase(name),
type: "line",
areaStyle: {},
stack: "all",
emphasis: {
focus: "series"
},
encode: {
x: "date",
y: name
}
}))
};
this.chart = echarts.init(container, this.theme);
this.chart.setOption(this.options);