@devexperts/dxcharts-lite 2.5.7 → 2.5.8

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.
@@ -180,8 +180,8 @@ export default class ChartBootstrap {
180
180
  this.volumesComponent = new VolumesComponent(this.dynamicObjectsCanvasModel, chartComponent, scaleModel, canvasBoundsContainer, drawingManager, config, paneManager, this.dynamicObjects);
181
181
  this.chartComponents.push(this.volumesComponent);
182
182
  // grid component
183
- const mainChartGridComponent = new GridComponent(mainCanvasModel, scaleModel, config, this.yAxisComponent.state, 'GRID', drawingManager, () => this.canvasBoundsContainer.getBounds(CanvasElement.ALL_PANES), () => this.canvasBoundsContainer.getBounds(chartPaneId), () => this.xAxisComponent.xAxisLabelsGenerator.labels, () => this.yAxisComponent.model.baseLabelsModel.labels, () => mainPane.mainExtent.toY(mainPane.mainExtent.getBaseline()), () => config.components.grid.visible);
184
- this.chartComponents.push(mainChartGridComponent);
183
+ const verticalGridComponent = new GridComponent(mainCanvasModel, scaleModel, config, this.yAxisComponent.state, 'GRID', drawingManager, () => this.canvasBoundsContainer.getBounds(CanvasElement.ALL_PANES), () => this.canvasBoundsContainer.getBounds(chartPaneId), () => this.xAxisComponent.xAxisLabelsGenerator.labels, () => [], undefined, () => config.components.grid.visible);
184
+ this.chartComponents.push(verticalGridComponent);
185
185
  this.hoverProducer = new HoverProducerComponent(this.crossEventProducer, scaleModel, config, chartModel, canvasInputListener, this.canvasBoundsContainer, this.paneManager, timeZoneModel, formatterFactory);
186
186
  this.chartComponents.push(this.hoverProducer);
187
187
  this.crossToolComponent = new CrossToolComponent(config, crossToolCanvasModel, canvasBoundsContainer, drawingManager, paneManager, this.crossEventProducer, this.hoverProducer);
@@ -7,12 +7,16 @@ import { ScaleModel } from '../../model/scale.model';
7
7
  import VisualCandle from '../../model/visual-candle';
8
8
  import { Timestamp } from '../../model/scaling/viewport.model';
9
9
  import { ChartModel } from './chart.model';
10
+ export interface BasicScaleOptions {
11
+ xScale?: boolean;
12
+ yScale?: boolean;
13
+ }
10
14
  /**
11
15
  * Calculates the initial viewport.
12
16
  * @param scaleModel
13
17
  * @doc-tags scaling,viewport
14
18
  */
15
- export declare const createBasicScaleViewportTransformer: (scale: ScaleModel) => (visualCandleSource: VisualCandle[]) => void;
19
+ export declare const createBasicScaleViewportTransformer: (scale: ScaleModel) => (visualCandleSource: VisualCandle[], scaleOptions?: BasicScaleOptions) => void;
16
20
  /**
17
21
  * Moves the viewport between 2 timestamps.
18
22
  * @param scaleModel
@@ -8,13 +8,17 @@
8
8
  * @param scaleModel
9
9
  * @doc-tags scaling,viewport
10
10
  */
11
- export const createBasicScaleViewportTransformer = (scale) => (visualCandleSource) => {
11
+ export const createBasicScaleViewportTransformer = (scale) => (visualCandleSource, scaleOptions = { xScale: true, yScale: true }) => {
12
12
  if (visualCandleSource.length !== 0) {
13
- const vCandles = visualCandleSource.slice(Math.max(visualCandleSource.length - scale.state.defaultViewportItems, 0));
14
- const startCandle = vCandles[0];
15
- const endCandle = vCandles[vCandles.length - 1];
16
- scale.setXScale(startCandle.startUnit, endCandle.startUnit + endCandle.width + scale.offsets.right);
17
- scale.doAutoScale(true);
13
+ if (scaleOptions.xScale) {
14
+ const vCandles = visualCandleSource.slice(Math.max(visualCandleSource.length - scale.state.defaultViewportItems, 0));
15
+ const startCandle = vCandles[0];
16
+ const endCandle = vCandles[vCandles.length - 1];
17
+ scale.setXScale(startCandle.startUnit, endCandle.startUnit + endCandle.width + scale.offsets.right);
18
+ }
19
+ if (scaleOptions.yScale) {
20
+ scale.doAutoScale(true);
21
+ }
18
22
  scale.fireChanged();
19
23
  }
20
24
  };
@@ -54,7 +54,7 @@ export declare class ChartModel extends ChartBaseElement {
54
54
  private candleWidthByChartType;
55
55
  secondaryChartColors: SecondaryChartColorsPool;
56
56
  lastTimeFrame: TimeFrameRange;
57
- basicScaleViewportTransformer: (visualCandleSource: VisualCandle[]) => void;
57
+ basicScaleViewportTransformer: (visualCandleSource: VisualCandle[], scaleOptions?: import("./basic-scale").BasicScaleOptions) => void;
58
58
  timeFrameViewportTransformer: (timeframe: [number, number], zoomIn?: boolean | null) => void;
59
59
  private FAKE_CANDLES_DEFAULT;
60
60
  readonly pane: PaneComponent;
@@ -64,7 +64,9 @@ export class ChartModel extends ChartBaseElement {
64
64
  const candleSeries = new MainCandleSeriesModel(this.chartBaseModel, this.paneManager.panes[CHART_UUID].mainExtent, uuid(), this.paneManager.hitTestController.getNewDataSeriesHitTestId(), this.bus, this.scale, new ChartInstrument(), this.candlesTransformersByChartType, this.candleWidthByChartType, Object.assign({}, this.config.colors));
65
65
  candleSeries.config.type = this.config.components.chart.type;
66
66
  this.candleSeries.push(candleSeries);
67
- scale.addXConstraint((_, state) => candleEdgesConstrait(state, this.mainCandleSeries.visualPoints, this.config.components.chart.minCandlesOffset, scale.getBounds()));
67
+ if (this.config.components.chart.minCandlesOffset > 0) {
68
+ scale.addXConstraint((_, state) => candleEdgesConstrait(state, this.mainCandleSeries.visualPoints, this.config.components.chart.minCandlesOffset, scale.getBounds()));
69
+ }
68
70
  this.basicScaleViewportTransformer = createBasicScaleViewportTransformer(scale);
69
71
  this.timeFrameViewportTransformer = createTimeFrameViewportTransformer(scale, this);
70
72
  this.pane = this.paneManager.panes[CHART_UUID];
@@ -217,7 +219,9 @@ export class ChartModel extends ChartBaseElement {
217
219
  });
218
220
  this.chartBaseModel.recalculatePeriod();
219
221
  this.autoScaleOnCandles();
220
- this.scale.doAutoScale();
222
+ if (this.config.scale.auto) {
223
+ this.scale.doAutoScale();
224
+ }
221
225
  this.candlesSetSubject.next();
222
226
  this.canvasModel.fireDraw();
223
227
  }
@@ -779,7 +783,9 @@ export class ChartModel extends ChartBaseElement {
779
783
  series.recalculateVisualPoints();
780
784
  }
781
785
  });
782
- this.scale.doAutoScale();
786
+ if (this.config.scale.auto) {
787
+ this.scale.doAutoScale();
788
+ }
783
789
  this.candlesUpdatedSubject.next();
784
790
  }
785
791
  /**
@@ -88,9 +88,9 @@ export class PaneComponent extends ChartBaseElement {
88
88
  * @param {NumericYAxisLabelsGenerator} yAxisLabelsGenerator - The generator used to create the labels for the y-axis.
89
89
  * @returns {GridComponent} - The newly created GridComponent instance.
90
90
  */
91
- createGridComponent(uuid, scale, yAxisLabelsGenerator, yAxisState) {
91
+ createGridComponent(uuid, scale, yAxisState, yAxisLabelsGetter, yAxisBaselineGetter) {
92
92
  const chartPaneId = CanvasElement.PANE_UUID(uuid);
93
- const gridComponent = new GridComponent(this.mainCanvasModel, scale, this.config, yAxisState, `PANE_${uuid}_grid_drawer`, this.drawingManager, () => this.canvasBoundsContainer.getBounds(chartPaneId), () => this.canvasBoundsContainer.getBounds(chartPaneId), () => [], () => yAxisLabelsGenerator.generateNumericLabels());
93
+ const gridComponent = new GridComponent(this.mainCanvasModel, scale, this.config, yAxisState, `PANE_${uuid}_grid_drawer`, this.drawingManager, () => this.canvasBoundsContainer.getBounds(chartPaneId), () => this.canvasBoundsContainer.getBounds(chartPaneId), () => [], yAxisLabelsGetter, yAxisBaselineGetter, () => this.config.components.grid.visible);
94
94
  return gridComponent;
95
95
  }
96
96
  /**
@@ -135,7 +135,7 @@ export class PaneComponent extends ChartBaseElement {
135
135
  if (useDefaultHighLow) {
136
136
  scaleModel.autoScaleModel.setHighLowProvider('default', createCandlesOffsetProvider(() => ({ top: 10, bottom: 10, left: 0, right: 0, visible: true }), createDefaultYExtentHighLowProvider(yExtentComponent)));
137
137
  }
138
- const gridComponent = this.createGridComponent(this.uuid, scaleModel, yExtentComponent.yAxis.model.labelsGenerator, yExtentComponent.yAxis.state);
138
+ const gridComponent = this.createGridComponent(this.uuid, scaleModel, yExtentComponent.yAxis.state, () => yExtentComponent.yAxis.model.baseLabelsModel.labels, () => yExtentComponent.toY(yExtentComponent.getBaseline()));
139
139
  yExtentComponent.addChildEntity(gridComponent);
140
140
  yExtentComponent.activate();
141
141
  this.yExtentComponents.push(yExtentComponent);
@@ -18,7 +18,7 @@ export interface XAxisLabelsGenerator {
18
18
  /**
19
19
  * Generates x-axis labels from scratch. Heavy operation.
20
20
  */
21
- generateLabels(): void;
21
+ generateLabels(prependedCandles?: VisualCandle[]): void;
22
22
  /**
23
23
  * Updates current labels state (x-position). Lightweight operation.
24
24
  */
@@ -107,7 +107,7 @@ export declare class XAxisTimeLabelsGenerator implements XAxisLabelsGenerator {
107
107
  * Calls the method generateWeightedLabels to generate labels.
108
108
  * @returns {void}
109
109
  */
110
- generateLabels(): void;
110
+ generateLabels(prependedCandles?: VisualCandle[]): void;
111
111
  /**
112
112
  * Recalculates the labels by calling the method recalculateCachedLabels.
113
113
  * @returns {void}
@@ -86,14 +86,14 @@ export class XAxisTimeLabelsGenerator {
86
86
  /**
87
87
  * Make a prediction(750) about how many candles we need to fake to fill all X axis by labels
88
88
  */
89
- getAllCandlesWithFake() {
89
+ getAllCandlesWithFake(prependedCandles = []) {
90
90
  const visualCandles = this.chartModel.mainCandleSeries.visualPoints;
91
91
  if (visualCandles.length === 0) {
92
92
  return [];
93
93
  }
94
94
  const fakeCandlesForSides = Array.from({ length: 750 });
95
95
  const appendFakeCandle = fakeCandlesForSides.map((_, idx) => fakeVisualCandle(this.chartModel.mainCandleSeries.dataPoints, this.chartModel.mainCandleSeries.visualPoints, this.chartModel.mainCandleSeries.meanCandleWidth, visualCandles.length + idx, this.chartModel.getPeriod()));
96
- return [...visualCandles, ...appendFakeCandle];
96
+ return [...prependedCandles, ...visualCandles, ...appendFakeCandle];
97
97
  }
98
98
  /**
99
99
  * Maps an array of weighted points to an array of XAxisLabelWeighted objects.
@@ -139,8 +139,8 @@ export class XAxisTimeLabelsGenerator {
139
139
  * @function
140
140
  * @returns {void}
141
141
  */
142
- generateWeightedLabels() {
143
- const allCandlesWithFake = this.getAllCandlesWithFake();
142
+ generateWeightedLabels(prependedCandles = []) {
143
+ const allCandlesWithFake = this.getAllCandlesWithFake(prependedCandles);
144
144
  const weightedPoints = mapCandlesToWeightedPoints(allCandlesWithFake, this.weightToTimeFormatMatcherArray, this.timeZoneModel.tzOffset(this.config.timezone));
145
145
  const weightedLabels = this.mapWeightedPointsToLabels(weightedPoints, allCandlesWithFake);
146
146
  this.labelsGroupedByWeight = groupLabelsByWeight(weightedLabels);
@@ -253,8 +253,8 @@ export class XAxisTimeLabelsGenerator {
253
253
  * Calls the method generateWeightedLabels to generate labels.
254
254
  * @returns {void}
255
255
  */
256
- generateLabels() {
257
- this.generateWeightedLabels();
256
+ generateLabels(prependedCandles) {
257
+ this.generateWeightedLabels(prependedCandles);
258
258
  }
259
259
  /**
260
260
  * Recalculates the labels by calling the method recalculateCachedLabels.
@@ -89,7 +89,7 @@ export class MainCanvasTouchHandler extends ChartBaseElement {
89
89
  const last = first +
90
90
  ((candleIndexes[0] - candleIndexes[1]) / (touchPositions[0] - touchPositions[1])) *
91
91
  this.scale.getBounds().width;
92
- if (first >= last) {
92
+ if (first >= last || touchPositions[0] === touchPositions[1]) {
93
93
  return;
94
94
  }
95
95
  this.scale.setXScale(first, last);