Skip to content

Commit

Permalink
Merge pull request #42 from devexperts/refactor-dataseries-and-dynami…
Browse files Browse the repository at this point in the history
…c-objects-ids

enhancement: refactor-dataseries-and-dynamic-objects-ids
  • Loading branch information
DeltaZN authored Oct 2, 2023
2 parents 3428cd6 + ba832c2 commit ea25a64
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/chart/components/chart/chart.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { ChartBaseModel } from './chart-base.model';
import { CandleSeries, ChartInstrument, PartialCandle } from './chart.component';
import { fakeCandle } from './fake-candles';
import { SecondaryChartColorsPool } from './secondary-chart-colors-pool';
import { uuid } from '../../utils/uuid.utils';

export type VisualCandleCalculator = (
candle: Candle,
Expand Down Expand Up @@ -93,6 +94,7 @@ export class ChartModel extends ChartBaseElement {
const candleSeries = new MainCandleSeriesModel(
this.chartBaseModel,
this.paneManager.panes[CHART_UUID].mainExtent,
uuid(),
this.paneManager.hitTestController.getNewDataSeriesHitTestId(),
this.bus,
this.scale,
Expand Down Expand Up @@ -435,6 +437,7 @@ export class ChartModel extends ChartBaseElement {
private createCandleSeriesModel(instrument: ChartInstrument, colors?: CandleSeriesColors): CandleSeriesModel {
const candleSeries = new CandleSeriesModel(
this.paneManager.panes[CHART_UUID].mainExtent,
uuid(),
this.paneManager.hitTestController.getNewDataSeriesHitTestId(),
this.bus,
this.scale,
Expand Down Expand Up @@ -620,7 +623,7 @@ export class ChartModel extends ChartBaseElement {
// lineX is the middle of candle - it's correct
return this.scale.toX(visualCandle.centerUnit);
}

/**
* Transforms X coordinate (relative to canvas element) to Candle object.
* If extrapolate = false, then it takes leftmost/rightmost existing candle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { LinkedList, ListNode } from '../../utils/linkedList.utils';
import { DynamicModelDrawer } from './dynamic-objects.drawer';

export type PaneId = string;
type DynamicObjectId = string | number;
export type DynamicObjectId = string | number;

export interface DynamicObject<T = unknown> {
readonly id: DynamicObjectId;
Expand Down
3 changes: 2 additions & 1 deletion src/chart/components/pane/extent/y-extent-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { ScaleModel } from '../../../model/scale.model';
import { HighLowProvider, mergeHighLow } from '../../../model/scaling/auto-scale.model';
import { Pixel, Price, Unit } from '../../../model/scaling/viewport.model';
import { uuid } from '../../../utils/uuid.utils';
import { ChartBaseModel } from '../../chart/chart-base.model';
import { createYExtentFormatters } from '../../chart/price.formatter';
import { DragNDropYComponent } from '../../dran-n-drop_helper/drag-n-drop-y.component';
Expand Down Expand Up @@ -98,7 +99,7 @@ export class YExtentComponent extends ChartBaseElement {
* @returns {DataSeriesModel} - The newly created DataSeriesModel object.
*/
public createDataSeries(): DataSeriesModel {
const series = new DataSeriesModel(this, this.hitTestController.getNewDataSeriesHitTestId());
const series = new DataSeriesModel(this, uuid(), this.hitTestController.getNewDataSeriesHitTestId());
series.toVisualPoints = this.toVisualPoints;
return series;
}
Expand Down
4 changes: 2 additions & 2 deletions src/chart/components/pane/pane-hit-test.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class PaneHitTestController implements HitTestSubscriber<DataSeriesModel>
* @returns {DataSeriesModel | undefined} - The data series with the given ID, or undefined if it does not exist.
*/
public lookup(id: number): DataSeriesModel | undefined {
const result = this.allDataSeries.find(d => d.id === id);
const result = this.allDataSeries.find(d => d.htId === id);
return result;
}

Expand All @@ -48,7 +48,7 @@ export class PaneHitTestController implements HitTestSubscriber<DataSeriesModel>
* @returns {void}
*/
onHover(model: DataSeriesModel | null): void {
this.allDataSeries.forEach(d => (d.hovered = d.id === model?.id));
this.allDataSeries.forEach(d => (d.hovered = d.htId === model?.htId));
this.canvasModel.fireDraw();
}

Expand Down
2 changes: 1 addition & 1 deletion src/chart/drawers/ht-data-series.drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class HTDataSeriesDrawer implements Drawer {
const drawer = this.seriesDrawers[paintTool];
if (drawer) {
const drawConfig: ChartDrawerConfig = {
singleColor: this.canvasModel.idToColor(series.id),
singleColor: this.canvasModel.idToColor(series.htId),
forceBold: 7,
};
// +- 1 to correctly draw points which are partly inside bounds
Expand Down
5 changes: 3 additions & 2 deletions src/chart/model/candle-series.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ export class CandleSeriesModel extends DataSeriesModel<Candle, VisualCandle> {

constructor(
extentComponent: YExtentComponent,
id: number,
id: string,
htId: number,
private eventBus: EventBus,
scale: ScaleModel,
instrument: ChartInstrument,
private readonly candlesTransformersByChartType: Partial<Record<DataSeriesType, VisualCandleCalculator>>,
private readonly candleWidthByChartType: Partial<Record<DataSeriesType, CandleWidthCalculator>>,
public colors: CandleSeriesColors = DEFAULT_CANDLE_SERIES_CONFIG,
) {
super(extentComponent, id);
super(extentComponent, id, htId);
this._instrument = instrument;
this.instrument = instrument;
this.highLowProvider = createCandleSeriesHighLowProvider(this);
Expand Down
4 changes: 3 additions & 1 deletion src/chart/model/compare-series-hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { BaseHover, HoverProducerPart } from '../inputhandlers/hover-producer.co
export interface CompareSeriesHover {
instrument: string;
price: string;
id: number;
id: string;
htId: number;
}

export class CompareSeriesHoverProducerPart implements HoverProducerPart<CompareSeriesHover[]> {
Expand All @@ -32,6 +33,7 @@ export class CompareSeriesHoverProducerPart implements HoverProducerPart<Compare
instrument: series.instrument.symbol,
price: priceToShow,
id: series.id,
htId: series.htId,
};
});

Expand Down
3 changes: 2 additions & 1 deletion src/chart/model/data-series.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ export class DataSeriesModel<

constructor(
public extentComponent: YExtentComponent,
public id: number,
public id: string,
public htId: number,
_config: AtLeastOne<DataSeriesConfig> = cloneUnsafe(DEFAULT_DATA_SERIES_CONFIG),
) {
super();
Expand Down
4 changes: 3 additions & 1 deletion src/chart/model/main-candle-series.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export class MainCandleSeriesModel extends CandleSeriesModel {
constructor(
private readonly baseModel: ChartBaseModel<'candle'>,
extentComponent: YExtentComponent,
id: number,
id: string,
htId: number,
eventBus: EventBus,
scale: ScaleModel,
instrument: ChartInstrument,
Expand All @@ -32,6 +33,7 @@ export class MainCandleSeriesModel extends CandleSeriesModel {
super(
extentComponent,
id,
htId,
eventBus,
scale,
instrument,
Expand Down

0 comments on commit ea25a64

Please sign in to comment.