From 5bd005a032dd666242bb97b97fb565befbc7cd18 Mon Sep 17 00:00:00 2001 From: Hao Wu Date: Wed, 11 Sep 2024 23:47:28 -0700 Subject: [PATCH] Add `chartLayout` getter to query chart values. This allows users to access the `google.visualization.ChartLayoutInterface` for the chart. This is useful for getting the position and size of chart elements, such as the legend or title. --- google-chart.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/google-chart.ts b/google-chart.ts index cf240ae..65e6ee2 100644 --- a/google-chart.ts +++ b/google-chart.ts @@ -346,6 +346,19 @@ export class GoogleChart extends LitElement { */ private chartWrapper: google.visualization.ChartWrapper|null = null; + /** + * Returns the google.visualization.ChartLayoutInterface for the chart. + * + * Call this on the core chart and only after the chart is drawn + * (`google-chart-ready` event). + */ + get chartLayout() { + if (this.chartWrapper == null) return null; + const chart = this.chartWrapper.getChart(); + return chart && + (chart as google.visualization.CoreChartBase).getChartLayoutInterface(); + } + private redrawTimeoutId: number|undefined = undefined; protected override render() {