scichart 2.1.0-beta.40 → 2.1.2261

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 (32) hide show
  1. package/Charting/ChartModifiers/RolloverModifier.d.ts +5 -3
  2. package/Charting/ChartModifiers/RolloverModifier.js +38 -80
  3. package/Charting/Model/PointSeries/BasePointSeriesResampled.js +2 -2
  4. package/Charting/Numerics/Resamplers/ExtremeResamplerHelper.d.ts +1 -1
  5. package/Charting/Numerics/Resamplers/ExtremeResamplerHelper.js +3 -1
  6. package/Charting/Services/SciChartRenderer.js +3 -0
  7. package/Charting/Visuals/Axis/CategoryAxisBase.d.ts +51 -0
  8. package/Charting/Visuals/Axis/CategoryAxisBase.js +85 -20
  9. package/Charting/Visuals/Axis/LabelProvider/SmartDateLabelProvider.js +7 -4
  10. package/Charting/Visuals/RenderableSeries/BaseOhlcRenderableSeries.js +70 -16
  11. package/Charting/Visuals/RenderableSeries/BaseRenderableSeries.d.ts +2 -1
  12. package/Charting/Visuals/RenderableSeries/BaseRenderableSeries.js +15 -11
  13. package/Charting/Visuals/RenderableSeries/DrawingProviders/ColumnSeriesDrawingProvider.d.ts +1 -0
  14. package/Charting/Visuals/RenderableSeries/DrawingProviders/ColumnSeriesDrawingProvider.js +27 -8
  15. package/Charting/Visuals/RenderableSeries/FastBubbleRenderableSeries.d.ts +5 -0
  16. package/Charting/Visuals/RenderableSeries/FastBubbleRenderableSeries.js +12 -0
  17. package/Charting/Visuals/SciChartPieSurface/SciChartPieSurface.d.ts +1 -0
  18. package/Charting/Visuals/SciChartPieSurface/SciChartPieSurface.js +7 -2
  19. package/Charting/Visuals/licenseManager2D.js +2 -0
  20. package/Charting/Visuals/loader.js +2 -0
  21. package/Charting/Visuals/sciChartInitCommon.js +4 -0
  22. package/Core/BuildStamp.d.ts +1 -1
  23. package/Core/BuildStamp.js +2 -2
  24. package/_wasm/scichart.browser.js +1 -1
  25. package/_wasm/scichart2d.js +10 -10
  26. package/_wasm/scichart2d.wasm +0 -0
  27. package/_wasm/scichart3d.js +1 -1
  28. package/_wasm/scichart3d.wasm +0 -0
  29. package/package.json +1 -1
  30. package/types/TSciChart.d.ts +1 -0
  31. package/utils/tooltip.d.ts +42 -0
  32. package/utils/tooltip.js +119 -0
@@ -49,6 +49,7 @@ export declare type TTooltipProps = {
49
49
  isCategoryAxis: boolean;
50
50
  isY1: boolean;
51
51
  height: number;
52
+ width: number;
52
53
  seriesInfo: SeriesInfo;
53
54
  };
54
55
  /**
@@ -237,15 +238,16 @@ export declare class RolloverModifier extends ChartModifierBase2D implements IIn
237
238
  * @param pixelRatio
238
239
  * @param isY1
239
240
  */
240
- export declare const calcTooltipProps: (index: number, rs: IRenderableSeries, rolloverProps: RolloverModifierRenderableSeriesProps, seriesViewRect: Rect, xValue: number, yValue: number, absoluteXCoord: number, absoluteYCoord: number, hitTestInfo: HitTestInfo, pixelRatio: number, isY1?: boolean) => TTooltipProps;
241
+ export declare const calcTooltipProps: (index: number, rs: IRenderableSeries, rolloverProps: RolloverModifierRenderableSeriesProps, seriesViewRect: Rect, xValue: number, yValue: number, absoluteXCoord: number, absoluteYCoord: number, hitTestInfo: HitTestInfo, pixelRatio: number, isY1?: boolean, isVerticalChart?: boolean) => TTooltipProps;
241
242
  /**
242
243
  * @ignore
243
244
  * @description Used internally, calculates tooltip positions to avoid overlapping
244
245
  * @param tooltipArray
245
246
  * @param allowTooltipOverlapping
246
- * @param tooltipPaddingTop
247
+ * @param spacing
247
248
  * @param seriesViewRect
248
249
  * @param pixelRatio
250
+ * @param isVerticalChart
249
251
  */
250
- export declare const calcTooltipPositions: (tooltipArray: TTooltipProps[], allowTooltipOverlapping: boolean, tooltipPaddingTop: number, seriesViewRect: Rect, pixelRatio: number) => TTooltipProps[];
252
+ export declare const calcTooltipPositions: (tooltipArray: TTooltipProps[], allowTooltipOverlapping: boolean, spacing: number, seriesViewRect: Rect, pixelRatio: number, isVerticalChart?: boolean) => TTooltipProps[];
251
253
  export {};
@@ -20,6 +20,7 @@ var classFactory_1 = require("../../Builder/classFactory");
20
20
  var BaseType_1 = require("../../types/BaseType");
21
21
  var ChartModifierType_1 = require("../../types/ChartModifierType");
22
22
  var SeriesType_1 = require("../../types/SeriesType");
23
+ var tooltip_1 = require("../../utils/tooltip");
23
24
  var translate_1 = require("../../utils/translate");
24
25
  var AnnotationBase_1 = require("../Visuals/Annotations/AnnotationBase");
25
26
  var LineAnnotation_1 = require("../Visuals/Annotations/LineAnnotation");
@@ -50,7 +51,7 @@ var EMousePosition;
50
51
  EMousePosition["SeriesArea"] = "SeriesArea";
51
52
  })(EMousePosition || (EMousePosition = {}));
52
53
  /** @ignore */
53
- var TOOLTIP_PADDING_TOP = 4;
54
+ var TOOLTIP_SPACING = 4;
54
55
  /**
55
56
  * The RolloverModifier provides tooltip and cursor behavior on a 2D {@link SciChartSurface}
56
57
  * within SciChart - High Performance {@link https://www.scichart.com/javascript-chart-features | JavaScript Charts}
@@ -518,7 +519,7 @@ var RolloverModifier = /** @class */ (function (_super) {
518
519
  if (isVisible) {
519
520
  var absoluteXCoord = _this.isVerticalChart() ? hitTestInfo.yCoord : hitTestInfo.xCoord;
520
521
  var absoluteYCoord = _this.isVerticalChart() ? hitTestInfo.xCoord : hitTestInfo.yCoord;
521
- var tooltipProps = (0, exports.calcTooltipProps)(index, rs, rs.rolloverModifierProps, _this.parentSurface.seriesViewRect, hitTestInfo.xValue, hitTestInfo.yValue, absoluteXCoord, absoluteYCoord, hitTestInfo, DpiHelper_1.DpiHelper.PIXEL_RATIO);
522
+ var tooltipProps = (0, exports.calcTooltipProps)(index, rs, rs.rolloverModifierProps, _this.parentSurface.seriesViewRect, hitTestInfo.xValue, hitTestInfo.yValue, absoluteXCoord, absoluteYCoord, hitTestInfo, DpiHelper_1.DpiHelper.PIXEL_RATIO, false, _this.isVerticalChart());
522
523
  if (tooltipProps)
523
524
  tooltipArray.push(tooltipProps);
524
525
  }
@@ -528,7 +529,7 @@ var RolloverModifier = /** @class */ (function (_super) {
528
529
  if (isVisibleY1) {
529
530
  var absoluteXCoord = _this.isVerticalChart() ? hitTestInfo.y1Coord : hitTestInfo.xCoord;
530
531
  var absoluteYCoord = _this.isVerticalChart() ? hitTestInfo.xCoord : hitTestInfo.y1Coord;
531
- var tooltipY1Props = (0, exports.calcTooltipProps)(index, rs, rs.rolloverModifierProps1, _this.parentSurface.seriesViewRect, hitTestInfo.xValue, hitTestInfo.y1Value, absoluteXCoord, absoluteYCoord, hitTestInfo, DpiHelper_1.DpiHelper.PIXEL_RATIO, true);
532
+ var tooltipY1Props = (0, exports.calcTooltipProps)(index, rs, rs.rolloverModifierProps1, _this.parentSurface.seriesViewRect, hitTestInfo.xValue, hitTestInfo.y1Value, absoluteXCoord, absoluteYCoord, hitTestInfo, DpiHelper_1.DpiHelper.PIXEL_RATIO, true, _this.isVerticalChart());
532
533
  if (tooltipY1Props)
533
534
  tooltipArray.push(tooltipY1Props);
534
535
  }
@@ -538,7 +539,7 @@ var RolloverModifier = /** @class */ (function (_super) {
538
539
  var orderedTooltipArray = tooltipArray.sort(function (a, b) {
539
540
  return a.yCoord > b.yCoord ? 1 : b.yCoord > a.yCoord ? -1 : 0;
540
541
  });
541
- var tooltipPositions = (0, exports.calcTooltipPositions)(orderedTooltipArray, this.allowTooltipOverlapping, TOOLTIP_PADDING_TOP * DpiHelper_1.DpiHelper.PIXEL_RATIO, this.parentSurface.seriesViewRect, DpiHelper_1.DpiHelper.PIXEL_RATIO);
542
+ var tooltipPositions = (0, exports.calcTooltipPositions)(orderedTooltipArray, this.allowTooltipOverlapping, TOOLTIP_SPACING * DpiHelper_1.DpiHelper.PIXEL_RATIO, this.parentSurface.seriesViewRect, DpiHelper_1.DpiHelper.PIXEL_RATIO, this.isVerticalChart());
542
543
  tooltipPositions.forEach(function (el) {
543
544
  var rs = rsList[el.index];
544
545
  var showTooltip = _this.showTooltip && el.seriesInfo.isHit;
@@ -589,8 +590,9 @@ exports.RolloverModifier = RolloverModifier;
589
590
  * @param pixelRatio
590
591
  * @param isY1
591
592
  */
592
- var calcTooltipProps = function (index, rs, rolloverProps, seriesViewRect, xValue, yValue, absoluteXCoord, absoluteYCoord, hitTestInfo, pixelRatio, isY1) {
593
+ var calcTooltipProps = function (index, rs, rolloverProps, seriesViewRect, xValue, yValue, absoluteXCoord, absoluteYCoord, hitTestInfo, pixelRatio, isY1, isVerticalChart) {
593
594
  if (isY1 === void 0) { isY1 = false; }
595
+ if (isVerticalChart === void 0) { isVerticalChart = false; }
594
596
  var visibleRange = rs.yAxis.visibleRange;
595
597
  var isVisible = visibleRange.min <= yValue && yValue <= visibleRange.max;
596
598
  if (isVisible) {
@@ -601,13 +603,21 @@ var calcTooltipProps = function (index, rs, rolloverProps, seriesViewRect, xValu
601
603
  var scaledHeight = height * pixelRatio;
602
604
  var distTop = absoluteYCoord;
603
605
  var distBottom = seriesViewRect.height - absoluteYCoord;
606
+ var defaultVerticalShift = 5 * pixelRatio;
604
607
  var xCoordShift = seriesViewRect.width - absoluteXCoord < scaledWidth ? -width : 5;
605
- var yCoordShift = -height / 2;
606
- if (distTop < scaledHeight / 2) {
607
- yCoordShift = -distTop / pixelRatio;
608
+ var yCoordShift = isVerticalChart ? defaultVerticalShift : -height / 2;
609
+ if (isVerticalChart) {
610
+ if (distBottom < scaledHeight + defaultVerticalShift) {
611
+ yCoordShift = ((scaledHeight + defaultVerticalShift) / pixelRatio) * -1;
612
+ }
608
613
  }
609
- else if (distBottom < scaledHeight / 2) {
610
- yCoordShift = -(scaledHeight - distBottom) / pixelRatio;
614
+ else {
615
+ if (distTop < scaledHeight / 2) {
616
+ yCoordShift = -distTop / pixelRatio;
617
+ }
618
+ else if (distBottom < scaledHeight / 2) {
619
+ yCoordShift = -(scaledHeight - distBottom) / pixelRatio;
620
+ }
611
621
  }
612
622
  var newRecord = {
613
623
  index: index,
@@ -621,6 +631,7 @@ var calcTooltipProps = function (index, rs, rolloverProps, seriesViewRect, xValu
621
631
  xCoordShift: xCoordShift,
622
632
  yCoordShift: yCoordShift,
623
633
  height: scaledHeight,
634
+ width: scaledWidth,
624
635
  seriesInfo: seriesInfo
625
636
  };
626
637
  return newRecord;
@@ -628,85 +639,32 @@ var calcTooltipProps = function (index, rs, rolloverProps, seriesViewRect, xValu
628
639
  return undefined;
629
640
  };
630
641
  exports.calcTooltipProps = calcTooltipProps;
631
- /** @ignore */
632
- var spreadTooltips = function (tooltipArray, totalTooltipsHeight, startY, endY, pixelRatio) {
633
- var currentTotalPadding = endY - startY - totalTooltipsHeight;
634
- var currentPadding = currentTotalPadding / (tooltipArray.length - 1);
635
- tooltipArray.reduce(function (tooltipTopYCoord, tooltip) {
636
- tooltip.yCoordShift = (tooltipTopYCoord - tooltip.yCoord) / pixelRatio;
637
- return tooltipTopYCoord + tooltip.height + currentPadding;
638
- }, startY);
639
- };
640
642
  /**
641
643
  * @ignore
642
644
  * @description Used internally, calculates tooltip positions to avoid overlapping
643
645
  * @param tooltipArray
644
646
  * @param allowTooltipOverlapping
645
- * @param tooltipPaddingTop
647
+ * @param spacing
646
648
  * @param seriesViewRect
647
649
  * @param pixelRatio
650
+ * @param isVerticalChart
648
651
  */
649
- var calcTooltipPositions = function (tooltipArray, allowTooltipOverlapping, tooltipPaddingTop, seriesViewRect, pixelRatio) {
652
+ var calcTooltipPositions = function (tooltipArray, allowTooltipOverlapping, spacing, seriesViewRect, pixelRatio, isVerticalChart) {
653
+ if (isVerticalChart === void 0) { isVerticalChart = false; }
654
+ var positionProperties = (0, tooltip_1.getTooltipPositionProperties)(isVerticalChart);
655
+ var hasOverlap = (0, tooltip_1.checkHasOverlap)(tooltipArray, spacing, pixelRatio, positionProperties);
650
656
  var length = tooltipArray.length;
651
- if (!allowTooltipOverlapping && length >= 2) {
652
- var checkHasOverlap = function () {
653
- for (var i = 0; i < length - 1; i++) {
654
- var tooltip0 = tooltipArray[i];
655
- var scaledHeightTooltip0 = tooltip0.height;
656
- var scaledYShiftTooltip0 = tooltip0.yCoordShift * pixelRatio;
657
- var bottomYTooltip0 = tooltip0.yCoord + scaledHeightTooltip0 + scaledYShiftTooltip0;
658
- var tooltip1 = tooltipArray[i + 1];
659
- var scaledYShiftTooltip1 = tooltip1.yCoordShift * pixelRatio;
660
- var topYTooltip1 = tooltip1.yCoord + scaledYShiftTooltip1;
661
- var diff = topYTooltip1 - bottomYTooltip0;
662
- if (diff < tooltipPaddingTop)
663
- return true;
664
- }
665
- return false;
666
- };
667
- if (checkHasOverlap()) {
668
- var totalTooltipsHeight = tooltipArray.reduce(function (prev, cur) { return prev + cur.height; }, 0);
669
- var totalPadding = (length - 1) * tooltipPaddingTop;
670
- var totalTooltipsHeightWithPadding = totalTooltipsHeight + totalPadding;
671
- var notEnoughViewRectHeight = seriesViewRect.height <= totalTooltipsHeightWithPadding;
672
- if (notEnoughViewRectHeight) {
673
- var deltaYCoord = tooltipArray[length - 1].yCoord - tooltipArray[0].yCoord;
674
- var centerY = tooltipArray[0].yCoord + deltaYCoord / 2;
675
- var initialY_1 = centerY - totalTooltipsHeight / 2;
676
- tooltipArray.reduce(function (prevSum, cur, index, arr) {
677
- var sum = index === 0 ? initialY_1 : prevSum + arr[index - 1].height + tooltipPaddingTop;
678
- // need to get not scaled value
679
- cur.yCoordShift = (sum - cur.yCoord) / pixelRatio;
680
- return sum;
681
- }, 0);
682
- }
683
- else {
684
- var firstTooltip = tooltipArray[0];
685
- var lastTooltip = tooltipArray[length - 1];
686
- var startY = firstTooltip.yCoord + firstTooltip.yCoordShift * pixelRatio;
687
- var endY = lastTooltip.yCoord + lastTooltip.yCoordShift * pixelRatio + lastTooltip.height;
688
- var isEnoughHeight = endY - startY >= totalTooltipsHeightWithPadding;
689
- if (isEnoughHeight) {
690
- spreadTooltips(tooltipArray, totalTooltipsHeight, startY, endY, pixelRatio);
691
- }
692
- else {
693
- var additionalHeightNeeded = totalTooltipsHeightWithPadding - (endY - startY);
694
- var availableHeightFromStart = startY;
695
- var availableHeightFromEnd = seriesViewRect.height - endY;
696
- var newStartY = startY - additionalHeightNeeded / 2;
697
- var newEndY = endY + additionalHeightNeeded / 2;
698
- if (availableHeightFromStart < additionalHeightNeeded / 2) {
699
- newStartY = 0;
700
- newEndY = endY + (additionalHeightNeeded - availableHeightFromStart);
701
- }
702
- else if (availableHeightFromEnd < additionalHeightNeeded / 2) {
703
- newStartY = startY - (additionalHeightNeeded - availableHeightFromEnd);
704
- newEndY = seriesViewRect.height;
705
- }
706
- spreadTooltips(tooltipArray, totalTooltipsHeight, newStartY, newEndY, pixelRatio);
707
- }
708
- }
709
- }
657
+ if (!allowTooltipOverlapping && length >= 2 && hasOverlap) {
658
+ var spreadMap_1 = (0, tooltip_1.spreadTooltips)(tooltipArray, pixelRatio, positionProperties, spacing, seriesViewRect);
659
+ tooltipArray.forEach(function (tooltip) {
660
+ tooltip[positionProperties.shiftPropertyName] = spreadMap_1.get(tooltip.index);
661
+ });
662
+ }
663
+ // centering for vertical charts without overlapping
664
+ if (isVerticalChart && !hasOverlap) {
665
+ tooltipArray.forEach(function (tooltip) {
666
+ return (tooltip[positionProperties.shiftPropertyName] = -(tooltip.width / 2) / pixelRatio);
667
+ });
710
668
  }
711
669
  return tooltipArray;
712
670
  };
@@ -27,9 +27,9 @@ var BasePointSeriesResampled = /** @class */ (function () {
27
27
  * Updates SCRTDoubleVector from IntVector
28
28
  */
29
29
  BasePointSeriesResampled.prototype.updateIndexes = function () {
30
- // We are not using this.intIndexes.size() because for OHLC after calling ExtremeResamplerHelper.mergeIndexes()
31
- // it is bigger than the actual size
32
30
  var resultCount = this.count;
31
+ // console.log("resultCount", resultCount);
32
+ // console.log("this.indexes", this.indexes);
33
33
  this.indexes.resizeFast(resultCount);
34
34
  // TODO: Find an effective way to copy indexes
35
35
  for (var i = 0; i < resultCount; i++) {
@@ -38,7 +38,7 @@ export declare class ExtremeResamplerHelper implements IDeletable {
38
38
  */
39
39
  resampleIntoPointSeries(wasmContext: TSciChart, rp: ResamplingParams, xOriginalValues: SCRTDoubleVector, yOriginalValues: SCRTDoubleVector, indexesOut: IntVector, xResampledValuesOut: SCRTDoubleVector, yResampledValuesOut: SCRTDoubleVector, fillBasicNativeArgs?: boolean): void;
40
40
  mergeIndexes(indices: IntVector, size1: number, size2: number, mergedIndicesOut: IntVector): number;
41
- copyValuesByIndexes(indices: IntVector, xValues: SCRTDoubleVector, yValues: SCRTDoubleVector, y1Values: SCRTDoubleVector, count: number, isCategoryAxis: boolean, xValuesOut: SCRTDoubleVector, yValuesOut: SCRTDoubleVector, y1ValuesOut: SCRTDoubleVector): void;
41
+ copyValuesByIndexes(indices: IntVector, xValues: SCRTDoubleVector, yValues: SCRTDoubleVector, y1Values: SCRTDoubleVector, count: number, isCategoryAxis: boolean, xValuesOut: SCRTDoubleVector, yValuesOut: SCRTDoubleVector, y1ValuesOut: SCRTDoubleVector, y1Offset?: number): void;
42
42
  /** @inheritDoc */
43
43
  delete(): void;
44
44
  private debugParameters;
@@ -90,13 +90,15 @@ var ExtremeResamplerHelper = /** @class */ (function () {
90
90
  ExtremeResamplerHelper.prototype.mergeIndexes = function (indices, size1, size2, mergedIndicesOut) {
91
91
  return this.nativeResampler.MergeIndices(indices, size1, size2, mergedIndicesOut);
92
92
  };
93
- ExtremeResamplerHelper.prototype.copyValuesByIndexes = function (indices, xValues, yValues, y1Values, count, isCategoryAxis, xValuesOut, yValuesOut, y1ValuesOut) {
93
+ ExtremeResamplerHelper.prototype.copyValuesByIndexes = function (indices, xValues, yValues, y1Values, count, isCategoryAxis, xValuesOut, yValuesOut, y1ValuesOut, y1Offset) {
94
+ if (y1Offset === void 0) { y1Offset = 0; }
94
95
  var mp = this.nativeMergeIndexParams;
95
96
  mp.SetIndices(indices);
96
97
  this.xInput.SetInput(xValues);
97
98
  mp.SetXInput(this.xInput);
98
99
  mp.SetYInput(yValues);
99
100
  mp.SetY1Input(y1Values);
101
+ mp.SetY1Offset(y1Offset);
100
102
  mp.count = count;
101
103
  mp.isCategoryData = isCategoryAxis;
102
104
  mp.SetXOut(xValuesOut);
@@ -258,6 +258,9 @@ var SciChartRenderer = /** @class */ (function () {
258
258
  // TODO: Calculate XRange before resample but YRange after resample for faster autorange on large datasets
259
259
  for (var i = 0; i < this.sciChartSurface.renderableSeries.size(); i++) {
260
260
  var series = this.sciChartSurface.renderableSeries.get(i);
261
+ // don't try and draw series with no data
262
+ if (!series.isStacked && !series.dataSeries)
263
+ continue;
261
264
  // TODO: Do resampling, store result for use in drawing
262
265
  var xAxis = xAxesById.item(series.xAxisId);
263
266
  var seriesRenderPassInfo = SciChartRenderer.resampleSeries(xAxis, series, seriesViewRect);
@@ -6,11 +6,30 @@ import { AxisBase2D, IAxisBase2dOptions } from "./AxisBase2D";
6
6
  import { ILabel2DOptions } from "./LabelProvider/LabelProviderBase2D";
7
7
  export declare type TCategoryCoordCalc = CategoryCoordinateCalculator | FlippedCategoryCoordinateCalculator;
8
8
  export interface ICategoryAxisBaseOptions extends IAxisBase2dOptions, ILabel2DOptions {
9
+ /**
10
+ * The default x values to use if no series or data is added to the chart.
11
+ * The tick values shown will depend on the visible range, which for category axis is by index, not by value.
12
+ * eg if you want default values [10, 20, 30, 40] you would need to set visibleRange: new NumberRange(0,3)
13
+ * By default it will start at 0 and increment by 1, up to the size of the visible range.
14
+ * To change the start and step set defaultXStart and defaultXStep
15
+ */
16
+ defaultXValues?: number[];
17
+ /**
18
+ * The starting value for default x values. See defaultXValues
19
+ */
20
+ defaultXStart?: number;
21
+ /**
22
+ * The step size for default x values. See defaultXValues
23
+ */
24
+ defaultXStep?: number;
9
25
  }
10
26
  /**
11
27
  * @summary A 2D Chart Category Axis Base type
12
28
  */
13
29
  export declare abstract class CategoryAxisBase extends AxisBase2D {
30
+ private defaultXValuesProperty;
31
+ private defaultXStartProperty;
32
+ private defaultXStepProperty;
14
33
  /**
15
34
  * Creates an instance of a {@link CategoryAxisBase}
16
35
  * @param webAssemblyContext The {@link TSciChart | SciChart 2D WebAssembly Context} containing native methods and
@@ -22,6 +41,38 @@ export declare abstract class CategoryAxisBase extends AxisBase2D {
22
41
  * @inheritDoc
23
42
  */
24
43
  get isCategoryAxis(): boolean;
44
+ /**
45
+ * The default x values to use if no series or data is added to the chart.
46
+ * The tick values shown will depend on the visible range, which for category axis is by index, not by value.
47
+ * eg if you want default values [10, 20, 30, 40] you would need to set visibleRange: new NumberRange(0,3)
48
+ * By default it will start at 0 and increment by 1, up to the size of the visible range.
49
+ * To change the start and step set defaultXStart and defaultXStep
50
+ */
51
+ get defaultXValues(): number[];
52
+ /**
53
+ * The default x values to use if no series or data is added to the chart.
54
+ * The tick values shown will depend on the visible range, which for category axis is by index, not by value.
55
+ * eg if you want default values [10, 20, 30, 40] you would need to set visibleRange: new NumberRange(0,3)
56
+ * By default it will start at 0 and increment by 1, up to the size of the visible range.
57
+ * To change the start and step set defaultXStart and defaultXStep
58
+ */
59
+ set defaultXValues(values: number[]);
60
+ /**
61
+ * The starting value for default x values. See defaultXValues
62
+ */
63
+ get defaultXStart(): number;
64
+ /**
65
+ * The starting value for default x values. See defaultXValues
66
+ */
67
+ set defaultXStart(value: number);
68
+ /**
69
+ * The step size for default x values. See defaultXValues
70
+ */
71
+ get defaultXStep(): number;
72
+ /**
73
+ * The step size for default x values. See defaultXValues
74
+ */
75
+ set defaultXStep(value: number);
25
76
  /**
26
77
  * @inheritDoc
27
78
  */
@@ -19,6 +19,7 @@ exports.CategoryAxisBase = void 0;
19
19
  var Deleter_1 = require("../../../Core/Deleter");
20
20
  var NumberRange_1 = require("../../../Core/NumberRange");
21
21
  var SeriesType_1 = require("../../../types/SeriesType");
22
+ var appendDoubleVectorFromJsArray_1 = require("../../../utils/ccall/appendDoubleVectorFromJsArray");
22
23
  var CategoryCoordinateCalculator_1 = require("../../Numerics/CoordinateCalculators/CategoryCoordinateCalculator");
23
24
  var FlippedCategoryCoordinateCalculator_1 = require("../../Numerics/CoordinateCalculators/FlippedCategoryCoordinateCalculator");
24
25
  var NumericTickProvider_1 = require("../../Numerics/TickProviders/NumericTickProvider");
@@ -36,7 +37,14 @@ var CategoryAxisBase = /** @class */ (function (_super) {
36
37
  * @param options Optional parameters of type {@link ICategoryAxisBaseOptions} used to configure the axis at instantiation time
37
38
  */
38
39
  function CategoryAxisBase(webAssemblyContext, options) {
40
+ var _a, _b, _c;
39
41
  var _this = _super.call(this, webAssemblyContext, options) || this;
42
+ _this.defaultXValuesProperty = [];
43
+ _this.defaultXStartProperty = 0;
44
+ _this.defaultXStepProperty = 1;
45
+ _this.defaultXValuesProperty = (_a = options === null || options === void 0 ? void 0 : options.defaultXValues) !== null && _a !== void 0 ? _a : _this.defaultXValuesProperty;
46
+ _this.defaultXStartProperty = (_b = options === null || options === void 0 ? void 0 : options.defaultXStart) !== null && _b !== void 0 ? _b : _this.defaultXStartProperty;
47
+ _this.defaultXStepProperty = (_c = options === null || options === void 0 ? void 0 : options.defaultXStep) !== null && _c !== void 0 ? _c : _this.defaultXStepProperty;
40
48
  _this.tickProvider = new NumericTickProvider_1.NumericTickProvider(_this.webAssemblyContext2D);
41
49
  _this.deltaCalculator = new CategoryDeltaCalculator_1.CategoryDeltaCalculator(_this.webAssemblyContext2D);
42
50
  return _this;
@@ -51,6 +59,68 @@ var CategoryAxisBase = /** @class */ (function (_super) {
51
59
  enumerable: false,
52
60
  configurable: true
53
61
  });
62
+ Object.defineProperty(CategoryAxisBase.prototype, "defaultXValues", {
63
+ /**
64
+ * The default x values to use if no series or data is added to the chart.
65
+ * The tick values shown will depend on the visible range, which for category axis is by index, not by value.
66
+ * eg if you want default values [10, 20, 30, 40] you would need to set visibleRange: new NumberRange(0,3)
67
+ * By default it will start at 0 and increment by 1, up to the size of the visible range.
68
+ * To change the start and step set defaultXStart and defaultXStep
69
+ */
70
+ get: function () {
71
+ return this.defaultXValuesProperty;
72
+ },
73
+ /**
74
+ * The default x values to use if no series or data is added to the chart.
75
+ * The tick values shown will depend on the visible range, which for category axis is by index, not by value.
76
+ * eg if you want default values [10, 20, 30, 40] you would need to set visibleRange: new NumberRange(0,3)
77
+ * By default it will start at 0 and increment by 1, up to the size of the visible range.
78
+ * To change the start and step set defaultXStart and defaultXStep
79
+ */
80
+ set: function (values) {
81
+ this.defaultXValuesProperty = values;
82
+ if (this.invalidateParentCallback)
83
+ this.invalidateParentCallback();
84
+ },
85
+ enumerable: false,
86
+ configurable: true
87
+ });
88
+ Object.defineProperty(CategoryAxisBase.prototype, "defaultXStart", {
89
+ /**
90
+ * The starting value for default x values. See defaultXValues
91
+ */
92
+ get: function () {
93
+ return this.defaultXStartProperty;
94
+ },
95
+ /**
96
+ * The starting value for default x values. See defaultXValues
97
+ */
98
+ set: function (value) {
99
+ this.defaultXStartProperty = value;
100
+ if (this.invalidateParentCallback)
101
+ this.invalidateParentCallback();
102
+ },
103
+ enumerable: false,
104
+ configurable: true
105
+ });
106
+ Object.defineProperty(CategoryAxisBase.prototype, "defaultXStep", {
107
+ /**
108
+ * The step size for default x values. See defaultXValues
109
+ */
110
+ get: function () {
111
+ return this.defaultXStepProperty;
112
+ },
113
+ /**
114
+ * The step size for default x values. See defaultXValues
115
+ */
116
+ set: function (value) {
117
+ this.defaultXStepProperty = value;
118
+ if (this.invalidateParentCallback)
119
+ this.invalidateParentCallback();
120
+ },
121
+ enumerable: false,
122
+ configurable: true
123
+ });
54
124
  /**
55
125
  * @inheritDoc
56
126
  */
@@ -60,16 +130,6 @@ var CategoryAxisBase = /** @class */ (function (_super) {
60
130
  var coordCalc = this.getCurrentCoordinateCalculatorInternal();
61
131
  var scs = this.parentSurface;
62
132
  var renderableSeries = scs.renderableSeries.asArray().find(function (rs) { return rs.xAxisId === _this.id; });
63
- if (!renderableSeries) {
64
- throw new Error("category x axis with id=".concat(this.id, " should have renderable series"));
65
- }
66
- if (!renderableSeries.hasDataSeries()) {
67
- throw new Error("category x axis with id=".concat(this.id, " should have data series"));
68
- }
69
- var dataSeriesLength = renderableSeries.getDataSeriesValuesCount();
70
- if (dataSeriesLength === 0) {
71
- throw new Error("category x axis with id=".concat(this.id, " should have data series count > 0"));
72
- }
73
133
  this.setBaseXValues(coordCalc, renderableSeries);
74
134
  this.coordCalcCache = coordCalc;
75
135
  };
@@ -84,16 +144,6 @@ var CategoryAxisBase = /** @class */ (function (_super) {
84
144
  var shouldFlip = !(this.isXAxis !== this.flippedCoordinates);
85
145
  var scs = this.parentSurface;
86
146
  var renderableSeries = scs.renderableSeries.asArray().find(function (rs) { return rs.xAxisId === _this.id; });
87
- if (!renderableSeries) {
88
- throw new Error("category x axis with id=".concat(this.id, " should have renderable series"));
89
- }
90
- if (!renderableSeries.hasDataSeries()) {
91
- throw new Error("category x axis with id=".concat(this.id, " should have data series"));
92
- }
93
- var dataSeriesLength = renderableSeries.getDataSeriesValuesCount();
94
- if (dataSeriesLength === 0) {
95
- throw new Error("category x axis with id=".concat(this.id, " should have data series count > 0"));
96
- }
97
147
  var coordCalc = shouldFlip
98
148
  ? new FlippedCategoryCoordinateCalculator_1.FlippedCategoryCoordinateCalculator(this.webAssemblyContext2D, size, 0, 0, min, max, this.offset)
99
149
  : new CategoryCoordinateCalculator_1.CategoryCoordinateCalculator(this.webAssemblyContext2D, size, 0, 0, min, max, this.offset);
@@ -128,6 +178,21 @@ var CategoryAxisBase = /** @class */ (function (_super) {
128
178
  return Math.min(Math.max(1, this.maxAutoTicks), coordCalc.baseXValues.size());
129
179
  };
130
180
  CategoryAxisBase.prototype.setBaseXValues = function (coordCalc, renderableSeries) {
181
+ var _this = this;
182
+ if (!(renderableSeries === null || renderableSeries === void 0 ? void 0 : renderableSeries.dataSeries)) {
183
+ if (!coordCalc.baseXValues) {
184
+ var defaultBaseXValues = new this.webAssemblyContext2D.SCRTDoubleVector();
185
+ if (this.defaultXValues && this.defaultXValues.length > 0) {
186
+ (0, appendDoubleVectorFromJsArray_1.appendDoubleVectorFromJsArray)(this.webAssemblyContext2D, defaultBaseXValues, this.defaultXValues);
187
+ }
188
+ else {
189
+ var xValues = Array.from(Array(this.visibleRange.diff), function (_, i) { return _this.defaultXStart + i * _this.defaultXStep; });
190
+ (0, appendDoubleVectorFromJsArray_1.appendDoubleVectorFromJsArray)(this.webAssemblyContext2D, defaultBaseXValues, xValues);
191
+ }
192
+ coordCalc.baseXValues = defaultBaseXValues;
193
+ }
194
+ return;
195
+ }
131
196
  if (renderableSeries.type === SeriesType_1.ESeriesType.UniformHeatmapSeries) {
132
197
  throw Error("Category Axis is not supported for UniformHeatmapRenderableSeries");
133
198
  }
@@ -117,7 +117,8 @@ var SmartDateLabelProvider = /** @class */ (function (_super) {
117
117
  };
118
118
  SmartDateLabelProvider.prototype.formatTradeChartLabel = function (tradeChartLabelFormat, value, prevValue, prevPrevValue) {
119
119
  if (tradeChartLabelFormat === ETradeChartLabelFormat.Minutes) {
120
- var newDate = !prevValue || (0, date_1.formatUnixDateToHumanStringMMMDD)(value) !== (0, date_1.formatUnixDateToHumanStringMMMDD)(prevValue);
120
+ var newDate = prevValue === undefined ||
121
+ (0, date_1.formatUnixDateToHumanStringMMMDD)(value) !== (0, date_1.formatUnixDateToHumanStringMMMDD)(prevValue);
121
122
  if (newDate) {
122
123
  return (0, date_1.formatUnixDateToHumanStringMMMDD)(value);
123
124
  }
@@ -126,7 +127,8 @@ var SmartDateLabelProvider = /** @class */ (function (_super) {
126
127
  }
127
128
  }
128
129
  else if (tradeChartLabelFormat === ETradeChartLabelFormat.Days) {
129
- var newMonth = !prevValue || (0, date_1.formatUnixDateToHumanStringMMM)(value) !== (0, date_1.formatUnixDateToHumanStringMMM)(prevValue);
130
+ var newMonth = prevValue === undefined ||
131
+ (0, date_1.formatUnixDateToHumanStringMMM)(value) !== (0, date_1.formatUnixDateToHumanStringMMM)(prevValue);
130
132
  if (newMonth) {
131
133
  return (0, date_1.formatUnixDateToHumanStringMMM)(value);
132
134
  }
@@ -135,12 +137,13 @@ var SmartDateLabelProvider = /** @class */ (function (_super) {
135
137
  }
136
138
  }
137
139
  else if (tradeChartLabelFormat === ETradeChartLabelFormat.Months) {
138
- var newYear = !prevValue || (0, date_1.formatUnixDateToHumanStringYYYY)(value) !== (0, date_1.formatUnixDateToHumanStringYYYY)(prevValue);
140
+ var newYear = prevValue === undefined ||
141
+ (0, date_1.formatUnixDateToHumanStringYYYY)(value) !== (0, date_1.formatUnixDateToHumanStringYYYY)(prevValue);
139
142
  if (newYear) {
140
143
  return (0, date_1.formatUnixDateToHumanStringYYYY)(value);
141
144
  }
142
145
  // If previous label was year, display month label
143
- var prevPrevNewYear = !prevPrevValue ||
146
+ var prevPrevNewYear = prevPrevValue === undefined ||
144
147
  (0, date_1.formatUnixDateToHumanStringYYYY)(prevValue) !== (0, date_1.formatUnixDateToHumanStringYYYY)(prevPrevValue);
145
148
  var newMonth = prevPrevNewYear || (0, date_1.formatUnixDateToHumanStringMMM)(value) !== (0, date_1.formatUnixDateToHumanStringMMM)(prevValue);
146
149
  if (newMonth) {
@@ -171,9 +171,6 @@ var BaseOhlcRenderableSeries = /** @class */ (function (_super) {
171
171
  else {
172
172
  this.pointSeries.xRange = rp.xVisibleRange;
173
173
  }
174
- var rpHigh = rp.clone({
175
- resamplingMode: rp.resamplingMode === ResamplingMode_1.EResamplingMode.None ? ResamplingMode_1.EResamplingMode.None : ResamplingMode_1.EResamplingMode.Max
176
- });
177
174
  var ps = this.pointSeries;
178
175
  var ds = this.dataSeries;
179
176
  var xValues = ds.getNativeXValues();
@@ -181,22 +178,79 @@ var BaseOhlcRenderableSeries = /** @class */ (function (_super) {
181
178
  var highValues = ds.getNativeHighValues();
182
179
  var lowValues = ds.getNativeLowValues();
183
180
  var closeValues = ds.getNativeCloseValues();
184
- this.resamplerHelper.resampleIntoPointSeries(this.webAssemblyContext, rpHigh, xValues, highValues, this.xyyTempPointSeries.intIndexes, this.xyyTempPointSeries.xValues, this.xyyTempPointSeries.yValues);
185
- var xySize = this.xyyTempPointSeries.intIndexes.size();
181
+ var originalIndexes = ds.getNativeIndexes();
182
+ // 1) calc ps.highValues
183
+ var rpHigh = rp.clone({
184
+ resamplingMode: rp.resamplingMode === ResamplingMode_1.EResamplingMode.None ? ResamplingMode_1.EResamplingMode.None : ResamplingMode_1.EResamplingMode.Max
185
+ });
186
+ this.resamplerHelper.resampleIntoPointSeries(this.webAssemblyContext, rpHigh, xValues, highValues, this.xyyTempPointSeries.intIndexes, // don't care
187
+ this.xyyTempPointSeries.xValues, // don't care
188
+ ps.highValues);
189
+ // console.log("high count ", ps.highValues.size());
190
+ this.xyyTempPointSeries.clearIntIndexes();
191
+ // 2) calc ps.lowValues
186
192
  var rpLow = rp.clone({
187
193
  resamplingMode: rp.resamplingMode === ResamplingMode_1.EResamplingMode.None ? ResamplingMode_1.EResamplingMode.None : ResamplingMode_1.EResamplingMode.Min
188
194
  });
189
- this.resamplerHelper.resampleIntoPointSeries(this.webAssemblyContext, rpLow, xValues, lowValues, this.xyyTempPointSeries.intIndexes, this.xyyTempPointSeries.xValues, this.xyyTempPointSeries.y1Values);
190
- // Because intIndexes vector is not cleared indexes for rpLow are appended at the end of rpHigh indexes
191
- var xy1Size = this.xyyTempPointSeries.intIndexes.size() - xySize;
192
- // We merge indexes excluding duplicates for rpLow and rpHigh into one vector
193
- var mergedSize = this.resamplerHelper.mergeIndexes(this.xyyTempPointSeries.intIndexes, xySize, xy1Size, ps.intIndexes);
194
- // Clear the intIndexes as long as we do not need them any more
195
- this.xyyTempPointSeries.intIndexes.clear();
196
- // Get values by indexes for High and Low values
197
- this.resamplerHelper.copyValuesByIndexes(ps.intIndexes, xValues, highValues, lowValues, mergedSize, rp.isCategoryAxis, ps.xValues, ps.highValues, ps.lowValues);
198
- // Get values by indexes for Open and Close values
199
- this.resamplerHelper.copyValuesByIndexes(ps.intIndexes, xValues, openValues, closeValues, mergedSize, rp.isCategoryAxis, ps.xValues, ps.openValues, ps.closeValues);
195
+ this.resamplerHelper.resampleIntoPointSeries(this.webAssemblyContext, rpLow, xValues, lowValues, this.xyyTempPointSeries.intIndexes, // don't care
196
+ this.xyyTempPointSeries.xValues, ps.lowValues);
197
+ // console.log("low count ", ps.lowValues.size());
198
+ // We don't want the indexes for high/low
199
+ this.xyyTempPointSeries.clearIntIndexes();
200
+ this.xyyTempPointSeries.y1Values.clear();
201
+ // 3) Get batch indexes
202
+ // Resample indexes to get start and end of batch
203
+ var rpOpenClose = rp.clone({
204
+ resamplingMode: rp.resamplingMode === ResamplingMode_1.EResamplingMode.None ? ResamplingMode_1.EResamplingMode.None : ResamplingMode_1.EResamplingMode.Min
205
+ });
206
+ this.resamplerHelper.resampleIntoPointSeries(this.webAssemblyContext, rpOpenClose, xValues, originalIndexes, ps.intIndexes, this.xyyTempPointSeries.xValues, // don't care
207
+ this.xyyTempPointSeries.y1Values // don't care
208
+ );
209
+ var openCloseSize = ps.intIndexes.size();
210
+ this.xyyTempPointSeries.y1Values.clear();
211
+ // 4) calc ps.openValues, ps.closeValues
212
+ // console.log("open/close count ", openCloseSize);
213
+ // indexes 0, 1, 2, 3, 4, 5, 6, 7
214
+ // opens 3, 4, 7, 8, 3, 5, 9, 6
215
+ // closes 8, 3, 5, 9, 6, 3
216
+ // batch 0, 3, 6
217
+ // batch 0 - open 3 (index 0), close 8 (index 2)
218
+ var lastIndexOfFirstBatch = ps.intIndexes.get(3) - ps.intIndexes.get(2) - 1;
219
+ // console.log(
220
+ // "indexes ",
221
+ // ps.intIndexes.get(0),
222
+ // ps.intIndexes.get(1),
223
+ // ps.intIndexes.get(2),
224
+ // ps.intIndexes.get(3),
225
+ // ps.intIndexes.get(4),
226
+ // ps.intIndexes.get(5),
227
+ // ps.intIndexes.get(6)
228
+ // );
229
+ // console.log(
230
+ // "x values ",
231
+ // xValues.get(0),
232
+ // xValues.get(1),
233
+ // xValues.get(2),
234
+ // xValues.get(3),
235
+ // xValues.get(4),
236
+ // xValues.get(5),
237
+ // xValues.get(6)
238
+ // );
239
+ // console.log("Max index", rp.indexesRange.max);
240
+ // const batchWidth = rp.xVisibleRange.diff / rp.viewportRect.width;
241
+ // console.log(
242
+ // "Batch width ",
243
+ // batchWidth,
244
+ // Math.floor(Math.log2(batchWidth)),
245
+ // Math.pow(2, Math.floor(Math.log2(batchWidth)))
246
+ // );
247
+ // console.log("X Spacing ", rp.xVisibleRange.diff / rp.indexesRange.max);
248
+ // console.log("original points / resampled points ", xValues.size() / openCloseSize);
249
+ // console.log("lastIndexOfFirstBatch ", lastIndexOfFirstBatch);
250
+ // Get values by indexes for Open values
251
+ this.resamplerHelper.copyValuesByIndexes(ps.intIndexes, xValues, openValues, closeValues, openCloseSize, rp.isCategoryAxis, ps.xValues, ps.openValues, ps.closeValues, lastIndexOfFirstBatch);
252
+ // Last close value is handled in c++;
253
+ // 5) update indexes for category axis
200
254
  if (rp.isCategoryAxis)
201
255
  ps.updateIndexes();
202
256
  ps.clearIntIndexes();