Skip to content

Commit

Permalink
feat: get bounds optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillBobkov authored and disyakidneyshot committed Dec 4, 2023
1 parent d73ed72 commit 1513839
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/chart/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,11 @@ export default class ChartBootstrap {
const canvasAnimation = new CanvasAnimation(eventBus);
this.canvasAnimation = canvasAnimation;

const chartPaneId = CanvasElement.PANE_UUID(CHART_UUID);
//#region ScaleModel init
const scaleModel = new ScaleModel(
config,
() => canvasBoundsContainer.getBounds(CanvasElement.PANE_UUID(CHART_UUID)),
() => canvasBoundsContainer.getBounds(chartPaneId),
canvasAnimation,
);
this.scaleModel = scaleModel;
Expand Down Expand Up @@ -482,7 +483,7 @@ export default class ChartBootstrap {
'GRID',
drawingManager,
() => this.canvasBoundsContainer.getBounds(CanvasElement.ALL_PANES),
() => this.canvasBoundsContainer.getBounds(CanvasElement.PANE_UUID(CHART_UUID)),
() => this.canvasBoundsContainer.getBounds(chartPaneId),
() => this.xAxisComponent.xAxisLabelsGenerator.labels,
() => this.yAxisComponent.model.baseLabelsModel.labels,
() => mainPane.mainExtent.toY(mainPane.mainExtent.getBaseline()),
Expand Down
3 changes: 2 additions & 1 deletion src/chart/components/chart/chart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ export class ChartComponent extends ChartBaseElement {
new MainChartHistogramDrawer(this.config.components.chart.histogram),
);

const mainChartBoundsProvider = () => this.canvasBoundsContainer.getBounds(CanvasElement.PANE_UUID(CHART_UUID));
const chartPaneId = CanvasElement.PANE_UUID(CHART_UUID);
const mainChartBoundsProvider = () => this.canvasBoundsContainer.getBounds(chartPaneId);
this.registerDataSeriesTypeDrawer('LINEAR', new LinearDrawer());
this.registerDataSeriesTypeDrawer('HISTOGRAM', new HistogramDrawer());
this.registerDataSeriesTypeDrawer('TREND_HISTOGRAM', new TrendHistogramDrawer());
Expand Down
11 changes: 7 additions & 4 deletions src/chart/components/pane/pane.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,16 @@ export class PaneComponent extends ChartBaseElement {
yAxisLabelsGenerator: NumericYAxisLabelsGenerator,
yAxisState: YAxisConfig,
) {
const chartPaneId = CanvasElement.PANE_UUID(uuid);
const gridComponent = new GridComponent(
this.mainCanvasModel,
scale,
this.config,
yAxisState,
`PANE_${uuid}_grid_drawer`,
this.drawingManager,
() => this.canvasBoundsContainer.getBounds(CanvasElement.PANE_UUID(uuid)),
() => this.canvasBoundsContainer.getBounds(CanvasElement.PANE_UUID(uuid)),
() => this.canvasBoundsContainer.getBounds(chartPaneId),
() => this.canvasBoundsContainer.getBounds(chartPaneId),
() => [],
() => yAxisLabelsGenerator.generateNumericLabels(),
);
Expand All @@ -153,9 +154,10 @@ export class PaneComponent extends ChartBaseElement {
* @returns {Unsubscriber}
*/
private createYPanHandler(uuid: string, scale: ScaleModel): [Unsubscriber, DragNDropYComponent] {
const chartPaneId = CanvasElement.PANE_UUID(uuid);
const dragNDropComponent = this.chartPanComponent.chartAreaPanHandler.registerChartYPanHandler(
scale,
this.canvasBoundsContainer.getBoundsHitTest(CanvasElement.PANE_UUID(uuid)),
this.canvasBoundsContainer.getBoundsHitTest(chartPaneId),
);
return [
() => {
Expand All @@ -174,7 +176,8 @@ export class PaneComponent extends ChartBaseElement {

public createExtentComponent(options?: AtLeastOne<YExtentCreationOptions>) {
const extentIdx = this.yExtentComponents.length;
const getBounds = () => this.canvasBoundsContainer.getBounds(CanvasElement.PANE_UUID(this.uuid));
const chartPaneId = CanvasElement.PANE_UUID(this.uuid);
const getBounds = () => this.canvasBoundsContainer.getBounds(chartPaneId);
const scaleModel =
options?.scale ??
new SyncedByXScaleModel(this.mainScale, this.config, getBounds, this.canvasAnimation);
Expand Down
10 changes: 6 additions & 4 deletions src/chart/model/scaling/viewport.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ export abstract class ViewportModel extends ChartBaseElement implements Viewable
* @returns {Pixel} - The pixel value of the given unit value in the Y-axis.
*/
toY(unit: Unit): Pixel {
const bounds = this.getBounds();
if (this.inverseY) {
return this.getBounds().y + unitToPixels(unit - this.yStart, this.zoomY);
return bounds.y + unitToPixels(unit - this.yStart, this.zoomY);
} else {
// inverse by default because canvas calculation [0,0] point starts from top-left corner
return this.getBounds().y + this.getBounds().height - unitToPixels(unit - this.yStart, this.zoomY);
return bounds.y + bounds.height - unitToPixels(unit - this.yStart, this.zoomY);
}
}

Expand Down Expand Up @@ -210,13 +211,14 @@ export abstract class ViewportModel extends ChartBaseElement implements Viewable
* @returns {void}
*/
fromY(px: Pixel): Unit {
const normalizedPx = px - this.getBounds().y;
const bounds = this.getBounds();
const normalizedPx = px - bounds.y;
if (this.inverseY) {
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(
this.getBounds().height - normalizedPx + unitToPixels(this.yStart, this.zoomY),
bounds.height - normalizedPx + unitToPixels(this.yStart, this.zoomY),
this.zoomY,
);
}
Expand Down

0 comments on commit 1513839

Please sign in to comment.