Skip to content

Commit

Permalink
Handle clicking on a timeline history graph row to display more info …
Browse files Browse the repository at this point in the history
…for the displayed entity
  • Loading branch information
k3a authored and Mario Hros committed Sep 25, 2023
1 parent 4b5c702 commit 2624cb3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/components/chart/state-history-chart-timeline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ChartData, ChartDataset, ChartOptions } from "chart.js";
import { getRelativePosition } from "chart.js/helpers";
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { formatDateTimeWithSeconds } from "../../common/datetime/format_date_time";
Expand Down Expand Up @@ -220,6 +221,18 @@ export class StateHistoryChartTimeline extends LitElement {
},
// @ts-expect-error
locale: numberFormatToLocale(this.hass.locale),
onClick: (e: any) => {
const chart = e.chart;
const canvasPosition = getRelativePosition(e, chart);

const index = Math.abs(
chart.scales.y.getValueForPixel(canvasPosition.y)
);
fireEvent(this, "hass-more-info", {
// @ts-ignore
entityId: this._chartData?.datasets[index]?.label,
});
},
};
}

Expand Down

0 comments on commit 2624cb3

Please sign in to comment.