Splash 5 years ago committed by GitHub
parent 204df6d4f5
commit 76aee04cc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,34 +18,35 @@ const chart_options = {
}; };
function update_chart(input_data, possibilities) { function update_chart(input_data, possibilities) {
var ctx = $("#chart"); let ctx = $("#chart"),
datasets = [{
datasets = [
{
label: i18next.t("output.chart.input"), label: i18next.t("output.chart.input"),
data: input_data.slice(1), data: input_data.slice(1),
fill: false, fill: false,
}, }, {
{
label: i18next.t("output.chart.minimum"), label: i18next.t("output.chart.minimum"),
data: possibilities[0].prices.slice(1).map(day => day.min), data: possibilities[0].prices.slice(1).map(day => day.min),
fill: false, fill: false,
}, }, {
{
label: i18next.t("output.chart.maximum"), label: i18next.t("output.chart.maximum"),
data: possibilities[0].prices.slice(1).map(day => day.max), data: possibilities[0].prices.slice(1).map(day => day.max),
fill: "-1", fill: "-1",
}, },
]; ],
labels = [i18next.t("weekdays.sunday")].concat(...[i18next.t("weekdays.abr.monday"), i18next.t("weekdays.abr.tuesday"), i18next.t("weekdays.abr.wednesday"), i18next.t("weekdays.abr.thursday"), i18next.t("weekdays.abr.friday"), i18next.t("weekdays.abr.saturday")].map(
day => [i18next.t("times.morning"),
i18next.t("times.afternoon")].map(
time => `${day} ${time}`)));
if (chart_instance) { if (chart_instance) {
chart_instance.data.datasets = datasets; chart_instance.data.datasets = datasets;
chart_instance.data.labels = labels;
chart_instance.update(); chart_instance.update();
} else { } else {
chart_instance = new Chart(ctx, { chart_instance = new Chart(ctx, {
data: { data: {
datasets: datasets, datasets: datasets,
labels: [i18next.t("weekdays.sunday"), i18next.t("weekdays.abr.monday") + " " + i18next.t("times.morning"), i18next.t("weekdays.abr.monday") + " " + i18next.t("times.afternoon"), i18next.t("weekdays.abr.tuesday") + " " + i18next.t("times.morning"), i18next.t("weekdays.abr.tuesday") + " " + i18next.t("times.afternoon"), i18next.t("weekdays.abr.wednesday") + " " + i18next.t("times.morning"), i18next.t("weekdays.abr.wednesday") + " " + i18next.t("times.afternoon"), i18next.t("weekdays.abr.thursday") + " " + i18next.t("times.morning"), i18next.t("weekdays.abr.thursday") + " " + i18next.t("times.afternoon"), i18next.t("weekdays.abr.friday") + " " + i18next.t("times.morning"), i18next.t("weekdays.abr.friday") + " " + i18next.t("times.afternoon"), i18next.t("weekdays.abr.saturday") + " " + i18next.t("times.morning"), i18next.t("weekdays.abr.saturday") + " " + i18next.t("times.afternoon")], labels: labels
}, },
options: chart_options, options: chart_options,
type: "line", type: "line",

Loading…
Cancel
Save