-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): preserve the zoom status only when needed (#974)
* fix: preserve the zoom status only when needed * chore: format * chore: move import * chore: remove imports * chore: remove unused
- Loading branch information
Showing
4 changed files
with
90 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { HiGlassSpec, View } from '@gosling-lang/higlass-schema'; | ||
import { preverseZoomStatus } from './higlass-zoom-config'; | ||
|
||
describe('Management of HiGlass view configs', () => { | ||
const viewBase: Pick<View, 'tracks' | 'layout'> = { | ||
tracks: { | ||
top: [], | ||
left: [], | ||
center: [], | ||
right: [], | ||
bottom: [], | ||
gallery: [], | ||
whole: [] | ||
}, | ||
layout: { | ||
x: 0, | ||
y: 0, | ||
w: 0, | ||
h: 0 | ||
} | ||
}; | ||
const prev: HiGlassSpec = { | ||
views: [{ ...viewBase, uid: 'existing-view', initialXDomain: [0, 1], initialYDomain: [0, 1] }], | ||
zoomLocks: { locksByViewUid: {}, locksDict: {} }, | ||
locationLocks: { locksByViewUid: {}, locksDict: {} } | ||
}; | ||
it('Should preserve zoom status', () => { | ||
const cur: HiGlassSpec = { | ||
views: [ | ||
{ ...viewBase, uid: 'existing-view', initialXDomain: [0, 1], initialYDomain: [0, 1] }, | ||
{ ...viewBase, uid: 'new-view', initialXDomain: [0, 999], initialYDomain: [0, 999] } | ||
], | ||
zoomLocks: { | ||
locksByViewUid: { | ||
'existing-view': 'lock-id', | ||
'new-view': 'lock-id' | ||
}, | ||
locksDict: {} | ||
}, | ||
locationLocks: { locksByViewUid: {}, locksDict: {} } | ||
}; | ||
preverseZoomStatus(cur, prev); | ||
expect(cur.views[0].initialXDomain).toEqual(cur.views[1].initialXDomain); | ||
}); | ||
it("Shouldn't preserve zoom status", () => { | ||
// This example is a new visualization, not containing any previous view. | ||
const cur: HiGlassSpec = { | ||
views: [ | ||
{ ...viewBase, uid: 'new-view-1', initialXDomain: [0, 1], initialYDomain: [0, 1] }, | ||
{ ...viewBase, uid: 'new-view-2', initialXDomain: [0, 999], initialYDomain: [0, 999] } | ||
], | ||
zoomLocks: { | ||
locksByViewUid: { | ||
'new-view-1': 'lock-id', | ||
'new-view-2': 'lock-id' | ||
}, | ||
locksDict: {} | ||
}, | ||
locationLocks: { locksByViewUid: {}, locksDict: {} } | ||
}; | ||
preverseZoomStatus(cur, prev); | ||
expect(cur.views[0].initialXDomain).not.toEqual(cur.views[1].initialXDomain); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { HiGlassSpec } from '@gosling-lang/higlass-schema'; | ||
|
||
/** | ||
* This makes sure that all the current zooming status is preserved when new tracks are added | ||
*/ | ||
export const preverseZoomStatus = (newSpec: HiGlassSpec, prevSpec: HiGlassSpec) => { | ||
newSpec.views.forEach(view => { | ||
const viewUid = view.uid!; | ||
const isNewView = !prevSpec.views.find(v => v.uid === viewUid); | ||
if (isNewView) { | ||
// if this view is linked with another view, we need to preverse the current zooming status of this view from the linked view | ||
// Otherwise, all the views that is linked with this view will be reset to the original zooming position | ||
const { locksByViewUid } = newSpec.zoomLocks; | ||
const lockUid = locksByViewUid[viewUid]; | ||
const linkedViewUid = Object.entries(locksByViewUid).find(([_, uid]) => _ && uid === lockUid)?.[0]; | ||
// Only if the linked view existed in the previous spec, we copy the zooming status | ||
const linkedViewExistedPrev = !!prevSpec.views.find(v => v.uid === linkedViewUid); | ||
if (linkedViewUid && linkedViewExistedPrev) { | ||
// We found a linked view, so copy the current zooming status | ||
view.initialXDomain = prevSpec.views.find(v => v.uid === linkedViewUid)?.initialXDomain; | ||
view.initialYDomain = prevSpec.views.find(v => v.uid === linkedViewUid)?.initialYDomain; | ||
} | ||
} | ||
}); | ||
}; |