scichart 3.0.317 → 3.1.333

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/Charting/Drawing/Pen2DCache.d.ts +1 -1
  2. package/Charting/Drawing/Pen2DCache.js +3 -2
  3. package/Charting/Services/ChartTitleRenderer.d.ts +33 -0
  4. package/Charting/Services/ChartTitleRenderer.js +149 -0
  5. package/Charting/Services/SciChartRenderer.d.ts +7 -1
  6. package/Charting/Services/SciChartRenderer.js +54 -8
  7. package/Charting/Services/TitleRenderer.d.ts +98 -0
  8. package/Charting/Services/TitleRenderer.js +249 -0
  9. package/Charting/Themes/IThemeProvider.d.ts +16 -0
  10. package/Charting/Themes/SciChartJSDarkTheme.d.ts +2 -0
  11. package/Charting/Themes/SciChartJSDarkTheme.js +2 -0
  12. package/Charting/Themes/SciChartJSLightTheme.d.ts +2 -0
  13. package/Charting/Themes/SciChartJSLightTheme.js +2 -0
  14. package/Charting/Visuals/Annotations/NativeTextAnnotation.js +1 -5
  15. package/Charting/Visuals/Annotations/SvgAnnotationBase.js +2 -1
  16. package/Charting/Visuals/Axis/AxisBase2D.js +7 -16
  17. package/Charting/Visuals/Axis/AxisCore.d.ts +9 -1
  18. package/Charting/Visuals/Axis/AxisRenderer.js +2 -2
  19. package/Charting/Visuals/Axis/AxisTitleRenderer.d.ts +14 -13
  20. package/Charting/Visuals/Axis/AxisTitleRenderer.js +102 -90
  21. package/Charting/Visuals/Axis/LabelProvider/LabelCache.js +1 -0
  22. package/Charting/Visuals/Axis/LabelProvider/LabelProviderBase2D.d.ts +5 -12
  23. package/Charting/Visuals/Axis/LabelProvider/LabelProviderBase2D.js +8 -55
  24. package/Charting/Visuals/Axis/LabelProvider/TextLabelProvider.d.ts +0 -1
  25. package/Charting/Visuals/Axis/LabelProvider/TextLabelProvider.js +0 -60
  26. package/Charting/Visuals/I2DSurfaceOptions.d.ts +9 -0
  27. package/Charting/Visuals/RenderableSeries/FastColumnRenderableSeries.d.ts +2 -2
  28. package/Charting/Visuals/RenderableSeries/FastColumnRenderableSeries.js +2 -2
  29. package/Charting/Visuals/SciChartDefaults.d.ts +2 -3
  30. package/Charting/Visuals/SciChartDefaults.js +2 -3
  31. package/Charting/Visuals/SciChartSurface.d.ts +31 -0
  32. package/Charting/Visuals/SciChartSurface.js +108 -6
  33. package/Charting/Visuals/TextureManager/DpiHelper.js +1 -1
  34. package/Charting/Visuals/TextureManager/TextureManager.js +34 -19
  35. package/Charting3D/Visuals/SciChart3DSurface.js +6 -2
  36. package/Core/BuildStamp.d.ts +1 -1
  37. package/Core/BuildStamp.js +2 -2
  38. package/_wasm/scichart.browser.js +1 -1
  39. package/_wasm/scichart2d.js +1 -1
  40. package/_wasm/scichart2d.wasm +0 -0
  41. package/_wasm/scichart3d.js +7 -7
  42. package/_wasm/scichart3d.wasm +0 -0
  43. package/constants/app.js +2 -1
  44. package/index.d.ts +14 -1
  45. package/index.js +21 -12
  46. package/index.min.js +1 -1
  47. package/package.json +1 -1
  48. package/types/NumberArray.js +2 -1
  49. package/types/TextStyle.d.ts +97 -0
  50. package/types/TextStyle.js +86 -0
  51. package/utils/text.d.ts +8 -1
  52. package/utils/text.js +23 -1
  53. package/Charting/Services/Workers/TextureWorker.d.ts +0 -16
  54. package/Charting/Services/Workers/TextureWorker.js +0 -142
  55. package/Charting/Services/Workers/TextureWorkerSource.d.ts +0 -1
  56. package/Charting/Services/Workers/TextureWorkerSource.js +0 -133
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "scichart",
3
3
  "description": "Fast WebGL JavaScript Charting Library and Framework",
4
4
  "homepage": "https://www.scichart.com",
5
- "version": "3.0.317",
5
+ "version": "3.1.333",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "keywords": [
@@ -6,6 +6,7 @@ function isTypedArray(a) {
6
6
  }
7
7
  exports.isTypedArray = isTypedArray;
8
8
  function isNumberArray(a) {
9
- return Array.isArray(a) && !a.some(function (arrayItem) { return typeof arrayItem !== "number"; });
9
+ // Check type is an array, and first element is number
10
+ return Array.isArray(a) && (a.length > 0 ? typeof a[0] === "number" : true);
10
11
  }
11
12
  exports.isNumberArray = isNumberArray;
@@ -0,0 +1,97 @@
1
+ import { Thickness } from "../Core/Thickness";
2
+ import { EMultiLineAlignment } from "./TextPosition";
3
+ /**
4
+ * Defines the anchor point of a text
5
+ */
6
+ export declare enum ETextAlignment {
7
+ Center = "Center",
8
+ Left = "Left",
9
+ Right = "Right"
10
+ }
11
+ /**
12
+ * Defines a side where the chart title should be placed
13
+ */
14
+ export declare enum ETitlePosition {
15
+ Top = "Top",
16
+ Bottom = "Bottom",
17
+ Right = "Right",
18
+ Left = "Left"
19
+ }
20
+ /**
21
+ * Defines common properties of text to render
22
+ */
23
+ export declare type TTextStyleBase = {
24
+ fontSize?: number;
25
+ fontFamily?: string;
26
+ color?: string;
27
+ /**
28
+ * Line spacing to use if text is wrapped.
29
+ * This is a multiple of the line height and defaults to 1.1
30
+ */
31
+ lineSpacing?: number;
32
+ padding?: Thickness;
33
+ };
34
+ /**
35
+ * Defines properties of text rendered via Native Text API
36
+ */
37
+ export declare type TNativeTextStyle = TTextStyleBase & {
38
+ useNativeText: true;
39
+ };
40
+ /**
41
+ * Defines properties of text rendered as a texture
42
+ */
43
+ export declare type TTextureTextStyle = TTextStyleBase & {
44
+ useNativeText?: false;
45
+ fontWeight?: string;
46
+ fontStyle?: string;
47
+ };
48
+ /**
49
+ * Defines text style which allows to switch between Native / Non-native text rendering
50
+ */
51
+ export declare type TCommonTextStyle = TNativeTextStyle | TTextureTextStyle;
52
+ export declare type TAdvancedTextProperties = {
53
+ /** Horizontal text alignment for multiline text. */
54
+ multilineAlignment?: EMultiLineAlignment;
55
+ };
56
+ /**
57
+ * Defines text style with advanced options
58
+ */
59
+ export declare type TAdvancedTextStyle = TCommonTextStyle & TAdvancedTextProperties;
60
+ /**
61
+ * Defines text style and positioning options used for Chart Title rendering
62
+ */
63
+ export declare type TChartTitleStyle = TAdvancedTextStyle & {
64
+ /**
65
+ * Defines a side where the title should be placed.
66
+ * @remarks
67
+ * {@link ETitlePosition.left} rotates the text clockwise by 90 degrees,
68
+ * while {@link ETitlePosition.Right} rotates the text counterclockwise by 90 degrees
69
+ */
70
+ position?: ETitlePosition;
71
+ /**
72
+ * Defines an anchor of the title relative to text
73
+ * @remarks
74
+ * the alignment directions are rotated accordingly to {@link TChartTitleStyle.position}
75
+ */
76
+ alignment?: ETextAlignment;
77
+ /**
78
+ * Defines whether title should be inside or outside of the series drawing area
79
+ */
80
+ placeWithinChart?: boolean;
81
+ };
82
+ /** @ignore */
83
+ export declare const getIsHorizontalPlacement: (position: ETitlePosition) => boolean;
84
+ /** @ignore */
85
+ export declare const handleInvalidChartTitlePosition: (invalidValue: never) => never;
86
+ /** @ignore */
87
+ export declare const handleInvalidTextAlignment: (invalidValue: never) => never;
88
+ /** @ignore */
89
+ export declare const areEqualTextureTextStyles: (style1: TTextureTextStyle, style2: TTextureTextStyle) => boolean;
90
+ /** @ignore */
91
+ export declare const areEqualNativeTextStyles: (style1: TNativeTextStyle, style2: TNativeTextStyle) => boolean;
92
+ /** @ignore */
93
+ export declare const areEqualSimpleTextStyles: (style1: TCommonTextStyle, style2: TCommonTextStyle) => boolean;
94
+ /** @ignore */
95
+ export declare const areEqualTextStyles: (style1: TAdvancedTextStyle, style2: TAdvancedTextStyle) => boolean;
96
+ /** @ignore */
97
+ export declare const adjustTextStyle: (textStyle: TCommonTextStyle) => TCommonTextStyle;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adjustTextStyle = exports.areEqualTextStyles = exports.areEqualSimpleTextStyles = exports.areEqualNativeTextStyles = exports.areEqualTextureTextStyles = exports.handleInvalidTextAlignment = exports.handleInvalidChartTitlePosition = exports.getIsHorizontalPlacement = exports.ETitlePosition = exports.ETextAlignment = void 0;
4
+ var DpiHelper_1 = require("../Charting/Visuals/TextureManager/DpiHelper");
5
+ /**
6
+ * Defines the anchor point of a text
7
+ */
8
+ var ETextAlignment;
9
+ (function (ETextAlignment) {
10
+ ETextAlignment["Center"] = "Center";
11
+ ETextAlignment["Left"] = "Left";
12
+ ETextAlignment["Right"] = "Right";
13
+ })(ETextAlignment = exports.ETextAlignment || (exports.ETextAlignment = {}));
14
+ /**
15
+ * Defines a side where the chart title should be placed
16
+ */
17
+ var ETitlePosition;
18
+ (function (ETitlePosition) {
19
+ ETitlePosition["Top"] = "Top";
20
+ ETitlePosition["Bottom"] = "Bottom";
21
+ ETitlePosition["Right"] = "Right";
22
+ ETitlePosition["Left"] = "Left";
23
+ })(ETitlePosition = exports.ETitlePosition || (exports.ETitlePosition = {}));
24
+ /** @ignore */
25
+ var getIsHorizontalPlacement = function (position) {
26
+ return position === ETitlePosition.Top || position === ETitlePosition.Bottom;
27
+ };
28
+ exports.getIsHorizontalPlacement = getIsHorizontalPlacement;
29
+ /** @ignore */
30
+ var handleInvalidChartTitlePosition = function (invalidValue) {
31
+ throw new Error("Invalid chart title position: ".concat(invalidValue, "!"));
32
+ };
33
+ exports.handleInvalidChartTitlePosition = handleInvalidChartTitlePosition;
34
+ /** @ignore */
35
+ var handleInvalidTextAlignment = function (invalidValue) {
36
+ throw new Error("Invalid text alignment \"".concat(invalidValue, "\"!"));
37
+ };
38
+ exports.handleInvalidTextAlignment = handleInvalidTextAlignment;
39
+ /** @ignore */
40
+ var areEqualTextureTextStyles = function (style1, style2) {
41
+ return (style1.color === style2.color &&
42
+ style1.fontFamily === style2.fontFamily &&
43
+ style1.fontSize === style2.fontSize &&
44
+ style1.fontStyle === style2.fontStyle &&
45
+ style1.fontWeight === style2.fontWeight &&
46
+ style1.lineSpacing === style2.lineSpacing &&
47
+ ((style1.padding === undefined && style2.padding === undefined) || style1.padding.equals(style2.padding)));
48
+ };
49
+ exports.areEqualTextureTextStyles = areEqualTextureTextStyles;
50
+ /** @ignore */
51
+ var areEqualNativeTextStyles = function (style1, style2) {
52
+ return (style1.color === style2.color &&
53
+ style1.fontFamily === style2.fontFamily &&
54
+ style1.fontSize === style2.fontSize &&
55
+ style1.lineSpacing === style2.lineSpacing &&
56
+ ((style1.padding === undefined && style2.padding === undefined) || style1.padding.equals(style2.padding)));
57
+ };
58
+ exports.areEqualNativeTextStyles = areEqualNativeTextStyles;
59
+ /** @ignore */
60
+ var areEqualSimpleTextStyles = function (style1, style2) {
61
+ if (!style1 || !style2 || !style1.useNativeText !== !style2.useNativeText) {
62
+ // comparing to an undefined style or styles have different rendering methods
63
+ return false;
64
+ }
65
+ else if (style1.useNativeText && style2.useNativeText) {
66
+ return (0, exports.areEqualNativeTextStyles)(style1, style2);
67
+ }
68
+ else {
69
+ return (0, exports.areEqualTextureTextStyles)(style1, style2);
70
+ }
71
+ };
72
+ exports.areEqualSimpleTextStyles = areEqualSimpleTextStyles;
73
+ /** @ignore */
74
+ var areEqualTextStyles = function (style1, style2) {
75
+ var areBasePropertiesEqual = (0, exports.areEqualSimpleTextStyles)(style1, style2);
76
+ return (areBasePropertiesEqual &&
77
+ // style1.rotation === style2.rotation &&
78
+ style1.multilineAlignment === style2.multilineAlignment);
79
+ };
80
+ exports.areEqualTextStyles = areEqualTextStyles;
81
+ /** @ignore */
82
+ var adjustTextStyle = function (textStyle) {
83
+ var adjustedTextStyle = DpiHelper_1.DpiHelper.adjustTextStyle(textStyle);
84
+ return adjustedTextStyle;
85
+ };
86
+ exports.adjustTextStyle = adjustTextStyle;
package/utils/text.d.ts CHANGED
@@ -1,5 +1,12 @@
1
- import { SCRTFont, TSRTextBounds } from "../types/TSciChart";
1
+ import { TNativeTextStyle } from "../types/TextStyle";
2
+ import { SCRTFont, TSciChart, TSRTextBounds } from "../types/TSciChart";
2
3
  /**
3
4
  * Wrap a string by adding newline characters, splitting on spaces and wrapping to a maximum size
4
5
  */
5
6
  export declare const wrapNativeText: (text: string, maxWidth: number, font: SCRTFont, textBounds: TSRTextBounds) => string;
7
+ export declare const getNativeTextSize: (text: string, nativeFont: SCRTFont, textStyle: TNativeTextStyle, webAssemblyContext: TSciChart) => {
8
+ textHeight: number;
9
+ textWidth: number;
10
+ nativeLineSpacing: number;
11
+ firstLineAscent: number;
12
+ };
package/utils/text.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapNativeText = void 0;
3
+ exports.getNativeTextSize = exports.wrapNativeText = void 0;
4
+ var NativeObject_1 = require("../Charting/Visuals/Helpers/NativeObject");
4
5
  /**
5
6
  * Wrap a string by adding newline characters, splitting on spaces and wrapping to a maximum size
6
7
  */
@@ -46,3 +47,24 @@ var wrapNativeText = function (text, maxWidth, font, textBounds) {
46
47
  return lines.join("\n");
47
48
  };
48
49
  exports.wrapNativeText = wrapNativeText;
50
+ var getNativeTextSize = function (text, nativeFont, textStyle, webAssemblyContext) {
51
+ var textBounds = (0, NativeObject_1.getTextBounds)(webAssemblyContext);
52
+ nativeFont.CalculateStringBounds(text, textBounds, 0);
53
+ var maxLineHeight = 0;
54
+ for (var i = 0; i < textBounds.GetLinesCount(); i++) {
55
+ var lineBounds = textBounds.GetLineBounds(i);
56
+ var lineHeight = lineBounds.m_fHeight - lineBounds.m_fOffsetY;
57
+ if (maxLineHeight < lineHeight) {
58
+ maxLineHeight = lineHeight;
59
+ }
60
+ }
61
+ var nativeLineSpacing = Math.round(maxLineHeight * (textStyle.lineSpacing - 1));
62
+ var textHeight = Math.round(textBounds.m_fHeight +
63
+ (textBounds.GetLinesCount() - 1) * nativeLineSpacing +
64
+ textStyle.padding.top +
65
+ textStyle.padding.bottom);
66
+ var textWidth = Math.round(textBounds.m_fWidth + textStyle.padding.left + textStyle.padding.right);
67
+ var firstLineAscent = textBounds.GetLineBounds(0).m_fHeight;
68
+ return { textHeight: textHeight, textWidth: textWidth, nativeLineSpacing: nativeLineSpacing, firstLineAscent: firstLineAscent };
69
+ };
70
+ exports.getNativeTextSize = getNativeTextSize;
@@ -1,16 +0,0 @@
1
- import { TTextStyle } from "../../Visuals/Axis/AxisCore";
2
- declare class TextureWorkerWrapper {
3
- private readonly worker;
4
- private timeout;
5
- private isActiveProperty;
6
- constructor();
7
- get isActive(): boolean;
8
- measureAndGetImageData(text: string[], textStyle: TTextStyle, rotation?: number, lineSpacing?: number, backgroundColor?: string, opacity?: number): Promise<{
9
- imageData: ImageData;
10
- textureWidth: number;
11
- textureHeight: number;
12
- }>;
13
- private makeWorker;
14
- }
15
- export declare const textureWorker: TextureWorkerWrapper;
16
- export {};
@@ -1,142 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.textureWorker = void 0;
40
- var app_1 = require("../../../constants/app");
41
- var resolves = {};
42
- var rejects = {};
43
- var globalMsgId = 0;
44
- // Activate calculation in the worker, returning a promise
45
- function sendMsg(payload, worker, method) {
46
- var msgId = globalMsgId++;
47
- var msg = {
48
- id: msgId,
49
- payload: payload,
50
- method: method
51
- };
52
- return new Promise(function (resolve, reject) {
53
- // save callbacks for later
54
- resolves[msgId] = resolve;
55
- rejects[msgId] = reject;
56
- worker.postMessage(msg);
57
- });
58
- }
59
- // Handle incoming calculation result
60
- function handleMsg(msg) {
61
- var _a = msg.data, id = _a.id, err = _a.err, payload = _a.payload;
62
- if (payload) {
63
- var resolve = resolves[id];
64
- if (resolve) {
65
- resolve(payload);
66
- }
67
- }
68
- else {
69
- // error condition
70
- var reject = rejects[id];
71
- if (reject) {
72
- if (err) {
73
- reject(err);
74
- }
75
- else {
76
- reject("Got nothing");
77
- }
78
- }
79
- }
80
- // purge used callbacks
81
- delete resolves[id];
82
- delete rejects[id];
83
- }
84
- // Wrapper class
85
- var TextureWorkerWrapper = /** @class */ (function () {
86
- function TextureWorkerWrapper() {
87
- var _this = this;
88
- this.timeout = 200;
89
- this.isActiveProperty = true;
90
- if (!app_1.IS_TEST_ENV &&
91
- typeof window !== "undefined" &&
92
- !!window.Worker &&
93
- // @ts-ignore
94
- typeof OffscreenCanvas !== "undefined") {
95
- this.worker = this.makeWorker(); // new Worker("./TextureWorkerSource.ts", { type: "module" });
96
- this.worker.onmessage = handleMsg;
97
- this.worker.onerror = function (ev) {
98
- console.warn("Label Worker could not be started", ev);
99
- _this.isActiveProperty = false;
100
- };
101
- }
102
- else {
103
- this.isActiveProperty = false;
104
- }
105
- }
106
- Object.defineProperty(TextureWorkerWrapper.prototype, "isActive", {
107
- get: function () {
108
- return this.isActiveProperty;
109
- },
110
- enumerable: false,
111
- configurable: true
112
- });
113
- TextureWorkerWrapper.prototype.measureAndGetImageData = function (text, textStyle, rotation, lineSpacing, backgroundColor, opacity) {
114
- return __awaiter(this, void 0, void 0, function () {
115
- var payload, result;
116
- return __generator(this, function (_a) {
117
- switch (_a.label) {
118
- case 0:
119
- if (!this.isActiveProperty) {
120
- return [2 /*return*/, Promise.reject("Worker is inactive")];
121
- }
122
- payload = { text: text, textStyle: textStyle, rotation: rotation, lineSpacing: lineSpacing, backgroundColor: backgroundColor, opacity: opacity };
123
- return [4 /*yield*/, sendMsg(payload, this.worker)];
124
- case 1:
125
- result = _a.sent();
126
- return [2 /*return*/, result];
127
- }
128
- });
129
- });
130
- };
131
- TextureWorkerWrapper.prototype.makeWorker = function () {
132
- var blobURL = URL.createObjectURL(new Blob([
133
- "\n var DEFAULT_HEIGHT = 1080;\n var DEFAULT_WIDTH = 1920;\n var ELabelAlignment;\n (function (ELabelAlignment) {\n ELabelAlignment[\"Auto\"] = \"Auto\";\n ELabelAlignment[\"Left\"] = \"Left\";\n ELabelAlignment[\"Right\"] = \"Right\";\n ELabelAlignment[\"Center\"] = \"Center\";\n })(ELabelAlignment || (ELabelAlignment = {}));\n var canvas = new OffscreenCanvas(DEFAULT_WIDTH, DEFAULT_HEIGHT);\n var ctx = canvas.getContext(\"2d\");\n var createTextTexture = function (text, textStyle, rotation, lineSpacing, backgroundColor, opacity) {\n var fontStyle = textStyle.fontStyle, fontWeight = textStyle.fontWeight, fontFamily = textStyle.fontFamily, fontSizePx = textStyle.fontSize, padding = textStyle.padding, alignment = textStyle.alignment, color = textStyle.color;\n ctx.globalAlpha = opacity !== null && opacity !== void 0 ? opacity : 1;\n ctx.textBaseline = \"top\";\n ctx.fillStyle = color;\n ctx.font = getFontString(fontStyle, fontWeight, fontSizePx, fontFamily);\n var textureWidth = 0;\n // const fontSizePt = Math.ceil(fontSizePx * PX_TO_PT);\n var lineHeight = measureTextHeight(fontSizePx);\n var extraLineHeight = lineHeight * (lineSpacing !== null && lineSpacing !== void 0 ? lineSpacing : 1.1);\n var textureHeight = lineHeight + padding.top + padding.bottom;\n for (var index = 0; index < text.length; index++) {\n var line = text[index];\n var lineWidth = measureTextWidth(line) + padding.left + padding.right;\n if (lineWidth > textureWidth) {\n textureWidth = lineWidth;\n }\n if (index > 0) {\n textureHeight += extraLineHeight;\n }\n }\n var y = padding.top;\n var x = padding.left;\n if (!textureWidth || !textureHeight) {\n return undefined;\n }\n var newTextureWidth = textureWidth;\n var newTextureHeight = textureHeight;\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n if (backgroundColor) {\n ctx.fillStyle = backgroundColor;\n ctx.fillRect(0, 0, canvas.width, canvas.height);\n }\n // Save state\n ctx.save();\n if (rotation) {\n // convert to radians\n var rotationRad = (rotation * Math.PI) / 180;\n // We need to Math.ceil to fix rotation for WebGL1\n newTextureWidth = Math.ceil(textureWidth * Math.abs(Math.cos(rotationRad)) + textureHeight * Math.abs(Math.sin(rotationRad)));\n newTextureHeight = Math.ceil(textureWidth * Math.abs(Math.sin(rotationRad)) + textureHeight * Math.abs(Math.cos(rotationRad)));\n // translate to the center of rectangle\n ctx.translate(newTextureWidth / 2, newTextureHeight / 2);\n ctx.rotate(rotationRad);\n // translate to the new origin that is located in the left top center of the texture\n ctx.translate(-textureWidth / 2, -textureHeight / 2);\n }\n for (var _i = 0, text_1 = text; _i < text_1.length; _i++) {\n var line = text_1[_i];\n if (alignment === ELabelAlignment.Center || alignment === ELabelAlignment.Right) {\n var lineWidth = measureTextWidth(line);\n x =\n alignment === ELabelAlignment.Right\n ? textureWidth - lineWidth - padding.right\n : (textureWidth - lineWidth) / 2;\n }\n ctx.fillText(line, Math.round(x), Math.round(y));\n y += extraLineHeight;\n }\n ctx.strokeStyle = color;\n ctx.restore();\n var imageData = ctx.getImageData(0, 0, newTextureWidth, newTextureHeight);\n return {\n imageData: imageData,\n textureWidth: newTextureWidth,\n textureHeight: newTextureHeight\n };\n };\n var measureTextHeight = function (fontSizePx) { return fontSizePx; };\n var measureTextWidth = function (text) {\n var textMeasure = ctx.measureText(text);\n return Math.ceil(textMeasure.width);\n };\n var getFontString = function (fontStyle, fontWeight, fontSize, fontFamily) {\n if (!fontWeight)\n return fontStyle + \" \" + fontSize + \"px \" + fontFamily;\n return fontStyle + \" \" + fontWeight + \" \" + fontSize + \"px \" + fontFamily;\n };\n self.onmessage = function (msg) {\n var _a = msg.data, id = _a.id, payload = _a.payload, method = _a.method;\n var text = payload.text, textStyle = payload.textStyle, rotation = payload.rotation, lineSpacing = payload.lineSpacing, backgroundColor = payload.backgroundColor, opacity = payload.opacity;\n try {\n var result = createTextTexture(text, textStyle, rotation, lineSpacing, backgroundColor, opacity);\n var reply = {\n id: id,\n payload: result\n };\n self.postMessage(reply);\n }\n catch (err) {\n self.postMessage({\n id: id,\n err: err,\n payload: undefined\n });\n }\n };"
134
- ], { type: "application/javascript" }));
135
- var worker = new Worker(blobURL);
136
- // Won't be needing this anymore
137
- URL.revokeObjectURL(blobURL);
138
- return worker;
139
- };
140
- return TextureWorkerWrapper;
141
- }());
142
- exports.textureWorker = new TextureWorkerWrapper();
@@ -1 +0,0 @@
1
- export {};
@@ -1,133 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /** @ignore */
4
- var DEFAULT_HEIGHT = 1080;
5
- /** @ignore */
6
- var DEFAULT_WIDTH = 1920;
7
- var ELabelAlignment;
8
- (function (ELabelAlignment) {
9
- ELabelAlignment["Auto"] = "Auto";
10
- ELabelAlignment["Left"] = "Left";
11
- ELabelAlignment["Right"] = "Right";
12
- ELabelAlignment["Center"] = "Center";
13
- })(ELabelAlignment || (ELabelAlignment = {}));
14
- // @ts-ignore
15
- var canvas = new OffscreenCanvas(DEFAULT_WIDTH, DEFAULT_HEIGHT);
16
- // @ts-ignore
17
- var ctx = canvas.getContext("2d");
18
- /**
19
- * Create a text texture supporting multiline and arbitrary rotation
20
- * @param text
21
- * @param textStyle
22
- * @param rotation
23
- * @param lineSpacing Expressed as a fraction of the font size. Default 1.1
24
- * @param backgroundColor
25
- * @param opacity
26
- * @returns
27
- */
28
- // tslint:disable-next-line: no-unused-expression
29
- var createTextTexture = function (text, textStyle, rotation, lineSpacing, backgroundColor, opacity) {
30
- var fontStyle = textStyle.fontStyle, fontWeight = textStyle.fontWeight, fontFamily = textStyle.fontFamily, fontSizePx = textStyle.fontSize, padding = textStyle.padding, alignment = textStyle.alignment, color = textStyle.color;
31
- // console.log("Creating label for", text[0], fontSizePx);
32
- ctx.globalAlpha = opacity !== null && opacity !== void 0 ? opacity : 1;
33
- ctx.textBaseline = "top";
34
- ctx.fillStyle = color;
35
- ctx.font = getFontString(fontStyle, fontWeight, fontSizePx, fontFamily);
36
- var textureWidth = 0;
37
- // const fontSizePt = Math.ceil(fontSizePx * PX_TO_PT);
38
- var lineHeight = measureTextHeight(fontSizePx);
39
- var extraLineHeight = lineHeight * (lineSpacing !== null && lineSpacing !== void 0 ? lineSpacing : 1.1);
40
- var textureHeight = lineHeight + padding.top + padding.bottom;
41
- for (var index = 0; index < text.length; index++) {
42
- var line = text[index];
43
- var lineWidth = measureTextWidth(line) + padding.left + padding.right;
44
- if (lineWidth > textureWidth) {
45
- textureWidth = lineWidth;
46
- }
47
- if (index > 0) {
48
- textureHeight += extraLineHeight;
49
- }
50
- }
51
- var y = padding.top;
52
- var x = padding.left;
53
- if (!textureWidth || !textureHeight) {
54
- return undefined;
55
- }
56
- var newTextureWidth = textureWidth;
57
- var newTextureHeight = textureHeight;
58
- ctx.clearRect(0, 0, canvas.width, canvas.height);
59
- if (backgroundColor) {
60
- ctx.fillStyle = backgroundColor;
61
- ctx.fillRect(0, 0, canvas.width, canvas.height);
62
- }
63
- // Save state
64
- ctx.save();
65
- if (rotation) {
66
- // convert to radians
67
- var rotationRad = (rotation * Math.PI) / 180;
68
- // We need to Math.ceil to fix rotation for WebGL1
69
- newTextureWidth = Math.ceil(textureWidth * Math.abs(Math.cos(rotationRad)) + textureHeight * Math.abs(Math.sin(rotationRad)));
70
- newTextureHeight = Math.ceil(textureWidth * Math.abs(Math.sin(rotationRad)) + textureHeight * Math.abs(Math.cos(rotationRad)));
71
- // translate to the center of rectangle
72
- ctx.translate(newTextureWidth / 2, newTextureHeight / 2);
73
- ctx.rotate(rotationRad);
74
- // translate to the new origin that is located in the left top center of the texture
75
- ctx.translate(-textureWidth / 2, -textureHeight / 2);
76
- }
77
- for (var _i = 0, text_1 = text; _i < text_1.length; _i++) {
78
- var line = text_1[_i];
79
- if (alignment === ELabelAlignment.Center || alignment === ELabelAlignment.Right) {
80
- var lineWidth = measureTextWidth(line);
81
- x =
82
- alignment === ELabelAlignment.Right
83
- ? textureWidth - lineWidth - padding.right
84
- : (textureWidth - lineWidth) / 2;
85
- }
86
- ctx.fillText(line, Math.round(x), Math.round(y));
87
- y += extraLineHeight;
88
- }
89
- ctx.strokeStyle = color;
90
- ctx.restore();
91
- // Useful for debugging rotated textures
92
- // ctx.beginPath();
93
- // ctx.rect(0, 0, newTextureWidth, newTextureHeight);
94
- // ctx.stroke();
95
- var imageData = ctx.getImageData(0, 0, newTextureWidth, newTextureHeight);
96
- // console.log("Returning label for", text[0], fontSizePx);
97
- return {
98
- imageData: imageData,
99
- textureWidth: newTextureWidth,
100
- textureHeight: newTextureHeight
101
- };
102
- };
103
- var measureTextHeight = function (fontSizePx) { return fontSizePx; };
104
- // @ts-ignore
105
- var measureTextWidth = function (text) {
106
- var textMeasure = ctx.measureText(text);
107
- return Math.ceil(textMeasure.width);
108
- };
109
- var getFontString = function (fontStyle, fontWeight, fontSize, fontFamily) {
110
- if (!fontWeight)
111
- return "".concat(fontStyle, " ").concat(fontSize, "px ").concat(fontFamily);
112
- return "".concat(fontStyle, " ").concat(fontWeight, " ").concat(fontSize, "px ").concat(fontFamily);
113
- };
114
- // Handle incoming messages
115
- self.onmessage = function (msg) {
116
- var _a = msg.data, id = _a.id, payload = _a.payload, method = _a.method;
117
- var text = payload.text, textStyle = payload.textStyle, rotation = payload.rotation, lineSpacing = payload.lineSpacing, backgroundColor = payload.backgroundColor, opacity = payload.opacity;
118
- try {
119
- var result = createTextTexture(text, textStyle, rotation, lineSpacing, backgroundColor, opacity);
120
- var reply = {
121
- id: id,
122
- payload: result
123
- };
124
- self.postMessage(reply);
125
- }
126
- catch (err) {
127
- self.postMessage({
128
- id: id,
129
- err: err,
130
- payload: undefined
131
- });
132
- }
133
- };