Skip to content

Commit

Permalink
feat: try to avoid removing github workflows during copybara sync pro…
Browse files Browse the repository at this point in the history
…cess

GitOrigin-RevId: fe20979dd8d3ef7385d51c10d7622f8d64aa7f9a
  • Loading branch information
dxpm authored and dxcity committed Dec 11, 2024
1 parent d37a75a commit a9b9667
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 357 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devexperts/dxcharts-lite",
"version": "2.6.1",
"version": "2.5.8",
"description": "DXCharts Lite",
"author": "Devexperts Solutions IE Limited",
"license": "MPL 2.0",
Expand Down
1 change: 0 additions & 1 deletion src/chart/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ export default class ChartBootstrap {
this.canvasBoundsContainer,
this.paneManager,
timeZoneModel,
chartPanComponent.mainCanvasTouchHandler,
formatterFactory,
);
this.chartComponents.push(this.hoverProducer);
Expand Down
6 changes: 1 addition & 5 deletions src/chart/canvas/canvas-bounds-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ const N_MAP_BUTTON_W = 15;
const KNOTS_W_MOBILE_MULTIPLIER = 1.5;
const N_MAP_KNOT_W = isMobile() ? 8 * KNOTS_W_MOBILE_MULTIPLIER : 8;

// additional x axis height padding for mobiles, used for better usability on mobile devices
export const X_AXIS_MOBILE_PADDING = isMobile() ? 5 : 0;

/**
* we need to check that: heightRatios - 1 < 0.000001 after calculations between decimals
*/
Expand Down Expand Up @@ -469,8 +466,7 @@ export class CanvasBoundsContainer {
this.xAxisHeight =
fontHeight +
(this.config.components.xAxis.padding.top ?? 0) +
(this.config.components.xAxis.padding.bottom ?? 0) +
X_AXIS_MOBILE_PADDING;
(this.config.components.xAxis.padding.bottom ?? 0);
}
return this.xAxisHeight;
}
Expand Down
13 changes: 1 addition & 12 deletions src/chart/chart.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
* Copyright (C) 2019 - 2024 Devexperts Solutions IE Limited
* 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/.
*/
/*
* Copyright (C) 2019 - 2024 Devexperts Solutions IE Limited
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
Expand Down Expand Up @@ -115,7 +110,6 @@ export const getDefaultConfig = (): FullChartConfig => ({
histogram: {
barCapSize: 1,
},
maxYAxisScalesAmount: 10,
sortCandles: defaultSortCandles,
},
yAxis: {
Expand Down Expand Up @@ -237,7 +231,7 @@ export const getDefaultConfig = (): FullChartConfig => ({
logoWidth: 20,
logoHeight: 20,
},
highLow: { visible: false, font: '12px sans-serif', prefix: { high: 'H: ', low: 'L: ' } },
highLow: { visible: false, font: '12px sans-serif' },
highlights: {
visible: false,
fontFamily: 'Open Sans',
Expand Down Expand Up @@ -985,10 +979,6 @@ export interface ChartConfigComponentsChart {
selectedWidth: number;
minCandlesOffset: number;
histogram: ChartConfigComponentsHistogram;
/**
* The maximum amount of Y axis scales on a single chart
*/
maxYAxisScalesAmount: number;
// optional because backward compability
sortCandles?: (candles: Candle[]) => Candle[];
}
Expand Down Expand Up @@ -1158,7 +1148,6 @@ export interface ChartConfigComponentsHighLow {
* Font config of high/low labels.
*/
font: string;
prefix: { high: string; low: string };
}
export interface ChartConfigComponentsCrossTool {
/**
Expand Down
8 changes: 1 addition & 7 deletions src/chart/components/cross_tool/cross-tool.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,11 @@ export class CrossToolComponent extends ChartBaseElement {
this.crossToolCanvasModel,
crossEventProducer,
hoverProducer,
this.canvasBoundsContainer,
);
this.addChildEntity(this.model);
const clearCanvasDrawer = new ClearCanvasDrawer(this.crossToolCanvasModel);
this.registerDefaultDrawerTypes();
const crossToolDrawer = new CrossToolDrawer(
this.model,
this.config,
this.crossToolCanvasModel,
this.crossToolTypeDrawers,
);
const crossToolDrawer = new CrossToolDrawer(this.model, this.crossToolCanvasModel, this.crossToolTypeDrawers);
const compositeDrawer = new CompositeDrawer();
compositeDrawer.addDrawer(clearCanvasDrawer, 'CLEAR_CANVAS');
compositeDrawer.addDrawer(crossToolDrawer, 'CROSS_TOOL_DRAWER');
Expand Down
8 changes: 2 additions & 6 deletions src/chart/components/cross_tool/cross-tool.drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { CanvasModel } from '../../model/canvas.model';
import { Drawer } from '../../drawers/drawing-manager';
import { CrossToolHover, CrossToolModel, CrossToolType } from './cross-tool.model';
import { FullChartConfig } from '../../chart.config';

export interface CrossToolTypeDrawer {
draw: (ctx: CanvasRenderingContext2D, hover: CrossToolHover) => void;
Expand All @@ -15,7 +14,6 @@ export interface CrossToolTypeDrawer {
export class CrossToolDrawer implements Drawer {
constructor(
private model: CrossToolModel,
private config: FullChartConfig,
private crossToolCanvasModel: CanvasModel,
private readonly crossToolTypeDrawers: Record<CrossToolType, CrossToolTypeDrawer>,
) {}
Expand All @@ -29,13 +27,11 @@ export class CrossToolDrawer implements Drawer {
* @returns {void}
*/
draw() {
const drawer = this.crossToolTypeDrawers[this.config.components.crossTool.type];
const drawer = this.crossToolTypeDrawers[this.model.type];
if (drawer) {
this.model.currentHover && drawer.draw(this.crossToolCanvasModel.ctx, this.model.currentHover);
} else {
console.error(
`No cross tool drawer type registered for drawer type ${this.config.components.crossTool.type}`,
);
console.error(`No cross tool drawer type registered for drawer type ${this.model.type}`);
}
}

Expand Down
63 changes: 10 additions & 53 deletions src/chart/components/cross_tool/cross-tool.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { CrossEventProducerComponent } from '../../inputhandlers/cross-event-pro
import { Hover, HoverProducerComponent } from '../../inputhandlers/hover-producer.component';
import { CanvasModel } from '../../model/canvas.model';
import { ChartBaseElement } from '../../model/chart-base-element';
import { CanvasBoundsContainer, CanvasElement, CHART_UUID } from '../../canvas/canvas-bounds-container';
import { isMobile } from '../../utils/device/browser.utils';
import { CHART_UUID } from '../../canvas/canvas-bounds-container';

export type CrossToolType = 'cross-and-labels' | 'only-labels' | 'none' | string;

Expand All @@ -30,15 +29,16 @@ export class CrossToolModel extends ChartBaseElement {
set currentHover(value: CrossToolHover | null) {
this.currentHoverSubject.next(value);
}
type: CrossToolType = 'cross-and-labels';

constructor(
private config: Required<ChartConfigComponentsCrossTool>,
private crossToolCanvasModel: CanvasModel,
private crossEventProducer: CrossEventProducerComponent,
private hoverProducer: HoverProducerComponent,
private canvasBoundsContainer: CanvasBoundsContainer,
) {
super();
this.type = config.type;
}

/**
Expand All @@ -48,19 +48,21 @@ export class CrossToolModel extends ChartBaseElement {
* @returns {void}
*/
public setType(type: CrossToolType) {
this.config.type = type;
this.type = type;
}

/**
* Method to activate the cross tool.
* It subscribes to the hoverProducer's hover event and updates the crosstool.
* It subscribes to the canvasInputListener's mouse move event and fires the draw event.
* It also subscribes to the eventBus's hover and close hover events and updates the hover and fires the draw event accordingly.
* It also subscribes to the chartModel's candlesSetSubject and timeZoneModel's observeTimeZoneChanged events and recalculates the cross tool X formatter.
*/
protected doActivate() {
super.doActivate();
this.addRxSubscription(
this.hoverProducer.hoverSubject.subscribe(hover => {
if (this.crossEventProducer.crossSubject.getValue() !== null && hover !== null) {
isMobile() ? this.updateCrossToolMobile(hover) : this.updateCrossTool(hover);
this.updateHover(hover);
} else {
this.currentHover = null;
}
Expand All @@ -74,7 +76,7 @@ export class CrossToolModel extends ChartBaseElement {
* @private
*/
private fireDraw() {
if (this.config.type !== 'none') {
if (this.type !== 'none') {
this.crossToolCanvasModel.fireDraw();
}
}
Expand All @@ -93,7 +95,7 @@ export class CrossToolModel extends ChartBaseElement {
* @param {number} hover.candleHover.closestOHLCY - The y coordinate of the closest OHLC price of the candle.
* @returns {void}
*/
public updateCrossTool(hover: Hover, magnetTarget = this.config.magnetTarget) {
public updateHover(hover: Hover, magnetTarget = this.config.magnetTarget) {
if (this.currentHover === null) {
this.currentHover = { x: hover.x, y: 0, time: hover.timeFormatted, paneId: hover.paneId };
} else {
Expand Down Expand Up @@ -127,49 +129,4 @@ export class CrossToolModel extends ChartBaseElement {
this.currentHover.paneId = hover.paneId;
this.currentHoverSubject.next(this.currentHover);
}

private updateCrossToolMobile(hover: Hover) {
// mobile crosstool works only after long touch event
if (!this.hoverProducer.longTouchActivatedSubject.getValue()) {
return;
}

const { fixed, temp, isSet } = this.crossEventProducer.crossToolTouchInfo;

// long touch makes crosstool fixed and the further moving will place crosstool under the current hover coordinates (ordinary logic)
// if crosstool is already set (long touch end event happened) the moving of chart will move crosstool according to it's initial (fixed position)
if (!isSet) {
this.updateCrossTool(hover);
return;
}

// additional crosstool move logic
const paneBounds = this.canvasBoundsContainer.getBounds(CanvasElement.PANE_UUID(hover.paneId));
const offset = 5;

// take a difference inbetween current hover and temporary crosstool coordinates
const xDiff = hover.x - temp.x;
const yDiff = hover.y - temp.y;

// apply the difference to the fixed coordinates
const rawX = fixed.x + xDiff;
const rawY = fixed.y + yDiff;

const paneYStart = paneBounds.y + offset;
const paneYEnd = paneBounds.y + paneBounds.height - offset;

// check for chart bounds and don't move crosstool outside of it
const x = rawX < offset ? offset : rawX > paneBounds.width - offset ? paneBounds.width - offset : rawX;
const y = rawY < paneYStart ? paneYStart : rawY > paneYEnd ? paneYEnd : rawY;
const crossToolHover = this.hoverProducer.createHover(x, y, hover.paneId) ?? hover;

const updatedHover = {
...crossToolHover,
x,
y,
};

this.crossEventProducer.crossToolHover = updatedHover;
this.updateCrossTool(updatedHover);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 { CanvasBoundsContainer, CanvasElement, X_AXIS_MOBILE_PADDING } from '../../../canvas/canvas-bounds-container';
import { CanvasBoundsContainer, CanvasElement } from '../../../canvas/canvas-bounds-container';
import { FullChartConfig } from '../../../chart.config';
import { avoidAntialiasing, drawRoundedRect } from '../../../utils/canvas/canvas-drawing-functions.utils';
import { PaneManager } from '../../pane/pane-manager.component';
Expand Down Expand Up @@ -112,12 +112,12 @@ export class CrossAndLabelsDrawerType implements CrossToolTypeDrawer {
const boxWidth = width + xLabelPaddingLeft + xLabelPaddingRight;
const boxHeight = fontHeight + xLabelPaddingTop + xLabelPaddingBottom;
const xBoxPos = Math.max(x - boxWidth / 2, 0);
const yBoxPos = xAxis.y + xLabelMarginTop + X_AXIS_MOBILE_PADDING / 2;
const yBoxPos = xAxis.y + xLabelMarginTop;
drawRoundedRect(ctx, xBoxPos, yBoxPos, boxWidth, boxHeight);
// label
ctx.fillStyle = crossToolColors.labelTextColor;
const xTextPos = Math.max(x - width / 2, xLabelPaddingLeft);
const yTextPos = xAxis.y + xLabelMarginTop + fontHeight + X_AXIS_MOBILE_PADDING / 2 + xLabelPaddingTop - 1; // -1 for vertical adjustment
const yTextPos = xAxis.y + xLabelMarginTop + fontHeight + xLabelPaddingTop - 1; // -1 for vertical adjustment
ctx.fillText(labelText, xTextPos, yTextPos);
ctx.restore();
}
Expand Down
8 changes: 1 addition & 7 deletions src/chart/components/high_low/high-low.drawer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
* Copyright (C) 2019 - 2024 Devexperts Solutions IE Limited
* 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/.
*/
/*
* Copyright (C) 2019 - 2024 Devexperts Solutions IE Limited
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
Expand Down Expand Up @@ -89,8 +84,7 @@ export class HighLowDrawer implements Drawer {
*/
private getMarkerText(yValue: number, type: MarkerType): string {
const formattedValue = this.chartModel.pane.regularFormatter(yValue);
const prefix =
type === 'high' ? this.config.components.highLow.prefix.high : this.config.components.highLow.prefix.low;
const prefix = type === 'high' ? 'H:' : 'L:';
return `${prefix} ${formattedValue}`;
}

Expand Down
31 changes: 0 additions & 31 deletions src/chart/components/pane/pane-manager.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import { HitTestCanvasModel } from '../../model/hit-test-canvas.model';
import { firstOf, flatMap, lastOf } from '../../utils/array.utils';
import { ChartResizeHandler } from '../../inputhandlers/chart-resize.handler';

export type MoveDataSeriesToPaneDirection = 'above' | 'below';

export class PaneManager extends ChartBaseElement {
public panes: Record<string, PaneComponent> = {};
public paneRemovedSubject: Subject<PaneComponent> = new Subject();
Expand Down Expand Up @@ -288,35 +286,6 @@ export class PaneManager extends ChartBaseElement {
this.recalculateState();
}

/**
* Move data series to a certain pane, or create a new one if no pane is found
*/
public moveDataSeriesToPane(
dataSeries: DataSeriesModel[],
initialPane: PaneComponent,
initialExtent: YExtentComponent,
paneUUID?: string,
extent?: YExtentComponent,
direction?: MoveDataSeriesToPaneDirection,
) {
const pane = paneUUID && this.panes[paneUUID];

if (!pane) {
const order = direction && direction === 'above' ? 0 : this.panesOrder.length;
const newPane = this.createPane(undefined, { order });
newPane.moveDataSeriesToExistingExtentComponent(dataSeries, initialPane, initialExtent, newPane.mainExtent);
initialPane.yExtentComponents.length === 0 && this.removePane(initialPane.uuid);
return;
}

if (extent) {
pane.moveDataSeriesToExistingExtentComponent(dataSeries, initialPane, initialExtent, extent);
} else {
pane.moveDataSeriesToNewExtentComponent(dataSeries, initialPane, initialExtent);
}
initialPane.yExtentComponents.length === 0 && this.removePane(initialPane.uuid);
}

/**
* Adds cursors to the chart elements based on the provided uuid and cursor type.
* @private
Expand Down
30 changes: 1 addition & 29 deletions src/chart/components/pane/pane.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
HitBoundsTest,
} from '../../canvas/canvas-bounds-container';
import { CursorHandler } from '../../canvas/cursor.handler';
import { FullChartConfig, YAxisAlign, YAxisConfig } from '../../chart.config';
import { FullChartConfig, YAxisConfig } from '../../chart.config';
import { DrawingManager } from '../../drawers/drawing-manager';
import EventBus from '../../events/event-bus';
import { CanvasInputListenerComponent } from '../../inputlisteners/canvas-input-listener.component';
Expand Down Expand Up @@ -267,34 +267,6 @@ export class PaneComponent extends ChartBaseElement {
this.canvasBoundsContainer.updateYAxisWidths();
}

/**
* Create new pane extent and attach data series to it
*/
public moveDataSeriesToNewExtentComponent(
dataSeries: DataSeriesModel[],
initialPane: PaneComponent,
initialExtent: YExtentComponent,
align: YAxisAlign = 'right',
) {
const extent = this.createExtentComponent();
extent.yAxis.setYAxisAlign(align);
dataSeries.forEach(series => series.moveToExtent(extent));
initialExtent.dataSeries.size === 0 && initialPane.removeExtentComponent(initialExtent);
}

/**
* Attach data series to existing y axis extent
*/
public moveDataSeriesToExistingExtentComponent(
dataSeries: DataSeriesModel[],
initialPane: PaneComponent,
initialExtent: YExtentComponent,
extentComponent: YExtentComponent,
) {
dataSeries.forEach(series => series.moveToExtent(extentComponent));
initialExtent.dataSeries.size === 0 && initialPane.removeExtentComponent(initialExtent);
}

/**
* This method updates the view by calling the doAutoScale method of the scaleModel and firing the Draw event using the eventBus.
* @private
Expand Down
Loading

0 comments on commit a9b9667

Please sign in to comment.