Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get bounds optimization #92

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tried to remove "provider" logic at all and pass bounds as is without function? I think it might work since bounds is mutable and new instance shouldn't be created

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if we want to pass bounds as mutable object, we need to refactor all places with such provider logic.
It it very important to keep app stable, because for now we don't have much QA forces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you're right, it might work, even faster than now.

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