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

fix: do not emit dateRangeChange in live mode #210

Merged
merged 6 commits into from
Dec 19, 2022
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
2 changes: 1 addition & 1 deletion packages/synchro-charts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@
"minimatch": "3.0.5"
},
"license": "Apache-2.0"
}
}
3 changes: 2 additions & 1 deletion packages/synchro-charts/src/components/sc-table/sc-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export class ScTable implements ChartConfig {
const hasViewPortChanged =
viewportStartDate(this.viewport).getTime() !== start.getTime() ||
viewportEndDate(this.viewport).getTime() !== end.getTime();
if (hasViewPortChanged) {
const isInLiveMode = Boolean(duration);
if (hasViewPortChanged && !isInLiveMode) {
this.onDateRangeChange([start, end, this.viewport.group]);
}
// Update active viewport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('sync chart scene cameras', () => {
const start = new Date(2000, 0, 0);
const end = new Date();
webGLRenderer.updateViewPorts({ start, end, manager: chartScene1 });
expect(chartScene1.updateViewPort).toBeCalledWith({ start, end });
expect(chartScene1.updateViewPort).toBeCalledWith(expect.objectContaining({ start, end }));
});

it('syncs multiple cameras viewport', () => {
Expand All @@ -79,8 +79,8 @@ describe('sync chart scene cameras', () => {
const start = new Date(2000, 0, 0);
const end = new Date();
webGLRenderer.updateViewPorts({ start, end, manager: chartScene1 });
expect(chartScene1.updateViewPort).toBeCalledWith({ start, end });
expect(chartScene2.updateViewPort).toBeCalledWith({ start, end });
expect(chartScene1.updateViewPort).toBeCalledWith(expect.objectContaining({ start, end }));
expect(chartScene2.updateViewPort).toBeCalledWith(expect.objectContaining({ start, end }));
});

it('does not sync camera of removed chart scene', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export class ScWidgetGrid implements ChartConfig {
const hasViewPortChanged =
viewportStartDate(this.viewport).getTime() !== start.getTime() ||
viewportEndDate(this.viewport).getTime() !== end.getTime();
if (hasViewPortChanged) {
const isInLiveMode = Boolean(duration);
if (hasViewPortChanged && !isInLiveMode) {
this.onDateRangeChange([start, end, this.viewport.group]);
}
// Update active viewport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ describe('syncing managers', () => {

/** Manager 1 is updated */
expect(manager1.updateViewPort).toBeCalledTimes(1);
expect(manager1.updateViewPort).toBeCalledWith({ start: START, end: END });
expect(manager1.updateViewPort).toBeCalledWith(expect.objectContaining({ start: START, end: END }));

/** Manager 2 is updated */
expect(manager2.updateViewPort).toBeCalledTimes(1);
expect(manager2.updateViewPort).toBeCalledWith({ start: START, end: END });
expect(manager2.updateViewPort).toBeCalledWith(expect.objectContaining({ start: START, end: END }));
});

it('always updates any managers when syncViewPortGroup is called', () => {
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('syncing managers', () => {

/** The manager which initiated the view port sync is updated */
expect(manager1.updateViewPort).toBeCalledTimes(1);
expect(manager1.updateViewPort).toBeCalledWith({ start: START, end: END });
expect(manager1.updateViewPort).toBeCalledWith(expect.objectContaining({ start: START, end: END }));

/** The other manager, which is in a different view port group, is not updated */
expect(manager2.updateViewPort).not.toBeCalled();
Expand All @@ -136,7 +136,7 @@ describe('syncing managers', () => {
groups.syncViewPortGroup({ start: START, end: END, manager: manager1 });

expect(manager1.updateViewPort).toBeCalledTimes(1);
expect(manager1.updateViewPort).toBeCalledWith({ start: START, end: END });
expect(manager1.updateViewPort).toBeCalledWith(expect.objectContaining({ start: START, end: END }));

expect(manager2.updateViewPort).not.toBeCalled();
});
Expand Down Expand Up @@ -203,6 +203,26 @@ describe('syncing managers', () => {
/** manager added to existing view port group that has had it's viewport synced should have it's viewport synced to the group */
expect(manager2.updateViewPort).not.toBeCalled();
});

it('blocks dateRangeChanged event emission when a duration is passed in', () => {
const groups = new ViewportHandler();

const VIEWPORT_GROUP = 'view-port-group-1';
const START = new Date(2000, 0, 0);
const END = new Date(2001, 0, 0);

const manager = viewportManager(VIEWPORT_GROUP);

groups.add({ manager });

groups.syncViewPortGroup({ start: START, end: END, manager, duration: 60000 });

expect(manager.updateViewPort).toBeCalledWith(
expect.objectContaining({
shouldBlockDateRangeChangedEvent: true,
})
);
});
});

describe('internal clock', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export class ViewportHandler<T extends ViewPortManager> {
}

const updateViewPort = (v: T) => {
v.updateViewPort({ start, end, duration });
const isInLiveMode = Boolean(duration);
v.updateViewPort({ start, end, duration, shouldBlockDateRangeChangedEvent: isInLiveMode });
};

if (manager.viewportGroup) {
Expand Down