Skip to content

Commit

Permalink
Merge branch 'master' into remove-unused-hover-data
Browse files Browse the repository at this point in the history
  • Loading branch information
Keelaro1 authored Dec 13, 2023
2 parents 77c7af1 + ba8f150 commit 085e9aa
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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,
};
Expand All @@ -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,
};
Expand Down
20 changes: 8 additions & 12 deletions src/chart/components/y_axis/y-axis-scale.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export class YAxisScaleHandler extends ChartBaseElement {

constructor(
private bus: EventBus,
private config: YAxisConfig,
config: YAxisConfig,
panning: ChartPanComponent,
private scale: ScaleModel,
private canvasInputListener: CanvasInputListenerComponent,
canvasInputListener: CanvasInputListenerComponent,
private bounds: CanvasBoundsContainer,
private hitTest: HitBoundsTest,
hitTest: HitBoundsTest,
private autoScaleCallback: (auto: boolean) => void,
) {
super();
Expand All @@ -58,17 +58,13 @@ export class YAxisScaleHandler extends ChartBaseElement {
},
);
this.addChildEntity(dragNDropYComponent);
}
}

protected doActivate(): void {
if (this.config.customScaleDblClick) {
this.addRxSubscription(
this.canvasInputListener.observeDbClick(this.hitTest).subscribe(() => {
this.autoScaleCallback(true);
if (config.customScaleDblClick) {
canvasInputListener.observeDbClick(hitTest).subscribe(() => {
autoScaleCallback(true);
this.bus.fireDraw();
}),
);
});
}
}
}

Expand Down
11 changes: 1 addition & 10 deletions src/chart/model/scale.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Constraints = (initialState: ViewportModelState, state: ViewportModelState)
export class ScaleModel extends ViewportModel {
public scaleInversedSubject: Subject<boolean> = new Subject<boolean>();
// y-axis component needs this subject in order to halt prev animation if axis type is percent
public beforeStartAnimationSubject: Subject<void> = new Subject<void>();
public beforeStartAnimationSubject = new Subject<void>();

// TODO rework, make a new history based on units
history: ScaleHistoryItem[] = [];
Expand Down Expand Up @@ -84,22 +84,13 @@ export class ScaleModel extends ViewportModel {
}

protected doActivate(): void {
super.doActivate();
this.scaleInversedSubject = new Subject();
this.beforeStartAnimationSubject = new Subject();
this.addRxSubscription(
this.scaleInversedSubject.subscribe(() => {
this.fireChanged();
}),
);
}

protected doDeactivate(): void {
super.doDeactivate();
this.scaleInversedSubject.complete();
this.beforeStartAnimationSubject.complete();
}

/**
* The method adds a new "constraint" to the existing list of x-axis constraints for charting.
* The "constraint" is expected to be an object containing information about the constraints, such as the minimum and maximum values for the x-axis.
Expand Down
15 changes: 4 additions & 11 deletions src/chart/model/scaling/viewport.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,6 @@ export abstract class ViewportModel extends ChartBaseElement implements Viewable
share(),
);
//endregion

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

protected doDeactivate(): void {
super.doDeactivate();
this.changed.complete();
}
//region conversion methods
/**
* Converts a unit value to pixels based on the current zoom level and xStart value.
Expand Down Expand Up @@ -227,7 +217,10 @@ export abstract class ViewportModel extends ChartBaseElement implements Viewable
return pixelsToUnits(normalizedPx + unitToPixels(this.yStart, this.zoomY), this.zoomY);
} else {
// inverse by default because canvas calculation [0,0] point starts from top-left corner
return pixelsToUnits(bounds.height - normalizedPx + unitToPixels(this.yStart, this.zoomY), this.zoomY);
return pixelsToUnits(
bounds.height - normalizedPx + unitToPixels(this.yStart, this.zoomY),
this.zoomY,
);
}
}

Expand Down

0 comments on commit 085e9aa

Please sign in to comment.