UNPKG

@visactor/vtable

Version:

canvas table width high performance

67 lines (59 loc) 3.87 kB
var __decorate = this && this.__decorate || function(decorators, target, key, desc) { var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc; if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) (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 { injectable, createImage } from "./../../../vrender"; import * as icons from "../../../icons"; import { calcKeepAspectRatioSize } from "../../utils/keep-aspect-ratio"; let loadingImage, VTableDrawItemInterceptorContribution = class { constructor() { this.order = 1, this.interceptors = [ new ImageDrawItemInterceptorContribution ]; } afterDrawItem(graphic, renderService, drawContext, drawContribution, params) { for (let i = 0; i < this.interceptors.length; i++) if (this.interceptors[i].afterDrawItem && this.interceptors[i].afterDrawItem(graphic, renderService, drawContext, drawContribution, params)) return !0; return !1; } beforeDrawItem(graphic, renderService, drawContext, drawContribution, params) { if ((!graphic.in3dMode || drawContext.in3dInterceptor) && !graphic.shadowRoot && !(graphic.baseGraphic || graphic.attribute.globalZIndex || graphic.interactiveGraphic)) return !1; for (let i = 0; i < this.interceptors.length; i++) if (this.interceptors[i].beforeDrawItem && this.interceptors[i].beforeDrawItem(graphic, renderService, drawContext, drawContribution, params)) return !0; return !1; } }; VTableDrawItemInterceptorContribution = __decorate([ injectable() ], VTableDrawItemInterceptorContribution); export { VTableDrawItemInterceptorContribution }; export class ImageDrawItemInterceptorContribution { constructor() { this.order = 1; } afterDrawItem(graphic, renderService, drawContext, drawContribution, params) { return "image" === graphic.type && this.drawItem(graphic, renderService, drawContext, drawContribution, params), !1; } drawItem(graphic, renderService, drawContext, drawContribution, params) { const {image: url, gif: gif} = graphic.attribute; if (gif && graphic.playing) return !1; if (!url || !graphic.resources) return !1; const res = graphic.resources.get(url); if (!res || "loading" !== res.state) return !1; if (!loadingImage) { const regedIcons = icons.get(), svg = regedIcons.loading_pic.svg, width = regedIcons.loading_pic.width, height = regedIcons.loading_pic.height; loadingImage = createImage({ width: width, height: height, image: svg }); } const {image: loadingUrl} = loadingImage.attribute; if (!url || !loadingImage.resources) return !1; const loadingRes = loadingImage.resources.get(loadingUrl); if ("success" !== loadingRes.state) return !1; const {context: context} = drawContext; context.highPerformanceSave(), graphic.parent && context.setTransformFromMatrix(graphic.parent.globalTransMatrix, !0), graphic.glyphHost && graphic.glyphHost.parent && context.setTransformFromMatrix(graphic.glyphHost.parent.globalTransMatrix, !0); const b = graphic.AABBBounds, {width: width, height: height} = calcKeepAspectRatioSize(loadingRes.data.width, loadingRes.data.height, b.width(), b.height()); return context.drawImage(loadingRes.data, b.x1 + (b.width() - width) / 2, b.y1 + (b.height() - height) / 2, width, height), context.highPerformanceRestore(), !0; } } //# sourceMappingURL=draw-interceptor.js.map