UNPKG

webwriter-chart

Version:

ww-chart is an interactive data visualization widget for the WebWriter tool that implements various charts and diagrams for static and exploratory data visualization.

67 lines (66 loc) 2.84 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { customElement, state } from "lit/decorators.js"; import Chart from "chart.js/auto"; import { ChartHelper, getContext, updateData } from "../functions"; import { GenericChart } from "../GenericChart"; import { OptionDefinition } from "./definition"; import { addAlphaToRGB } from "../../../functions"; let PolarChart = class PolarChart extends GenericChart { constructor() { super(OptionDefinition); } #chartHelper_accessor_storage; get chartHelper() { return this.#chartHelper_accessor_storage; } set chartHelper(value) { this.#chartHelper_accessor_storage = value; } //TODO: This is exactly the same as in Doughnut.ts updated() { if (!this.chartHelper) return; const datasets = this.prepareDataset(); this.chartHelper.setTitle(this.label); this.chartHelper.setXLabels(this.datasets.labels); updateData(datasets, this.chartHelper.chart.data.datasets); this.chartHelper.update(); } //TODO: besides the "polarArea", its exactly the same as in Doughnut.ts firstUpdated() { const datasets = this.prepareDataset(); const ctx = getContext(this); const chart = new Chart(ctx, { type: "polarArea", data: { labels: this.datasets.labels, datasets: datasets, }, }); this.chartHelper = new ChartHelper("polarArea", chart); this.chartHelper.setTitle(this.label); this.chartHelper.update(); } //TODO: This is exactly the same as in Doughnut.ts prepareDataset() { const result = this.datasets.sets.map((dataset) => { return { label: dataset.name, data: dataset.data, backgroundColor: dataset.colors.map((color) => addAlphaToRGB(color, this.options.filled ? 1 : 0.2)), borderColor: dataset.colors, borderWidth: this.options.borderWidth ?? 1, borderRadius: this.options.borderRadius ?? 0, }; }); return result; } }; __decorate([ state() ], PolarChart.prototype, "chartHelper", null); PolarChart = __decorate([ customElement("polar-chart") ], PolarChart); export { PolarChart };