scichart
Version:
Fast WebGL JavaScript Charting Library and Framework
87 lines (86 loc) • 4.92 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextureAxisRenderer = void 0;
var AxisRenderer_1 = require("./AxisRenderer");
/**
* AxisRenderer subclass that uses canvas texture rendering (drawTexture).
* Used when {@link LabelProviderBase2D.useNativeText} is false (the default).
*/
var TextureAxisRenderer = /** @class */ (function (_super) {
__extends(TextureAxisRenderer, _super);
function TextureAxisRenderer() {
return _super !== null && _super.apply(this, arguments) || this;
}
/** @inheritDoc */
TextureAxisRenderer.prototype.onBeginDrawLabels = function (renderContext, labelProvider, labelStyle) {
// Texture path does not use native font line height
return 0;
};
/** @inheritDoc */
TextureAxisRenderer.prototype.drawSingleLabel = function (renderContext, labelProvider, labelText, labelInfo, xCoord, yCoord, tickCoord, labelWidth, labelHeight, index, labelStyle, clipRect, isHorizontal) {
var viewRect = this.currentViewRect;
var _a = labelInfo
? { bitmapTexture: labelInfo.bitmapTexture, textureHeight: labelInfo.textureHeight, textureWidth: labelInfo.textureWidth }
: labelProvider.getCachedLabelTexture(labelText, this.textureManager, labelStyle), bitmapTexture = _a.bitmapTexture, textureHeight = _a.textureHeight, textureWidth = _a.textureWidth;
if (bitmapTexture) {
renderContext.resetAndClip(clipRect);
var _b = labelProvider.adjustLabel(index, labelText, labelWidth, labelHeight, xCoord + viewRect.left, yCoord + viewRect.top, 0, 0, 0), x = _b.x, y = _b.y;
renderContext.drawTexture(bitmapTexture, Math.round(x), Math.round(y), textureWidth, textureHeight);
if (!labelProvider.useCache) {
bitmapTexture.delete();
}
}
};
/** @inheritDoc */
TextureAxisRenderer.prototype.measureModifierAxisLabel = function (_renderContext, displayValue, textStyle, fill, effectivePadding, cornerRadius) {
this.cachedModifierAxisLabelTexture = this.textureManager.createSimpleTextTexture(displayValue, __assign(__assign({}, textStyle), { padding: effectivePadding }), fill, undefined, undefined, undefined, cornerRadius);
return {
textureWidth: this.cachedModifierAxisLabelTexture.textureWidth,
textureHeight: this.cachedModifierAxisLabelTexture.textureHeight
};
};
/** @inheritDoc */
TextureAxisRenderer.prototype.drawModifierAxisLabelSpecific = function (renderContext, displayValue, textStyle, fill, effectivePadding, cornerRadius, xPosition, yPosition, textureWidth, textureHeight, _clipRect) {
var _a;
if (!this.cachedModifierAxisLabelTexture) {
this.cachedModifierAxisLabelTexture = this.textureManager.createSimpleTextTexture(displayValue, __assign(__assign({}, textStyle), { padding: effectivePadding }), fill, undefined, undefined, undefined, cornerRadius);
}
if ((_a = this.cachedModifierAxisLabelTexture) === null || _a === void 0 ? void 0 : _a.bitmapTexture) {
renderContext.drawTexture(this.cachedModifierAxisLabelTexture.bitmapTexture, Math.round(xPosition), Math.round(yPosition), textureWidth, textureHeight);
this.cachedModifierAxisLabelTexture.bitmapTexture.delete();
}
this.cachedModifierAxisLabelTexture = undefined;
};
/** @inheritDoc */
TextureAxisRenderer.prototype.onEndDrawLabels = function () {
// No cleanup needed for texture path
};
return TextureAxisRenderer;
}(AxisRenderer_1.AxisRenderer));
exports.TextureAxisRenderer = TextureAxisRenderer;