@devexperts/dxcharts-lite 2.5.5 → 2.5.6
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.
- package/dist/chart/canvas/canvas-bounds-container.js +1 -1
- package/dist/chart/components/chart/basic-scale.js +0 -1
- package/dist/chart/model/scale.model.d.ts +1 -6
- package/dist/chart/model/scale.model.js +22 -23
- package/dist/chart/model/scaling/lock-ratio.model.d.ts +6 -6
- package/dist/chart/model/scaling/lock-ratio.model.js +27 -21
- package/dist/chart/model/scaling/viewport.model.js +6 -1
- package/dist/dxchart.min.js +4 -4
- package/package.json +1 -1
|
@@ -83,7 +83,7 @@ export class CanvasBoundsContainer {
|
|
|
83
83
|
this.rightRatio = 0;
|
|
84
84
|
this.boundsChangedSubject = new Subject();
|
|
85
85
|
this.barResizerChangedSubject = new Subject();
|
|
86
|
-
this._graphsHeightRatio = {
|
|
86
|
+
this._graphsHeightRatio = { [CHART_UUID]: 1 };
|
|
87
87
|
this.graphsHeightRatioChangedSubject = new Subject();
|
|
88
88
|
this.boundsChangedSubscriptions = {};
|
|
89
89
|
chartResizeHandler.canvasResized.subscribe(bcr => {
|
|
@@ -15,7 +15,6 @@ export const createBasicScaleViewportTransformer = (scale) => (visualCandleSourc
|
|
|
15
15
|
const endCandle = vCandles[vCandles.length - 1];
|
|
16
16
|
scale.setXScale(startCandle.startUnit, endCandle.startUnit + endCandle.width + scale.offsets.right);
|
|
17
17
|
scale.doAutoScale(true);
|
|
18
|
-
scale.recalculateZoomXYRatio();
|
|
19
18
|
scale.fireChanged();
|
|
20
19
|
}
|
|
21
20
|
};
|
|
@@ -7,7 +7,6 @@ import { Subject } from 'rxjs';
|
|
|
7
7
|
import { ChartConfigComponentsOffsets, ChartScale, FullChartConfig } from '../chart.config';
|
|
8
8
|
import { CanvasAnimation } from '../animation/canvas-animation';
|
|
9
9
|
import { AutoScaleViewportSubModel } from './scaling/auto-scale.model';
|
|
10
|
-
import { ZoomXToZoomYRatio } from './scaling/lock-ratio.model';
|
|
11
10
|
import { Price, Unit, ViewportModel, ViewportModelState, Zoom } from './scaling/viewport.model';
|
|
12
11
|
import { BoundsProvider } from './bounds.model';
|
|
13
12
|
export interface HighLowWithIndex {
|
|
@@ -46,7 +45,6 @@ export declare class ScaleModel extends ViewportModel {
|
|
|
46
45
|
scaleInversedSubject: Subject<boolean>;
|
|
47
46
|
beforeStartAnimationSubject: Subject<void>;
|
|
48
47
|
autoScaleModel: AutoScaleViewportSubModel;
|
|
49
|
-
zoomXYRatio: ZoomXToZoomYRatio;
|
|
50
48
|
zoomReached: ZoomReached;
|
|
51
49
|
readonly state: ChartScale;
|
|
52
50
|
history: ScaleHistoryItem[];
|
|
@@ -101,6 +99,7 @@ export declare class ScaleModel extends ViewportModel {
|
|
|
101
99
|
*/
|
|
102
100
|
setXScale(xStart: Unit, xEnd: Unit, forceNoAnimation?: boolean): void;
|
|
103
101
|
setYScale(yStart: Unit, yEnd: Unit, fire?: boolean): void;
|
|
102
|
+
private setLockedYScale;
|
|
104
103
|
/**
|
|
105
104
|
* Moves both xStart and xEnd without changing the viewport width (zoom).
|
|
106
105
|
* Works without animation.
|
|
@@ -165,10 +164,6 @@ export declare class ScaleModel extends ViewportModel {
|
|
|
165
164
|
* @param value - If true, the price-to-bar ratio will be locked. If false, it will not be locked.
|
|
166
165
|
*/
|
|
167
166
|
setLockPriceToBarRatio(value?: boolean): void;
|
|
168
|
-
/**
|
|
169
|
-
* Recalculates the zoom X/Y ratio based on the current zoom levels.
|
|
170
|
-
*/
|
|
171
|
-
recalculateZoomXYRatio(): void;
|
|
172
167
|
}
|
|
173
168
|
/**
|
|
174
169
|
* The SyncedByXScaleModel class extends the ScaleModel class and adds support for synchronization with other ScaleModel instance, so both instances maintain the same X-axis bounds.
|
|
@@ -7,7 +7,7 @@ import { Subject } from 'rxjs';
|
|
|
7
7
|
import { startViewportModelAnimation } from '../animation/viewport-model-animation';
|
|
8
8
|
import { cloneUnsafe } from '../utils/object.utils';
|
|
9
9
|
import { AutoScaleViewportSubModel } from './scaling/auto-scale.model';
|
|
10
|
-
import { changeXToKeepRatio, changeYToKeepRatio
|
|
10
|
+
import { changeXToKeepRatio, changeYToKeepRatio } from './scaling/lock-ratio.model';
|
|
11
11
|
import { moveXStart, moveYStart } from './scaling/move-chart.functions';
|
|
12
12
|
import { ViewportModel, calculateZoom, compareStates, } from './scaling/viewport.model';
|
|
13
13
|
import { zoomXToEndViewportCalculator, zoomXToPercentViewportCalculator } from './scaling/x-zooming.functions';
|
|
@@ -36,7 +36,6 @@ export class ScaleModel extends ViewportModel {
|
|
|
36
36
|
this.scaleInversedSubject = new Subject();
|
|
37
37
|
// y-axis component needs this subject in order to halt prev animation if axis type is percent
|
|
38
38
|
this.beforeStartAnimationSubject = new Subject();
|
|
39
|
-
this.zoomXYRatio = 0;
|
|
40
39
|
this.zoomReached = { min: false, max: false };
|
|
41
40
|
// TODO rework, make a new history based on units
|
|
42
41
|
this.history = [];
|
|
@@ -133,7 +132,7 @@ export class ScaleModel extends ViewportModel {
|
|
|
133
132
|
return;
|
|
134
133
|
}
|
|
135
134
|
if (this.state.lockPriceToBarRatio) {
|
|
136
|
-
changeYToKeepRatio(
|
|
135
|
+
changeYToKeepRatio(initialStateCopy, constrainedState);
|
|
137
136
|
}
|
|
138
137
|
if (this.state.auto) {
|
|
139
138
|
this.autoScaleModel.doAutoYScale(constrainedState);
|
|
@@ -181,7 +180,7 @@ export class ScaleModel extends ViewportModel {
|
|
|
181
180
|
return;
|
|
182
181
|
}
|
|
183
182
|
if (this.state.lockPriceToBarRatio) {
|
|
184
|
-
changeYToKeepRatio(
|
|
183
|
+
changeYToKeepRatio(initialState, constrainedState);
|
|
185
184
|
}
|
|
186
185
|
if (this.state.auto) {
|
|
187
186
|
this.autoScaleModel.doAutoYScale(constrainedState);
|
|
@@ -199,21 +198,30 @@ export class ScaleModel extends ViewportModel {
|
|
|
199
198
|
if (initialState.yStart === yStart && initialState.yEnd === yEnd && initialState.zoomY > 0) {
|
|
200
199
|
return;
|
|
201
200
|
}
|
|
201
|
+
if (this.state.lockPriceToBarRatio) {
|
|
202
|
+
this.setLockedYScale(yStart, yEnd, fire, initialState);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
202
205
|
super.setYScale(yStart, yEnd, fire);
|
|
203
206
|
const state = this.export();
|
|
204
207
|
const constrainedState = this.scalePostProcessor(initialState, state);
|
|
205
|
-
if (this.state.
|
|
206
|
-
|
|
207
|
-
this.setXScale(constrainedState.xStart, constrainedState.xEnd);
|
|
208
|
-
// TODO: rewrite logic for applying constraints to consider both axes, now constraints on Y may not work correctly
|
|
209
|
-
return;
|
|
208
|
+
if (this.state.auto) {
|
|
209
|
+
this.autoScaleModel.doAutoYScale(constrainedState);
|
|
210
210
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
211
|
+
this.apply(constrainedState);
|
|
212
|
+
}
|
|
213
|
+
setLockedYScale(yStart, yEnd, fire = false, initialState) {
|
|
214
|
+
const zoomIn = yEnd < initialState.yEnd;
|
|
215
|
+
if ((this.zoomReached.min && zoomIn === false) || (this.zoomReached.max && zoomIn === true)) {
|
|
216
|
+
return;
|
|
216
217
|
}
|
|
218
|
+
super.setYScale(yStart, yEnd, fire);
|
|
219
|
+
const state = this.export();
|
|
220
|
+
const constrainedState = this.scalePostProcessor(initialState, state);
|
|
221
|
+
changeXToKeepRatio(initialState, constrainedState);
|
|
222
|
+
this.zoomReached = this.calculateZoomReached(constrainedState.zoomX, zoomIn);
|
|
223
|
+
this.apply(constrainedState);
|
|
224
|
+
this.fireChanged();
|
|
217
225
|
}
|
|
218
226
|
/**
|
|
219
227
|
* Moves both xStart and xEnd without changing the viewport width (zoom).
|
|
@@ -342,17 +350,8 @@ export class ScaleModel extends ViewportModel {
|
|
|
342
350
|
this.state.lockPriceToBarRatio = false;
|
|
343
351
|
return;
|
|
344
352
|
}
|
|
345
|
-
if (value) {
|
|
346
|
-
this.recalculateZoomXYRatio();
|
|
347
|
-
}
|
|
348
353
|
this.state.lockPriceToBarRatio = value;
|
|
349
354
|
}
|
|
350
|
-
/**
|
|
351
|
-
* Recalculates the zoom X/Y ratio based on the current zoom levels.
|
|
352
|
-
*/
|
|
353
|
-
recalculateZoomXYRatio() {
|
|
354
|
-
this.zoomXYRatio = ratioFromZoomXY(this.zoomX, this.zoomY);
|
|
355
|
-
}
|
|
356
355
|
}
|
|
357
356
|
/**
|
|
358
357
|
* The SyncedByXScaleModel class extends the ScaleModel class and adds support for synchronization with other ScaleModel instance, so both instances maintain the same X-axis bounds.
|
|
@@ -10,13 +10,13 @@ export declare const zoomXToZoomY: (zoomX: Zoom, ratio: ZoomXToZoomYRatio) => Zo
|
|
|
10
10
|
export declare const zoomYToZoomX: (zoomY: Zoom, ratio: ZoomXToZoomYRatio) => Zoom;
|
|
11
11
|
/**
|
|
12
12
|
* Locks the zoomY with zoomX and zooms y-scale depending on x-scale.
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
13
|
+
* @param prevState
|
|
14
|
+
* @param newState
|
|
15
15
|
*/
|
|
16
|
-
export declare const changeYToKeepRatio: (
|
|
16
|
+
export declare const changeYToKeepRatio: (prevState: ViewportModelState, newState: ViewportModelState) => void;
|
|
17
17
|
/**
|
|
18
18
|
* Locks the zoomY with zoomX and zooms x-scale depending on y-scale.
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
19
|
+
* @param prevState
|
|
20
|
+
* @param newState
|
|
21
21
|
*/
|
|
22
|
-
export declare const changeXToKeepRatio: (
|
|
22
|
+
export declare const changeXToKeepRatio: (prevState: ViewportModelState, newState: ViewportModelState) => void;
|
|
@@ -8,30 +8,36 @@ export const zoomXToZoomY = (zoomX, ratio) => zoomX / ratio;
|
|
|
8
8
|
export const zoomYToZoomX = (zoomY, ratio) => zoomY * ratio;
|
|
9
9
|
/**
|
|
10
10
|
* Locks the zoomY with zoomX and zooms y-scale depending on x-scale.
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
11
|
+
* @param prevState
|
|
12
|
+
* @param newState
|
|
13
13
|
*/
|
|
14
|
-
export const changeYToKeepRatio = (
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
export const changeYToKeepRatio = (prevState, newState) => {
|
|
15
|
+
const prevZoomX = prevState.zoomX;
|
|
16
|
+
const prevZoomY = prevState.zoomY;
|
|
17
|
+
const prevZoomXY = ratioFromZoomXY(prevZoomX, prevZoomY);
|
|
18
|
+
const prevYHeight = prevState.yEnd - prevState.yStart;
|
|
19
|
+
// recalculate zoomY
|
|
20
|
+
newState.zoomY = zoomXToZoomY(newState.zoomX, prevZoomXY);
|
|
21
|
+
const zoomYMult = newState.zoomY / prevZoomY;
|
|
22
|
+
const newYHeight = prevYHeight * zoomYMult;
|
|
23
|
+
const delta = newYHeight - prevYHeight;
|
|
24
|
+
newState.yEnd = newState.yEnd + delta / 2;
|
|
25
|
+
newState.yStart = newState.yStart - delta / 2;
|
|
23
26
|
};
|
|
24
27
|
/**
|
|
25
28
|
* Locks the zoomY with zoomX and zooms x-scale depending on y-scale.
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
29
|
+
* @param prevState
|
|
30
|
+
* @param newState
|
|
28
31
|
*/
|
|
29
|
-
export const changeXToKeepRatio = (
|
|
30
|
-
const prevZoomX =
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
export const changeXToKeepRatio = (prevState, newState) => {
|
|
33
|
+
const prevZoomX = prevState.zoomX;
|
|
34
|
+
const prevZoomY = prevState.zoomY;
|
|
35
|
+
const prevZoomXY = ratioFromZoomXY(prevZoomX, prevZoomY);
|
|
36
|
+
const prevXWidth = prevState.xEnd - prevState.xStart;
|
|
37
|
+
// recalculate zoomX
|
|
38
|
+
newState.zoomX = zoomYToZoomX(newState.zoomY, prevZoomXY);
|
|
39
|
+
const zoomXMult = newState.zoomX / prevZoomX;
|
|
40
|
+
const newXWidth = prevXWidth * zoomXMult;
|
|
41
|
+
const delta = newXWidth - prevXWidth;
|
|
42
|
+
newState.xStart = newState.xStart - delta;
|
|
37
43
|
};
|
|
@@ -287,7 +287,12 @@ export class ViewportModel extends ChartBaseElement {
|
|
|
287
287
|
* @returns {boolean} - Returns true if the viewport is valid, false otherwise.
|
|
288
288
|
*/
|
|
289
289
|
isViewportValid() {
|
|
290
|
-
return this.xStart !== this.xEnd &&
|
|
290
|
+
return (this.xStart !== this.xEnd &&
|
|
291
|
+
this.yStart !== this.yEnd &&
|
|
292
|
+
isFinite(this.yStart) &&
|
|
293
|
+
isFinite(this.yEnd) &&
|
|
294
|
+
this.zoomX > 0 &&
|
|
295
|
+
this.zoomY > 0);
|
|
291
296
|
}
|
|
292
297
|
}
|
|
293
298
|
export const compareStates = (a, b) => !keys(a).some(k => a[k] !== b[k]);
|