UNPKG

@amcharts/amcharts5

Version:
61 lines 2.44 kB
import { Entity } from "../../util/Entity"; /** * Base class for patterns. * * @see {@link https://www.amcharts.com/docs/v5/concepts/colors-gradients-and-patterns/patterns/} for more info */ export class Pattern extends Entity { constructor() { super(...arguments); this._display = this._root._renderer.makeGraphics(); this._backgroundDisplay = this._root._renderer.makeGraphics(); this._clear = false; } _afterNew() { // Applying themes because pattern will not have parent super._afterNewApplyThemes(); } get pattern() { return this._pattern; } _draw() { } _beforeChanged() { super._beforeChanged(); if (this.isDirty("repetition") || this.isDirty("width") || this.isDirty("height") || this.isDirty("rotation") || this.isDirty("strokeWidth") || this.isDirty("strokeDasharray") || this.isDirty("strokeDashoffset") || this.isDirty("colorOpacity") || this.isDirty("fillOpacity")) { this._clear = true; } this._checkDirtyFill(); } _checkDirtyFill() { if (this.isDirty("color") || this.isDirty("fill")) { this._clear = true; } } _changed() { super._changed(); if (this._clear) { const repetition = this.get("repetition", ""); const width = this.get("width", 100); const height = this.get("height", 100); const fill = this.get("fill"); const fillOpacity = this.get("fillOpacity", 1); const backgroundDisplay = this._backgroundDisplay; const display = this._display; display.clear(); backgroundDisplay.clear(); if (fill && (fillOpacity > 0)) { backgroundDisplay.beginFill(fill, fillOpacity); backgroundDisplay.drawRect(0, 0, width, height); backgroundDisplay.endFill(); } display.angle = this.get("rotation", 0); //display.pivot = { x: width / 2, y: height / 2 }; this._draw(); this._pattern = this._root._renderer.createPattern(display, backgroundDisplay, repetition, width, height); } this._clear = false; } } Pattern.className = "Pattern"; Pattern.classNames = Entity.classNames.concat([Pattern.className]); //# sourceMappingURL=Pattern.js.map