Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into remove-unused-hover…
Browse files Browse the repository at this point in the history
…-data
  • Loading branch information
KirillBobkov committed Dec 18, 2023
2 parents 77c7af1 + 9e84700 commit 5f87021
Showing 10 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion docs/how-to/custom-drawer/index.html
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ <h1>Chart custom drawer example</h1>
</div>
<div id="chart" class="chart"></div>
<script type="module">
import { clipToBounds } from '@devexperts/dxcharts-lite/dist/chart/drawers/data-series.drawer';
import { clipToBounds } from '@devexperts/dxcharts-lite/dist/chart/utils/canvas/canvas-drawing-functions.utils';
import generateCandlesData from '@devexperts/dxcharts-lite/dist/chart/utils/candles-generator.utils';
const container = document.getElementById('chart');
const chart = DXChart.createChart(container);
4 changes: 2 additions & 2 deletions src/chart/canvas/cursor.handler.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { Observable, Subject } from 'rxjs';
import { Observable, Subject, animationFrameScheduler } from 'rxjs';
import { distinctUntilChanged, throttleTime } from 'rxjs/operators';
import { CursorType } from '../chart.config';
import { CanvasInputListenerComponent } from '../inputlisteners/canvas-input-listener.component';
@@ -42,7 +42,7 @@ export class CursorHandler extends ChartBaseElement {
super.doActivate();
this.canvasInputListener
.observeMouseMoveNoDrag()
.pipe(throttleTime(100, undefined, { trailing: true }))
.pipe(throttleTime(100, animationFrameScheduler, { trailing: true }))
.subscribe(point => {
const cursorFromHT = this.hitTestCanvasModel.resolveCursor(point);
if (cursorFromHT !== undefined) {
6 changes: 3 additions & 3 deletions src/chart/components/chart/chart-area-pan.handler.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { merge } from 'rxjs';
import { merge, animationFrameScheduler } from 'rxjs';
import { throttleTime } from 'rxjs/operators';
import { CanvasAnimation, VIEWPORT_ANIMATION_ID } from '../../animation/canvas-animation';
import { CanvasBoundsContainer, CanvasElement, HitBoundsTest } from '../../canvas/canvas-bounds-container';
@@ -130,7 +130,7 @@ export class ChartAreaPanHandler extends ChartBaseElement {
this.canvasInputListener.observeWheel(allPanesHitTest),
this.canvasInputListener.observePinch(allPanesHitTest),
)
.pipe(throttleTime(this.wheelTrottleTime, undefined, { trailing: true, leading: true }))
.pipe(throttleTime(this.wheelTrottleTime, animationFrameScheduler, { trailing: true, leading: true }))
.subscribe(e => {
const isTouchpad = touchpadDetector(e);
const zoomSensitivity = isTouchpad
@@ -146,7 +146,7 @@ export class ChartAreaPanHandler extends ChartBaseElement {
this.addRxSubscription(
this.canvasInputListener
.observeScrollGesture()
.pipe(throttleTime(this.wheelTrottleTime, undefined, { trailing: true, leading: true }))
.pipe(throttleTime(this.wheelTrottleTime, animationFrameScheduler, { trailing: true, leading: true }))
.subscribe((e: WheelEvent) => {
let direction = -1;
const device = deviceDetector();
Original file line number Diff line number Diff line change
@@ -138,6 +138,7 @@ export class CrossAndLabelsDrawerType implements CrossToolTypeDrawer {
if (this.config.components.yAxis.visible) {
const pane = this.paneManager.panes[point.paneId];
const y = point.y;
const type = this.config.components.crossTool.yLabel.type;
if (!pane) {
return;
}
@@ -147,14 +148,15 @@ export class CrossAndLabelsDrawerType implements CrossToolTypeDrawer {
const bounds = this.canvasBoundsContainer.getBounds(
CanvasElement.PANE_UUID_Y_AXIS(pane.uuid, extent.idx),
);
const drawYLabel = priceLabelDrawersMap[this.config.components.crossTool.yLabel.type];
const drawYLabel = priceLabelDrawersMap[type];
const textColor = type === 'plain' ? crossToolColors.lineColor : crossToolColors.labelTextColor;
drawYLabel(
ctx,
bounds,
label,
y,
{
textColor: crossToolColors.labelTextColor,
textColor,
bgColor: crossToolColors.labelBoxColor,
paddingBottom: yLabelPadding?.bottom,
paddingEnd: yLabelPadding?.end,
4 changes: 2 additions & 2 deletions src/chart/components/x_axis/x-axis.component.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { merge } from 'rxjs';
import { merge, animationFrameScheduler } from 'rxjs';
import { distinctUntilChanged, map, throttleTime, filter } from 'rxjs/operators';
import { CanvasBoundsContainer, CanvasElement } from '../../canvas/canvas-bounds-container';
import { CursorHandler } from '../../canvas/cursor.handler';
@@ -136,7 +136,7 @@ export class XAxisComponent extends ChartBaseElement {

this.addRxSubscription(
merge(this.scale.xChanged, this.chartResizeHandler.canvasResized)
.pipe(throttleTime(50, undefined, { trailing: true, leading: true }))
.pipe(throttleTime(50, animationFrameScheduler, { trailing: true, leading: true }))
.subscribe(() => {
this.xAxisLabelsGenerator.recalculateLabels();
}),
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import { FullChartConfig, YAxisConfig } from '../../../chart.config';
import { CandleSeriesModel } from '../../../model/candle-series.model';
import { DataSeriesType } from '../../../model/data-series.config';
import { ChartModel, LastCandleLabelHandler } from '../../chart/chart.model';
import { getPlainLabelTextColor, getPrimaryLabelTextColor } from '../label-color.functions';
import { getPrimaryLabelTextColor } from '../label-color.functions';
import { YAxisLabelDrawConfig } from '../y-axis-labels.drawer';
import { LabelGroup, VisualYAxisLabel, YAxisLabelsProvider } from './y-axis-labels.model';
import { lastOf } from '../../../utils/array.utils';
@@ -113,7 +113,7 @@ export class LastCandleLabelsProvider implements YAxisLabelsProvider {
const colors = series.colors.labels;
const { rectLabelTextColor = 'white', rectLabelInvertedTextColor = 'black' } = this.chartConfig.colors.yAxis;

const getLabelBoxColor = this.resolveLabelColorFn(series.config.type);
const getLabelColorBySeries = this.resolveLabelColorFn(series.config.type);

if (!colors) {
return {
@@ -123,7 +123,7 @@ export class LastCandleLabelsProvider implements YAxisLabelsProvider {
};
}

const boxColor = getLabelBoxColor(series.lastPriceMovement, series.colors);
const boxColor = getLabelColorBySeries(series.lastPriceMovement, series.colors);

// if the label is for the main candle series
if (primary) {
@@ -132,12 +132,7 @@ export class LastCandleLabelsProvider implements YAxisLabelsProvider {
bgColor: boxColor,
textColor:
appearanceType === 'plain'
? getPlainLabelTextColor(
this.chartConfig.colors,
textColor,
rectLabelInvertedTextColor,
this.yAxisConfig,
)
? getLabelColorBySeries(series.lastPriceMovement, series.colors)
: getLabelTextColorByBackgroundColor(boxColor, textColor, rectLabelInvertedTextColor),
rounded: true,
};
@@ -148,12 +143,7 @@ export class LastCandleLabelsProvider implements YAxisLabelsProvider {
bgColor: boxColor,
textColor:
appearanceType === 'plain'
? getPlainLabelTextColor(
this.chartConfig.colors,
rectLabelTextColor,
rectLabelInvertedTextColor,
this.yAxisConfig,
)
? getLabelColorBySeries(series.lastPriceMovement, series.colors)
: getLabelTextColorByBackgroundColor(boxColor, rectLabelTextColor, rectLabelInvertedTextColor),
rounded: true,
};
4 changes: 2 additions & 2 deletions src/chart/model/hit-test-canvas.model.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { merge, Observable, Subject, Subscription } from 'rxjs';
import { merge, Observable, Subject, Subscription, animationFrameScheduler } from 'rxjs';
import { map, throttleTime } from 'rxjs/operators';
import { CanvasBoundsContainer, CanvasElement } from '../canvas/canvas-bounds-container';
import { CursorType, FullChartConfig } from '../chart.config';
@@ -69,7 +69,7 @@ export class HitTestCanvasModel extends CanvasModel {

const hoverSub = this.canvasInputListener
.observeMouseMove()
.pipe(throttleTime(100, undefined, { trailing: true }))
.pipe(throttleTime(100, animationFrameScheduler, { trailing: true }))
.subscribe(point => this.eventHandler(point, 'hover'));

const touchStartSub = this.canvasInputListener
1 change: 1 addition & 0 deletions src/chart/model/scale.model.ts
Original file line number Diff line number Diff line change
@@ -87,6 +87,7 @@ export class ScaleModel extends ViewportModel {
super.doActivate();
this.scaleInversedSubject = new Subject();
this.beforeStartAnimationSubject = new Subject();

this.addRxSubscription(
this.scaleInversedSubject.subscribe(() => {
this.fireChanged();
1 change: 0 additions & 1 deletion src/chart/model/scaling/viewport.model.ts
Original file line number Diff line number Diff line change
@@ -155,7 +155,6 @@ export abstract class ViewportModel extends ChartBaseElement implements Viewable

protected doActivate(): void {
super.doActivate();
this.changed = new Subject();
}

protected doDeactivate(): void {
4 changes: 4 additions & 0 deletions src/chart/utils/math.utils.ts
Original file line number Diff line number Diff line change
@@ -86,6 +86,10 @@ export class MathUtils {
};
return cutMap[amountToCut](value).toFixed(zeros) + amountToCut;
}

public static isExponential(a: number): boolean {
return /\de(\-|\+)\d/.test(a.toString());
}
}

/**

0 comments on commit 5f87021

Please sign in to comment.