@devexperts/dxcharts-lite 2.7.23 → 2.7.24

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.
@@ -34,6 +34,7 @@ export const prepareCandle = (candle) => {
34
34
  expansion: candle.expansion,
35
35
  idx: candle.idx,
36
36
  impVolatility: candle.impVolatility,
37
+ openInterest: candle.openInterest,
37
38
  vwap: preparedVwap,
38
39
  typicalPrice: candle.typicalPrice,
39
40
  };
@@ -86,14 +86,20 @@ export class VolumesDrawer {
86
86
  if (volumeMax === 0) {
87
87
  return;
88
88
  }
89
+ const viewportModel = this.getViewportModel();
90
+ if (!viewportModel.isViewportValid()) {
91
+ return;
92
+ }
89
93
  const candles = flat(this.chartModel.mainCandleSeries
90
94
  // TODO volumes drawer should be a part of data series drawer
91
95
  .getSeriesInViewport(this.chartModel.scale.xStart - 1, this.chartModel.scale.xEnd + 1));
92
- const viewportModel = this.getViewportModel();
93
96
  candles.forEach((vCandle, idx) => {
94
97
  if (vCandle.candle.volume) {
95
98
  const bounds = viewportModel.getBounds();
96
99
  const fullVHeight = bounds.height;
100
+ if (fullVHeight <= 0) {
101
+ return;
102
+ }
97
103
  const nextX = candles[idx + 1] !== undefined
98
104
  ? floorToDPR(viewportModel.toX(candles[idx + 1].startUnit))
99
105
  : undefined;
@@ -105,8 +111,16 @@ export class VolumesDrawer {
105
111
  this.drawVolume(canvasModel, vCandle, x, y, width, height);
106
112
  }
107
113
  else {
108
- const zoomY = volumeMax / (fullVHeight / OVERLAY_VOLUME_TOTAL_HEIGHT_DIVISOR);
109
- const height = Math.max(ceilToDPR(unitToPixels(vCandle.candle.volume, zoomY)), 2);
114
+ const volumeHeightDivisor = fullVHeight / OVERLAY_VOLUME_TOTAL_HEIGHT_DIVISOR;
115
+ if (volumeHeightDivisor <= 0) {
116
+ return;
117
+ }
118
+ const zoomY = volumeMax / volumeHeightDivisor;
119
+ if (!isFinite(zoomY) || zoomY <= 0) {
120
+ return;
121
+ }
122
+ const calculatedHeight = Math.max(ceilToDPR(unitToPixels(vCandle.candle.volume, zoomY)), 2);
123
+ const height = Math.min(calculatedHeight, fullVHeight);
110
124
  const y = floorToDPR(bounds.y + fullVHeight - height);
111
125
  this.drawVolume(canvasModel, vCandle, x, y, width, height);
112
126
  }
@@ -50,6 +50,8 @@ export class VolumesModel extends ChartBaseElement {
50
50
  */
51
51
  updateVolumeMax() {
52
52
  var _a;
53
- this.volumeMax.next((_a = firstOf(volumeMaxMinFn(this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport().flat()))) !== null && _a !== void 0 ? _a : 0);
53
+ // Use the same parameters as in drawer to ensure volumeMax is calculated from the same candles that will be drawn
54
+ const candles = this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport(this.scale.xStart - 1, this.scale.xEnd + 1);
55
+ this.volumeMax.next((_a = firstOf(volumeMaxMinFn(candles.flat()))) !== null && _a !== void 0 ? _a : 0);
54
56
  }
55
57
  }
@@ -21,6 +21,7 @@ export interface Candle {
21
21
  readonly expansion?: boolean;
22
22
  idx?: number;
23
23
  readonly impVolatility?: number;
24
+ readonly openInterest?: number;
24
25
  /**
25
26
  * @deprecated might be removed in next major version
26
27
  */
@@ -50,7 +50,7 @@ export function hollowDirection(open, close) {
50
50
  * @returns {Candle} A new Candle object with the same properties as the base object, with the option to modify the prices.
51
51
  */
52
52
  export function copyCandle(base, idx, pricesAsClose = false) {
53
- const { id, expansion, impVolatility, vwap, typicalPrice, volume, timestamp } = base;
53
+ const { id, expansion, impVolatility, openInterest, vwap, typicalPrice, volume, timestamp } = base;
54
54
  let hi = base.hi;
55
55
  let lo = base.lo;
56
56
  let open = base.open;
@@ -75,6 +75,7 @@ export function copyCandle(base, idx, pricesAsClose = false) {
75
75
  expansion,
76
76
  idx: _idx,
77
77
  impVolatility,
78
+ openInterest,
78
79
  vwap,
79
80
  typicalPrice,
80
81
  };
@@ -7,3 +7,9 @@ export type Mutable<T> = {
7
7
  -readonly [P in keyof T]: T[P];
8
8
  };
9
9
  export type PartialExcept<T, K extends keyof T> = Partial<Omit<T, K>> & Pick<T, K>;
10
+ export type RequiredKeys<T> = {
11
+ [K in keyof T]-?: undefined extends T[K] ? never : K;
12
+ }[keyof T];
13
+ export type OptionalKeys<T> = {
14
+ [K in keyof T]-?: undefined extends T[K] ? K : never;
15
+ }[keyof T];