-
Notifications
You must be signed in to change notification settings - Fork 32
/
chart_scorecard.ts
36 lines (30 loc) · 1.25 KB
/
chart_scorecard.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Component, useEffect, useRef } from "@odoo/owl";
import { drawScoreChart } from "../../../../helpers/figures/charts/scorecard_chart";
import { getScorecardConfiguration } from "../../../../helpers/figures/charts/scorecard_chart_config_builder";
import { Figure, SpreadsheetChildEnv } from "../../../../types";
import { ScorecardChartRuntime } from "../../../../types/chart/scorecard_chart";
interface Props {
figure: Figure;
}
export class ScorecardChart extends Component<Props, SpreadsheetChildEnv> {
static template = "o-spreadsheet-ScorecardChart";
private canvas = useRef("chartContainer");
get runtime(): ScorecardChartRuntime {
return this.env.model.getters.getChartRuntime(this.props.figure.id) as ScorecardChartRuntime;
}
setup() {
useEffect(this.createChart.bind(this), () => {
const canvas = this.canvas.el as HTMLCanvasElement;
const rect = canvas.getBoundingClientRect();
return [rect.width, rect.height, this.runtime, this.canvas.el];
});
}
private createChart() {
const canvas = this.canvas.el as HTMLCanvasElement;
const config = getScorecardConfiguration(canvas.getBoundingClientRect(), this.runtime);
drawScoreChart(config, canvas);
}
}
ScorecardChart.props = {
figure: Object,
};