123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- var Definable = require("./Definable");
- var zrUtil = require("../../core/util");
- var matrix = require("../../core/matrix");
- function ClippathManager(zrId, svgRoot) {
- Definable.call(this, zrId, svgRoot, 'clipPath', '__clippath_in_use__');
- }
- zrUtil.inherits(ClippathManager, Definable);
- ClippathManager.prototype.update = function (displayable) {
- var svgEl = this.getSvgElement(displayable);
- if (svgEl) {
- this.updateDom(svgEl, displayable.__clipPaths, false);
- }
- var textEl = this.getTextSvgElement(displayable);
- if (textEl) {
-
-
- this.updateDom(textEl, displayable.__clipPaths, true);
- }
- this.markUsed(displayable);
- };
- ClippathManager.prototype.updateDom = function (parentEl, clipPaths, isText) {
- if (clipPaths && clipPaths.length > 0) {
-
- var defs = this.getDefs(true);
- var clipPath = clipPaths[0];
- var clipPathEl;
- var id;
- var dom = isText ? '_textDom' : '_dom';
- if (clipPath[dom]) {
-
- id = clipPath[dom].getAttribute('id');
- clipPathEl = clipPath[dom];
- if (!defs.contains(clipPathEl)) {
-
-
- defs.appendChild(clipPathEl);
- }
- } else {
-
- id = 'zr' + this._zrId + '-clip-' + this.nextId;
- ++this.nextId;
- clipPathEl = this.createElement('clipPath');
- clipPathEl.setAttribute('id', id);
- defs.appendChild(clipPathEl);
- clipPath[dom] = clipPathEl;
- }
- var svgProxy = this.getSvgProxy(clipPath);
- if (clipPath.transform && clipPath.parent.invTransform && !isText) {
-
-
- var transform = Array.prototype.slice.call(clipPath.transform);
- matrix.mul(clipPath.transform, clipPath.parent.invTransform, clipPath.transform);
- svgProxy.brush(clipPath);
- clipPath.transform = transform;
- } else {
- svgProxy.brush(clipPath);
- }
- var pathEl = this.getSvgElement(clipPath);
- clipPathEl.innerHTML = '';
-
- clipPathEl.appendChild(pathEl.cloneNode());
- parentEl.setAttribute('clip-path', 'url(#' + id + ')');
- if (clipPaths.length > 1) {
-
- this.updateDom(clipPathEl, clipPaths.slice(1), isText);
- }
- } else {
-
- if (parentEl) {
- parentEl.setAttribute('clip-path', 'none');
- }
- }
- };
- ClippathManager.prototype.markUsed = function (displayable) {
- var that = this;
- if (displayable.__clipPaths) {
- zrUtil.each(displayable.__clipPaths, function (clipPath) {
- if (clipPath._dom) {
- Definable.prototype.markUsed.call(that, clipPath._dom);
- }
- if (clipPath._textDom) {
- Definable.prototype.markUsed.call(that, clipPath._textDom);
- }
- });
- }
- };
- var _default = ClippathManager;
- module.exports = _default;
|