mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Remove custom TimeLineScale for chartjs (#23270)
This commit is contained in:
parent
df4d5a4567
commit
f0ddc408e8
@ -106,7 +106,7 @@ export class StateHistoryChartTimeline extends LitElement {
|
||||
animation: false,
|
||||
scales: {
|
||||
x: {
|
||||
type: "timeline",
|
||||
type: "time",
|
||||
position: "bottom",
|
||||
adapters: {
|
||||
date: {
|
||||
|
@ -17,7 +17,6 @@ declare module "chart.js" {
|
||||
datasetOptions: BarControllerDatasetOptions;
|
||||
defaultDataPoint: TimeLineData;
|
||||
parsedDataType: any;
|
||||
scales: "timeline";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +0,0 @@
|
||||
import { TimeScale } from "chart.js";
|
||||
import type { TimeLineData } from "./const";
|
||||
|
||||
export class TimeLineScale extends TimeScale {
|
||||
static id = "timeline";
|
||||
|
||||
static defaults = {
|
||||
position: "bottom",
|
||||
tooltips: {
|
||||
mode: "nearest",
|
||||
},
|
||||
ticks: {
|
||||
autoSkip: true,
|
||||
},
|
||||
};
|
||||
|
||||
determineDataLimits() {
|
||||
const options = this.options;
|
||||
// @ts-ignore
|
||||
const adapter = this._adapter;
|
||||
const unit = options.time.unit || "day";
|
||||
let { min, max } = this.getUserBounds();
|
||||
|
||||
const chart = this.chart;
|
||||
|
||||
// Convert data to timestamps
|
||||
chart.data.datasets.forEach((dataset, index) => {
|
||||
if (!chart.isDatasetVisible(index)) {
|
||||
return;
|
||||
}
|
||||
for (const data of dataset.data as TimeLineData[]) {
|
||||
let timestamp0 = adapter.parse(data.start, this);
|
||||
let timestamp1 = adapter.parse(data.end, this);
|
||||
if (timestamp0 > timestamp1) {
|
||||
[timestamp0, timestamp1] = [timestamp1, timestamp0];
|
||||
}
|
||||
if (min > timestamp0 && timestamp0) {
|
||||
min = timestamp0;
|
||||
}
|
||||
if (max < timestamp1 && timestamp1) {
|
||||
max = timestamp1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// In case there is no valid min/max, var's use today limits
|
||||
min =
|
||||
isFinite(min) && !isNaN(min) ? min : +adapter.startOf(Date.now(), unit);
|
||||
max = isFinite(max) && !isNaN(max) ? max : +adapter.endOf(Date.now(), unit);
|
||||
|
||||
// Make sure that max is strictly higher than min (required by the lookup table)
|
||||
this.min = adapter.parse(options.min, this) ?? Math.min(min, max - 1);
|
||||
this.max = adapter.parse(options.max, this) ?? Math.max(min + 1, max);
|
||||
}
|
||||
}
|
@ -16,7 +16,6 @@ import {
|
||||
} from "chart.js";
|
||||
import { TextBarElement } from "../components/chart/timeline-chart/textbar-element";
|
||||
import { TimelineController } from "../components/chart/timeline-chart/timeline-controller";
|
||||
import { TimeLineScale } from "../components/chart/timeline-chart/timeline-scale";
|
||||
import "../components/chart/chart-date-adapter";
|
||||
|
||||
export { Chart } from "chart.js";
|
||||
@ -34,7 +33,6 @@ Chart.register(
|
||||
PointElement,
|
||||
LineElement,
|
||||
TextBarElement,
|
||||
TimeLineScale,
|
||||
TimelineController,
|
||||
CategoryScale,
|
||||
LogarithmicScale
|
||||
|
Loading…
x
Reference in New Issue
Block a user