@visactor/vtable
Version:
canvas table width high performance
93 lines (85 loc) • 5.23 kB
JavaScript
;
var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
void 0 === k2 && (k2 = k);
var desc = Object.getOwnPropertyDescriptor(m, k);
desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
enumerable: !0,
get: function() {
return m[k];
}
}), Object.defineProperty(o, k2, desc);
} : function(o, m, k, k2) {
void 0 === k2 && (k2 = k), o[k2] = m[k];
}), __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function(o, v) {
Object.defineProperty(o, "default", {
enumerable: !0,
value: v
});
} : function(o, v) {
o.default = v;
}), __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;
}, __importStar = this && this.__importStar || function(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (null != mod) for (var k in mod) "default" !== k && Object.prototype.hasOwnProperty.call(mod, k) && __createBinding(result, mod, k);
return __setModuleDefault(result, mod), result;
};
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.ImageDrawItemInterceptorContribution = exports.VTableDrawItemInterceptorContribution = void 0;
const vrender_1 = require("./../../../vrender"), icons = __importStar(require("../../../icons")), keep_aspect_ratio_1 = require("../../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([ (0, vrender_1.injectable)() ], VTableDrawItemInterceptorContribution),
exports.VTableDrawItemInterceptorContribution = VTableDrawItemInterceptorContribution;
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 = (0, vrender_1.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} = (0, keep_aspect_ratio_1.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;
}
}
exports.ImageDrawItemInterceptorContribution = ImageDrawItemInterceptorContribution;
//# sourceMappingURL=draw-interceptor.js.map