PageSourceSearch

https://swh.de/assets/@symfony/ux-chartjs/controller-Gcnh5ai.js

js swh.de collected 2026-09-24 11:20:57 UTC 2,002 bytes, 63 lines download raw bytes

1import { Controller } from "@hotwired/stimulus";
2import { Chart, registerables } from "chart.js";
3if (registerables) Chart.register(...registerables);
4let isChartInitialized = false;
5var _Class = class extends Controller {
6	constructor(..._args) {
7		super(..._args);
8		this.chart = null;
9	}
10	connect() {
11		if (!isChartInitialized) {
12			isChartInitialized = true;
13			this.dispatchEvent("init", { Chart });
14		}
15		if (!(this.element instanceof HTMLCanvasElement)) throw new Error("Invalid element");
16		const payload = this.viewValue;
17		if (Array.isArray(payload.options) && 0 === payload.options.length) payload.options = {};
18		this.dispatchEvent("pre-connect", {
19			options: payload.options,
20			config: payload
21		});
22		const canvasContext = this.element.getContext("2d");
23		if (!canvasContext) throw new Error("Could not getContext() from Element");
24		this.chart = new Chart(canvasContext, payload);
25		this.dispatchEvent("connect", { chart: this.chart });
26	}
27	disconnect() {
28		this.dispatchEvent("disconnect", { chart: this.chart });
29		if (this.chart) {
30			this.chart.destroy();
31			this.chart = null;
32		}
33	}
34	viewValueChanged() {
35		if (this.chart) {
36			const viewValue = {
37				data: this.viewValue.data,
38				options: this.viewValue.options
39			};
40			if (Array.isArray(viewValue.options) && 0 === viewValue.options.length) viewValue.options = {};
41			this.dispatchEvent("view-value-change", viewValue);
42			this.chart.data = viewValue.data;
43			this.chart.options = viewValue.options;
44			this.chart.update();
45			const parentElement = this.element.parentElement;
46			if (parentElement && this.chart.options.responsive) {
47				const originalWidth = parentElement.style.width;
48				parentElement.style.width = `${parentElement.offsetWidth + 1}px`;
49				setTimeout(() => {
50					parentElement.style.width = originalWidth;
51				}, 0);
52			}
53		}
54	}
55	dispatchEvent(name, payload) {
56		this.dispatch(name, {
57			detail: payload,
58			prefix: "chartjs"
59		});
60	}
61};
62_Class.values = { view: Object };
63export { _Class as default };

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.