scichart 3.1.329 → 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.
@@ -26,10 +26,6 @@ export declare class ChartTitleRenderer extends TitleRendererBase<TChartTitleSty
26
26
  */
27
27
  draw(renderContext: WebGlRenderContext2D): void;
28
28
  protected getTitleTexture(): import("../Visuals/TextureManager/TextureManager").TTextureObject;
29
- /**
30
- * Calculates width and hight of the title text
31
- */
32
- protected getTextSize(title: string | string[], textStyle: TChartTitleStyle, renderContext: WebGlRenderContext2D): void;
33
29
  /**
34
30
  * Calculates the {@link ChartTitleRenderer.titleOffset}
35
31
  */
@@ -29,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.ChartTitleRenderer = void 0;
30
30
  var Thickness_1 = require("../../Core/Thickness");
31
31
  var TextStyle_1 = require("../../types/TextStyle");
32
- var text_1 = require("../../utils/text");
33
32
  var SciChartSurfaceBase_1 = require("../Visuals/SciChartSurfaceBase");
34
33
  var TitleRenderer_1 = require("./TitleRenderer");
35
34
  /**
@@ -60,12 +59,15 @@ var ChartTitleRenderer = /** @class */ (function (_super) {
60
59
  var shouldUpdateTextSize = title !== this.text ||
61
60
  !(0, TextStyle_1.areEqualTextStyles)(originalTextStyle, this.originalTextStyle) ||
62
61
  ((_a = this.originalTextStyle) === null || _a === void 0 ? void 0 : _a.position) !== originalTextStyle.position;
63
- this.text = title;
64
- if (title) {
65
- if (!this.useCache || !this.texture || shouldUpdateTextSize) {
62
+ if (title && title.length > 0) {
63
+ if (!this.useCache || (!this.texture && !originalTextStyle.useNativeText) || shouldUpdateTextSize) {
66
64
  // recalculate cached text size info or texture
65
+ this.invalidateCache();
66
+ this.text = title;
67
67
  this.originalTextStyle = __assign({}, originalTextStyle);
68
68
  this.textStyle = (0, TextStyle_1.adjustTextStyle)(originalTextStyle);
69
+ this.useNativeTextProperty = originalTextStyle.useNativeText;
70
+ this.titlePosition = originalTextStyle.position;
69
71
  this.getTextSize(title, this.textStyle, renderContext);
70
72
  }
71
73
  else {
@@ -81,7 +83,7 @@ var ChartTitleRenderer = /** @class */ (function (_super) {
81
83
  * @param chartViewRect - the container area which is used as an origin for title layout calculation
82
84
  */
83
85
  ChartTitleRenderer.prototype.layout = function (chartViewRect) {
84
- if (!this.text) {
86
+ if (!this.text || this.text.length === 0) {
85
87
  this.viewRectProperty = undefined;
86
88
  return;
87
89
  }
@@ -91,14 +93,14 @@ var ChartTitleRenderer = /** @class */ (function (_super) {
91
93
  * Performs rendering of the title
92
94
  */
93
95
  ChartTitleRenderer.prototype.draw = function (renderContext) {
94
- if (!this.text) {
96
+ if (!this.text || this.text.length === 0) {
95
97
  return;
96
98
  }
97
99
  if (SciChartSurfaceBase_1.DebugForDpi) {
98
100
  console.log("ChartTitleRenderer.draw fontSize: ".concat(this.textStyle.fontSize));
99
101
  }
100
102
  var _a = this.textStyle, useNativeText = _a.useNativeText, position = _a.position, lineSpacing = _a.lineSpacing;
101
- this.drawInternal(renderContext, useNativeText, position, lineSpacing);
103
+ this.drawInternal(renderContext, useNativeText, position);
102
104
  if (this.drawDebug) {
103
105
  this.drawTitleDebugViewRect(renderContext);
104
106
  }
@@ -113,7 +115,6 @@ var ChartTitleRenderer = /** @class */ (function (_super) {
113
115
  else if (position === TextStyle_1.ETitlePosition.Right) {
114
116
  adjRotation += 90;
115
117
  }
116
- // TODO try using rotation property here
117
118
  var titleText = Array.isArray(this.text) ? this.text : this.text.split("\n");
118
119
  var texture = this.textureManager.createTextTexture(titleText,
119
120
  // @ts-ignore mismatch with TTextStyle
@@ -122,39 +123,11 @@ var ChartTitleRenderer = /** @class */ (function (_super) {
122
123
  adjRotation, this.textStyle.lineSpacing);
123
124
  return texture;
124
125
  };
125
- /**
126
- * Calculates width and hight of the title text
127
- */
128
- ChartTitleRenderer.prototype.getTextSize = function (title, textStyle, renderContext) {
129
- if (title === void 0) { title = ""; }
130
- var hasHorizontalPlacement = (0, TextStyle_1.getIsHorizontalPlacement)(textStyle.position);
131
- if (textStyle.useNativeText) {
132
- // @ts-ignore mismatch with TTextStyle
133
- var nativeFont = renderContext.getFont(textStyle, !hasHorizontalPlacement);
134
- var titleString = Array.isArray(title) ? title.join("\n") : title;
135
- var _a = (0, text_1.getNativeTextSize)(titleString, nativeFont, textStyle, this.webAssemblyContext), textHeight = _a.textHeight, textWidth = _a.textWidth, nativeLineSpacing = _a.nativeLineSpacing, firstLineAscent = _a.firstLineAscent;
136
- this.textHeight = textHeight;
137
- this.textWidth = textWidth;
138
- this.nativeLineSpacing = nativeLineSpacing;
139
- this.firstLineAscent = firstLineAscent;
140
- this.desiredHeightProperty = hasHorizontalPlacement ? this.textHeight : this.textWidth;
141
- this.desiredWidthProperty = hasHorizontalPlacement ? this.textWidth : this.textHeight;
142
- }
143
- else {
144
- // current title texture doesn't include paddings, so they should be added here
145
- var texture = this.getTitleTexture();
146
- this.texture = texture;
147
- this.desiredHeightProperty = texture.textureHeight;
148
- this.desiredWidthProperty = texture.textureWidth;
149
- this.textHeight = hasHorizontalPlacement ? this.desiredHeightProperty : this.desiredWidthProperty;
150
- this.textWidth = hasHorizontalPlacement ? this.desiredWidthProperty : this.desiredHeightProperty;
151
- }
152
- };
153
126
  /**
154
127
  * Calculates the {@link ChartTitleRenderer.titleOffset}
155
128
  */
156
129
  ChartTitleRenderer.prototype.getTitleOffset = function (title, textStyle) {
157
- if (!title || textStyle.placeWithinChart) {
130
+ if (!this.text || this.text.length === 0 || textStyle.placeWithinChart) {
158
131
  return Thickness_1.Thickness.fromNumber(0);
159
132
  }
160
133
  var height = this.textHeight;
@@ -28,7 +28,7 @@ export declare class TitleRendererBase<TextStyleType extends TTextStyle | TChart
28
28
  /**
29
29
  * Current title
30
30
  */
31
- text: string | string[];
31
+ protected text: string | string[];
32
32
  protected viewRectProperty: Rect;
33
33
  protected webAssemblyContext: TSciChart;
34
34
  protected textureManager: TextureManager;
@@ -65,6 +65,8 @@ export declare class TitleRendererBase<TextStyleType extends TTextStyle | TChart
65
65
  protected nativeLineSpacing: number;
66
66
  /** The height of the first line above baseline for native text, calculated during measure*/
67
67
  protected firstLineAscent: number;
68
+ protected useNativeTextProperty: boolean;
69
+ protected titlePosition: ETitlePosition;
68
70
  constructor(webAssemblyContext: TSciChart);
69
71
  measure(...params: any[]): void;
70
72
  layout(originRect: Rect): void;
@@ -76,9 +78,14 @@ export declare class TitleRendererBase<TextStyleType extends TTextStyle | TChart
76
78
  /**
77
79
  * Performs rendering of the title
78
80
  */
79
- protected drawInternal(renderContext: WebGlRenderContext2D, useNativeText: boolean, titlePosition: ETitlePosition, lineSpacing: number): void;
81
+ protected drawInternal(renderContext: WebGlRenderContext2D, useNativeText: boolean, titlePosition: ETitlePosition): void;
80
82
  protected drawWithNativeText(renderContext: WebGlRenderContext2D, position: ETitlePosition): void;
81
83
  protected drawWithTexture(renderContext: WebGlRenderContext2D, titlePosition: ETitlePosition): void;
84
+ /**
85
+ * Calculates width and hight of the title text
86
+ */
87
+ protected getTextSize(title: string | string[], textStyle: TChartTitleStyle, renderContext: WebGlRenderContext2D): void;
88
+ protected getTitleTexture(): TTextureObject;
82
89
  /**
83
90
  * Calculates the {@link TitleRenderer.viewRect}
84
91
  */
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TitleRendererBase = void 0;
4
+ var app_1 = require("../../constants/app");
4
5
  var Deleter_1 = require("../../Core/Deleter");
5
6
  var Rect_1 = require("../../Core/Rect");
6
7
  var TextPosition_1 = require("../../types/TextPosition");
7
8
  var TextStyle_1 = require("../../types/TextStyle");
8
9
  var parseColor_1 = require("../../utils/parseColor");
10
+ var text_1 = require("../../utils/text");
9
11
  var createNativeRect_1 = require("../Visuals/Helpers/createNativeRect");
10
12
  var NativeObject_1 = require("../Visuals/Helpers/NativeObject");
11
13
  var DpiHelper_1 = require("../Visuals/TextureManager/DpiHelper");
@@ -31,6 +33,7 @@ var TitleRendererBase = /** @class */ (function () {
31
33
  * The width taken by the text considering current orientation orientation including padding
32
34
  */
33
35
  this.desiredWidthProperty = 0;
36
+ this.useNativeTextProperty = false;
34
37
  this.webAssemblyContext = webAssemblyContext;
35
38
  this.textureManager = new TextureManager_1.TextureManager(webAssemblyContext);
36
39
  this.onDpiChanged = this.onDpiChanged.bind(this);
@@ -66,12 +69,11 @@ var TitleRendererBase = /** @class */ (function () {
66
69
  };
67
70
  TitleRendererBase.prototype.resetCache = function () {
68
71
  this.invalidateCache();
72
+ this.textStyle = undefined;
73
+ this.originalTextStyle = undefined;
69
74
  };
70
75
  TitleRendererBase.prototype.invalidateCache = function () {
71
76
  var _a;
72
- this.text = undefined;
73
- this.textStyle = undefined;
74
- this.originalTextStyle = undefined;
75
77
  (0, Deleter_1.deleteSafe)((_a = this.texture) === null || _a === void 0 ? void 0 : _a.bitmapTexture);
76
78
  this.texture = undefined;
77
79
  };
@@ -81,8 +83,8 @@ var TitleRendererBase = /** @class */ (function () {
81
83
  /**
82
84
  * Performs rendering of the title
83
85
  */
84
- TitleRendererBase.prototype.drawInternal = function (renderContext, useNativeText, titlePosition, lineSpacing) {
85
- if (!this.text) {
86
+ TitleRendererBase.prototype.drawInternal = function (renderContext, useNativeText, titlePosition) {
87
+ if (!this.text || this.text.length === 0) {
86
88
  return;
87
89
  }
88
90
  if (useNativeText) {
@@ -138,12 +140,69 @@ var TitleRendererBase = /** @class */ (function () {
138
140
  }
139
141
  }
140
142
  };
143
+ /**
144
+ * Calculates width and hight of the title text
145
+ */
146
+ TitleRendererBase.prototype.getTextSize = function (title, textStyle, renderContext) {
147
+ if (title === void 0) { title = ""; }
148
+ if (!title || title.length === 0) {
149
+ this.desiredHeightProperty = 0;
150
+ this.desiredWidthProperty = 0;
151
+ this.textHeight = 0;
152
+ this.textWidth = 0;
153
+ return;
154
+ }
155
+ var hasHorizontalPlacement = (0, TextStyle_1.getIsHorizontalPlacement)(this.titlePosition);
156
+ if (this.useNativeTextProperty) {
157
+ // @ts-ignore mismatch with TTextStyle
158
+ var nativeFont = renderContext.getFont(textStyle, !hasHorizontalPlacement);
159
+ var titleString = Array.isArray(title) ? title.join("\n") : title;
160
+ var _a = (0, text_1.getNativeTextSize)(titleString, nativeFont, textStyle, this.webAssemblyContext), textHeight = _a.textHeight, textWidth = _a.textWidth, nativeLineSpacing = _a.nativeLineSpacing, firstLineAscent = _a.firstLineAscent;
161
+ this.textHeight = textHeight;
162
+ this.textWidth = textWidth;
163
+ this.nativeLineSpacing = nativeLineSpacing;
164
+ this.firstLineAscent = firstLineAscent;
165
+ this.desiredHeightProperty = hasHorizontalPlacement ? this.textHeight : this.textWidth;
166
+ this.desiredWidthProperty = hasHorizontalPlacement ? this.textWidth : this.textHeight;
167
+ }
168
+ else {
169
+ // current title texture doesn't include paddings, so they should be added here
170
+ var texture = this.getTitleTexture();
171
+ this.texture = texture;
172
+ this.desiredHeightProperty = texture.textureHeight;
173
+ this.desiredWidthProperty = texture.textureWidth;
174
+ this.textHeight = hasHorizontalPlacement ? this.desiredHeightProperty : this.desiredWidthProperty;
175
+ this.textWidth = hasHorizontalPlacement ? this.desiredWidthProperty : this.desiredHeightProperty;
176
+ }
177
+ if (app_1.IS_TEST_ENV) {
178
+ if (hasHorizontalPlacement) {
179
+ this.desiredHeightProperty =
180
+ (0, TextureManager_1.measureTextHeight)(textStyle.fontSize) + this.textStyle.padding.top + this.textStyle.padding.bottom;
181
+ this.desiredWidthProperty = 0;
182
+ }
183
+ else {
184
+ this.desiredHeightProperty = 0;
185
+ this.desiredWidthProperty =
186
+ (0, TextureManager_1.measureTextHeight)(textStyle.fontSize) + this.textStyle.padding.top + this.textStyle.padding.bottom;
187
+ }
188
+ }
189
+ };
190
+ TitleRendererBase.prototype.getTitleTexture = function () {
191
+ // TODO this is not used at the moment; consider unifying logic for Chart Title Renderer and Axis Title Renderer
192
+ var titleText = Array.isArray(this.text) ? this.text : this.text.split("\n");
193
+ var texture = this.textureManager.createTextTexture(titleText,
194
+ // @ts-ignore mismatch with TTextStyle
195
+ this.textStyle
196
+ // { ...this.textStyle, padding: new Thickness(0, 0, 0, 0) },
197
+ );
198
+ return texture;
199
+ };
141
200
  /**
142
201
  * Calculates the {@link TitleRenderer.viewRect}
143
202
  */
144
203
  TitleRendererBase.prototype.getViewRect = function (title, originRect, titlePosition, alignment) {
145
204
  if (title === void 0) { title = ""; }
146
- if (!title) {
205
+ if (!title || title.length === 0) {
147
206
  return Rect_1.Rect.createZero();
148
207
  }
149
208
  var hasHorizontalPlacement = (0, TextStyle_1.getIsHorizontalPlacement)(titlePosition);
@@ -569,6 +569,7 @@ var AxisBase2D = /** @class */ (function (_super) {
569
569
  */
570
570
  AxisBase2D.prototype.onAttach = function (parentSurface, isXAxis, isPrimaryAxis) {
571
571
  this.parentSurface = parentSurface;
572
+ this.axisTitleRenderer.parentSurface = parentSurface;
572
573
  this.setIsXAxis(isXAxis);
573
574
  this.isPrimaryAxisProperty = isPrimaryAxis;
574
575
  };
@@ -585,7 +586,7 @@ var AxisBase2D = /** @class */ (function (_super) {
585
586
  console.log("Measure. fontSize: ".concat(this.labelStyle.fontSize, ", dpiAdjusted: ").concat(this.dpiAdjustedLabelStyle.fontSize));
586
587
  }
587
588
  this.axisRenderer.measure(this.isHorizontalAxis, this.dpiAdjustedLabelStyle, majorTickLabels, this.getTicksMaxSize(), this.labelProvider, this.drawLabels, drawTicks);
588
- this.axisTitleRenderer.measure(this.dpiAdjustedAxisTitleStyle, this.isHorizontalAxis);
589
+ this.axisTitleRenderer.measure(this.axisTitle, this.dpiAdjustedAxisTitleStyle, this.axisAlignment);
589
590
  }
590
591
  else {
591
592
  this.axisRenderer.desiredHeight = 0;
@@ -648,7 +649,6 @@ var AxisBase2D = /** @class */ (function (_super) {
648
649
  var viewTitleRect = _this.axisTitleRenderer.viewRect;
649
650
  var brush = _this.solidBrushCacheAxisBackground.newBrush(_this.backgroundColorProperty, false);
650
651
  var nativeAxisRect = void 0;
651
- var nativeTitleRect = void 0;
652
652
  // Empty space covering for axis coloring
653
653
  // let shift: number = 0;
654
654
  // let additionalSize: number = 0;
@@ -675,17 +675,11 @@ var AxisBase2D = /** @class */ (function (_super) {
675
675
  // nativeAxisRect = createNativeRect(this.webAssemblyContext2D, 0, 0 - shift, viewAxisRect.width, viewAxisRect.height + additionalSize);
676
676
  // nativeTitleRect = createNativeRect(this.webAssemblyContext2D, 0, 0 - shift, viewTitleRect.width, viewTitleRect.height + additionalSize);
677
677
  // }
678
- nativeAxisRect = (0, createNativeRect_1.createNativeRect)(_this.webAssemblyContext2D, 0, 0, viewAxisRect.width, viewAxisRect.height);
678
+ nativeAxisRect = (0, createNativeRect_1.createNativeRect)(_this.webAssemblyContext2D, 0, 0, _this.viewRect.width, _this.viewRect.height);
679
679
  if (nativeAxisRect) {
680
680
  var vecRects = (0, NativeObject_1.getVectorRectVertex)(_this.webAssemblyContext2D);
681
681
  vecRects.push_back(nativeAxisRect);
682
- renderContext.drawRects(vecRects, brush, viewAxisRect.left, viewAxisRect.top);
683
- }
684
- nativeTitleRect = (0, createNativeRect_1.createNativeRect)(_this.webAssemblyContext2D, 0, 0, viewTitleRect.width, viewTitleRect.height);
685
- if (nativeTitleRect) {
686
- var vecRects = (0, NativeObject_1.getVectorRectVertex)(_this.webAssemblyContext2D);
687
- vecRects.push_back(nativeTitleRect);
688
- renderContext.drawRects(vecRects, brush, viewTitleRect.left, viewTitleRect.top);
682
+ renderContext.drawRects(vecRects, brush, _this.viewRect.x, _this.viewRect.y);
689
683
  }
690
684
  }
691
685
  // Draw axis labels
@@ -703,7 +697,7 @@ var AxisBase2D = /** @class */ (function (_super) {
703
697
  _this.axisRenderer.drawTicks(renderContext, _this.axisAlignment, _this.isInnerAxis, tickObject.majorTickCoords, _this.offset, penForMajorTickLines, majorTickStyle);
704
698
  }
705
699
  // Draw axis title
706
- _this.axisTitleRenderer.draw(renderContext, _this.dpiAdjustedAxisTitleStyle, _this.axisAlignment, _this.parentSurface.debugRendering);
700
+ _this.axisTitleRenderer.draw(renderContext);
707
701
  if (_this.labelProvider.useNativeText && _this.parentSurface.renderNativeAxisLabelsImmediately) {
708
702
  renderContext.endFonts(true);
709
703
  }
@@ -1105,9 +1099,6 @@ var AxisBase2D = /** @class */ (function (_super) {
1105
1099
  * @inheritDoc
1106
1100
  */
1107
1101
  AxisBase2D.prototype.notifyPropertyChanged = function (propertyName) {
1108
- if (propertyName === constants_1.PROPERTY.AXIS_TITLE && this.axisTitleRenderer) {
1109
- this.axisTitleRenderer.text = this.axisTitle;
1110
- }
1111
1102
  if (propertyName === constants_1.PROPERTY.IS_XAXIS) {
1112
1103
  if (this.axisAlignmentProperty === undefined) {
1113
1104
  this.axisAlignmentProperty = this.isXAxisProperty ? AxisAlignment_1.EAxisAlignment.Bottom : AxisAlignment_1.EAxisAlignment.Right;
@@ -1,32 +1,28 @@
1
1
  import { Rect } from "../../../Core/Rect";
2
2
  import { EAxisAlignment } from "../../../types/AxisAlignment";
3
- import { TSciChart } from "../../../types/TSciChart";
4
3
  import { WebGlRenderContext2D } from "../../Drawing/WebGlRenderContext2D";
5
- import { TextureManager, TTextureObject } from "../TextureManager/TextureManager";
4
+ import { TitleRendererBase } from "../../Services/TitleRenderer";
5
+ import { SciChartSurface } from "../SciChartSurface";
6
6
  import { TTextStyle } from "./AxisCore";
7
7
  /**
8
8
  * Draws an axis title using our WebGL Rendering engine
9
9
  */
10
- export declare class AxisTitleRenderer {
11
- useCache: boolean;
12
- viewRect: Rect;
13
- text: string | string[];
10
+ export declare class AxisTitleRenderer extends TitleRendererBase<TTextStyle> {
14
11
  lineSpacing: number;
12
+ /** For internal use */
13
+ parentSurface: SciChartSurface;
15
14
  private previousText;
16
- private textStyle;
17
15
  private previousLineSpacing;
18
- private texture;
19
- private webAssemblyContext;
20
- private desiredHeightProperty;
21
- private desiredWidthProperty;
22
- private textureManager;
23
- constructor(webAssemblyContext: TSciChart);
24
- measure(textStyle: TTextStyle, isHorizontal: boolean): void;
16
+ private previousNativeTextMode;
17
+ private previousAxisAlignment;
18
+ measure(text: string | string[], textStyle: TTextStyle, axisAlignment: EAxisAlignment): void;
19
+ get useNativeText(): boolean;
20
+ set useNativeText(value: boolean);
25
21
  get desiredHeight(): number;
26
22
  set desiredHeight(value: number);
27
23
  get desiredWidth(): number;
28
24
  set desiredWidth(value: number);
29
25
  layout(rect: Rect): void;
30
- getTitleTexture(text: string | string[], textStyle: TTextStyle, textureManager: TextureManager): TTextureObject;
31
- draw(renderContext: WebGlRenderContext2D, textStyle: TTextStyle, axisAlignment: EAxisAlignment, debugRendering: boolean): void;
26
+ protected getTitleTexture(): import("../TextureManager/TextureManager").TTextureObject;
27
+ draw(renderContext: WebGlRenderContext2D): void;
32
28
  }
@@ -1,63 +1,70 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
10
8
  };
11
- return __assign.apply(this, arguments);
12
- };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
13
17
  Object.defineProperty(exports, "__esModule", { value: true });
14
18
  exports.AxisTitleRenderer = void 0;
15
- var Deleter_1 = require("../../../Core/Deleter");
16
- var Rect_1 = require("../../../Core/Rect");
17
- var Thickness_1 = require("../../../Core/Thickness");
18
- var AxisAlignment_1 = require("../../../types/AxisAlignment");
19
- var parseColor_1 = require("../../../utils/parseColor");
20
- var WebGlPen_1 = require("../../Drawing/WebGlPen");
21
- var TextureManager_1 = require("../TextureManager/TextureManager");
22
- /** @ignore */
23
- var PADDING = {
24
- // TOP: 13,
25
- // BOTTOM: 8,
26
- NO_TITLE: 0
27
- };
19
+ var LabelAlignment_1 = require("../../../types/LabelAlignment");
20
+ var TextStyle_1 = require("../../../types/TextStyle");
21
+ var TitleRenderer_1 = require("../../Services/TitleRenderer");
28
22
  /**
29
23
  * Draws an axis title using our WebGL Rendering engine
30
24
  */
31
- var AxisTitleRenderer = /** @class */ (function () {
32
- function AxisTitleRenderer(webAssemblyContext) {
33
- this.useCache = true;
34
- this.viewRect = Rect_1.Rect.createZero();
35
- this.text = "";
36
- this.lineSpacing = 1.1;
37
- this.desiredHeightProperty = 0;
38
- this.desiredWidthProperty = 0;
39
- this.webAssemblyContext = webAssemblyContext;
40
- this.textureManager = new TextureManager_1.TextureManager(webAssemblyContext);
25
+ var AxisTitleRenderer = /** @class */ (function (_super) {
26
+ __extends(AxisTitleRenderer, _super);
27
+ function AxisTitleRenderer() {
28
+ var _this = _super !== null && _super.apply(this, arguments) || this;
29
+ _this.lineSpacing = 1.1;
30
+ return _this;
41
31
  }
42
- AxisTitleRenderer.prototype.measure = function (textStyle, isHorizontal) {
43
- var _a, _b, _c, _d;
44
- var lines = Array.isArray(this.text) ? this.text.length : 1;
45
- var lineWithSpacing = lines > 1 ? 1 + this.lineSpacing * (lines - 1) : lines;
46
- if (isHorizontal) {
47
- this.desiredHeightProperty = this.text
48
- ? lineWithSpacing * (0, TextureManager_1.measureTextHeight)(textStyle.fontSize) +
49
- ((_a = textStyle === null || textStyle === void 0 ? void 0 : textStyle.padding) === null || _a === void 0 ? void 0 : _a.bottom) +
50
- ((_b = textStyle === null || textStyle === void 0 ? void 0 : textStyle.padding) === null || _b === void 0 ? void 0 : _b.top)
51
- : PADDING.NO_TITLE;
52
- }
53
- else {
54
- this.desiredWidthProperty = this.text
55
- ? lineWithSpacing * (0, TextureManager_1.measureTextHeight)(textStyle.fontSize) +
56
- ((_c = textStyle === null || textStyle === void 0 ? void 0 : textStyle.padding) === null || _c === void 0 ? void 0 : _c.left) +
57
- ((_d = textStyle === null || textStyle === void 0 ? void 0 : textStyle.padding) === null || _d === void 0 ? void 0 : _d.right)
58
- : PADDING.NO_TITLE;
32
+ AxisTitleRenderer.prototype.measure = function (text, textStyle, axisAlignment) {
33
+ if (text === void 0) { text = ""; }
34
+ this.text = text;
35
+ var shouldUpdateTextSize = !this.useCache ||
36
+ (!this.texture && !this.useNativeText) ||
37
+ this.text !== this.previousText ||
38
+ this.lineSpacing !== this.previousLineSpacing ||
39
+ axisAlignment !== this.previousAxisAlignment ||
40
+ this.previousNativeTextMode !== this.useNativeText ||
41
+ !checkAreEqualTextStyles(textStyle, this.textStyle);
42
+ if (shouldUpdateTextSize) {
43
+ this.invalidateCache();
44
+ this.previousLineSpacing = this.lineSpacing;
45
+ this.previousNativeTextMode = this.useNativeText;
46
+ this.previousAxisAlignment = axisAlignment;
47
+ this.previousText = text;
48
+ this.textStyle = textStyle;
49
+ this.titlePosition = TextStyle_1.ETitlePosition[axisAlignment];
50
+ this.textStyle = textStyle;
51
+ // @ts-ignore mismatch with TTextStyle
52
+ this.textStyle.lineSpacing = this.lineSpacing;
53
+ var renderContext = this.parentSurface.currentWebGlRenderContext;
54
+ // @ts-ignore mismatch with TTextStyle
55
+ this.getTextSize(text, this.textStyle, renderContext);
59
56
  }
60
57
  };
58
+ Object.defineProperty(AxisTitleRenderer.prototype, "useNativeText", {
59
+ get: function () {
60
+ return this.useNativeTextProperty;
61
+ },
62
+ set: function (value) {
63
+ this.useNativeTextProperty = value;
64
+ },
65
+ enumerable: false,
66
+ configurable: true
67
+ });
61
68
  Object.defineProperty(AxisTitleRenderer.prototype, "desiredHeight", {
62
69
  get: function () {
63
70
  return this.desiredHeightProperty;
@@ -79,76 +86,55 @@ var AxisTitleRenderer = /** @class */ (function () {
79
86
  configurable: true
80
87
  });
81
88
  AxisTitleRenderer.prototype.layout = function (rect) {
82
- this.viewRect = rect;
83
- };
84
- AxisTitleRenderer.prototype.getTitleTexture = function (text, textStyle, textureManager) {
85
- if (this.useCache &&
86
- this.texture &&
87
- text === this.previousText &&
88
- this.lineSpacing === this.previousLineSpacing &&
89
- checkAreEqualTextStyles(textStyle, this.textStyle)) {
90
- return this.texture;
91
- }
92
- this.previousLineSpacing = this.lineSpacing;
93
- this.previousText = text;
94
- this.textStyle = textStyle;
95
- var lines = Array.isArray(text) ? text : [text];
96
- var texture = textureManager.createTextTexture(lines, __assign(__assign({}, textStyle), { padding: new Thickness_1.Thickness(0, 0, 0, 0) }), 0, this.lineSpacing);
97
- this.texture = texture;
98
- return texture;
99
- };
100
- AxisTitleRenderer.prototype.draw = function (renderContext, textStyle, axisAlignment, debugRendering) {
101
- if (!this.text)
89
+ if (!this.text) {
90
+ this.viewRectProperty = rect;
102
91
  return;
103
- var nativeContext = renderContext.getNativeContext();
104
- var _a = this.getTitleTexture(this.text, textStyle, this.textureManager), bitmapTexture = _a.bitmapTexture, textureHeight = _a.textureHeight, textureWidth = _a.textureWidth;
105
- var padding = textStyle.padding;
106
- if (axisAlignment === AxisAlignment_1.EAxisAlignment.Top || axisAlignment === AxisAlignment_1.EAxisAlignment.Bottom) {
107
- var deltaToCenter = (this.viewRect.width - textureWidth) / 2;
108
- var xPositionCenter = this.viewRect.x + deltaToCenter;
109
- var yPosition = this.viewRect.y + (padding === null || padding === void 0 ? void 0 : padding.top);
110
- // (axisAlignment === EAxisAlignment.Bottom ? padding?.top : padding?.bottom);
111
- nativeContext.DrawTexture(bitmapTexture, Math.round(xPositionCenter), Math.round(yPosition), textureWidth, textureHeight);
112
- // for debugging width and height measure
113
- if (debugRendering) {
114
- var pen = new WebGlPen_1.WebGlPen(new this.webAssemblyContext.SCRTPen((0, parseColor_1.parseColorToUIntArgb)("Red"), 1, true));
115
- renderContext.drawRect(new Rect_1.Rect(xPositionCenter, yPosition, textureWidth, textureHeight), Rect_1.Rect.create(0, 0, 999, 999), pen);
116
- pen.delete();
117
- }
118
- // End debug
119
- }
120
- if (axisAlignment === AxisAlignment_1.EAxisAlignment.Left) {
121
- nativeContext.PushMatrix();
122
- nativeContext.Rotate(-90);
123
- var deltaToCenter = (this.viewRect.height - textureWidth) / 2;
124
- var xPositionCenter = -(this.viewRect.y + this.viewRect.height) + deltaToCenter;
125
- nativeContext.Translate(Math.round(xPositionCenter), Math.round(this.viewRect.x + (padding === null || padding === void 0 ? void 0 : padding.left)));
126
- nativeContext.DrawTexture(bitmapTexture, 0, 0, textureWidth, textureHeight);
127
- nativeContext.PopMatrix();
128
92
  }
129
- if (axisAlignment === AxisAlignment_1.EAxisAlignment.Right) {
130
- nativeContext.PushMatrix();
131
- nativeContext.Rotate(90);
132
- var deltaToCenter = (this.viewRect.height - textureWidth) / 2;
133
- var xPositionCenter = this.viewRect.y + deltaToCenter;
134
- nativeContext.Translate(Math.round(xPositionCenter), Math.round(-(this.viewRect.x + this.viewRect.width) + (padding === null || padding === void 0 ? void 0 : padding.right)));
135
- nativeContext.DrawTexture(bitmapTexture, 0, 0, textureWidth, textureHeight);
136
- nativeContext.PopMatrix();
93
+ var alignment = convertLabelAlignmentToTextAlignment(this.textStyle.alignment);
94
+ this.viewRectProperty = this.getViewRect(this.text, rect, this.titlePosition, alignment);
95
+ };
96
+ AxisTitleRenderer.prototype.getTitleTexture = function () {
97
+ var position = this.titlePosition;
98
+ var adjRotation = 0;
99
+ // let adjRotation = this.textStyle.rotation;
100
+ if (position === TextStyle_1.ETitlePosition.Left) {
101
+ adjRotation += -90;
137
102
  }
138
- if (!this.useCache) {
139
- (0, Deleter_1.deleteSafe)(bitmapTexture);
140
- this.texture = undefined;
103
+ else if (position === TextStyle_1.ETitlePosition.Right) {
104
+ adjRotation += 90;
141
105
  }
106
+ var titleText = Array.isArray(this.text) ? this.text : this.text.split("\n");
107
+ var texture = this.textureManager.createTextTexture(titleText,
108
+ // @ts-ignore mismatch with TTextStyle
109
+ this.textStyle,
110
+ // { ...this.textStyle, padding: new Thickness(0, 0, 0, 0) },
111
+ adjRotation, this.lineSpacing);
112
+ return texture;
113
+ };
114
+ AxisTitleRenderer.prototype.draw = function (renderContext) {
115
+ return this.drawInternal(renderContext, this.useNativeText, this.titlePosition);
142
116
  };
143
117
  return AxisTitleRenderer;
144
- }());
118
+ }(TitleRenderer_1.TitleRendererBase));
145
119
  exports.AxisTitleRenderer = AxisTitleRenderer;
146
120
  var checkAreEqualTextStyles = function (style1, style2) {
121
+ if (!style1 || !style2) {
122
+ return false;
123
+ }
147
124
  return (style1.color === style2.color &&
148
125
  style1.fontFamily === style2.fontFamily &&
149
126
  style1.fontSize === style2.fontSize &&
150
127
  style1.fontStyle === style2.fontStyle &&
151
128
  style1.fontWeight === style2.fontWeight &&
129
+ style1.alignment === style2.alignment &&
152
130
  style1.multilineAlignment === style2.multilineAlignment &&
153
131
  ((style1.padding === undefined && style2.padding === undefined) || style1.padding.equals(style2.padding)));
154
132
  };
133
+ // TODO consider refactoring
134
+ // helper function used to unify title renderer types & interfaces
135
+ var convertLabelAlignmentToTextAlignment = function (alignment) {
136
+ if (alignment === LabelAlignment_1.ELabelAlignment.Auto) {
137
+ return TextStyle_1.ETextAlignment.Center;
138
+ }
139
+ return TextStyle_1.ETextAlignment[alignment];
140
+ };
@@ -113,6 +113,7 @@ var pruneCache = function () {
113
113
  };
114
114
  var checkTextStyleEqual = function (style1, style2) {
115
115
  return (style1.alignment === style2.alignment &&
116
+ style1.multilineAlignment === style2.multilineAlignment &&
116
117
  style1.color === style2.color &&
117
118
  style1.fontFamily === style2.fontFamily &&
118
119
  style1.fontSize === style2.fontSize &&
@@ -225,6 +225,7 @@ export declare class SciChartSurface extends SciChartSurfaceBase {
225
225
  protected titleStyleProperty: Readonly<Required<TChartTitleStyle>>;
226
226
  protected chartTitleRendererProperty: IChartTitleRenderer;
227
227
  protected paddingProperty: Thickness;
228
+ protected currentWebGlRenderContextProperty: WebGlRenderContext2D;
228
229
  private readonly sciChartRenderer;
229
230
  private layoutManagerProperty;
230
231
  private dataLabelLayoutManagerProperty;
@@ -468,6 +469,7 @@ export declare class SciChartSurface extends SciChartSurfaceBase {
468
469
  * Gets the SciChartSurface Canvas Bottom Border
469
470
  */
470
471
  get bottomCanvasBorder(): number;
472
+ get currentWebGlRenderContext(): WebGlRenderContext2D;
471
473
  /**
472
474
  * Is being called on each render, to run animations
473
475
  * @param timeElapsed