UNPKG

preact-chartist

Version:
78 lines (77 loc) 2.52 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var ChartistBaseChart_exports = {}; __export(ChartistBaseChart_exports, { default: () => ChartistBaseChart_default }); module.exports = __toCommonJS(ChartistBaseChart_exports); var import_preact = require("preact"); class ChartistBaseChart extends import_preact.Component { Component = (...args) => { }; type = "Base"; baseCSSClassName = "ChartistBaseChart"; chart = (0, import_preact.createRef)(); componentWillUnmount() { if (this.chartist) { this.chartist.detach(); } } componentDidMount() { this.updateChart(this.props); } componentDidUpdate() { this.updateChart(this.props); } updateChart(config) { let { data } = config; let options = config.options || {}; let responsiveOptions = config.responsiveOptions || []; let event; if (this.chartist) { this.chartist.update(data, options, responsiveOptions); } else { this.chartist = new this.Component(this.chart.current, data, options, responsiveOptions); if (config.listener) { for (event in config.listener) { if (config.listener.hasOwnProperty(event)) { this.chartist.on(event, config.listener[event]); } } } } return this.chartist; } render() { const { className, style, children, data } = this.props; const childrenWithProps = (children || []).map((child) => (0, import_preact.cloneElement)(child, { type: this.type, data })); return /* @__PURE__ */ (0, import_preact.h)( "div", { className: `${this.baseCSSClassName} ${className || ""}`, ref: this.chart, style }, childrenWithProps ); } } var ChartistBaseChart_default = ChartistBaseChart;