Skip to content

Commit

Permalink
Merge branch 'master' into etowahadams/fetch-header
Browse files Browse the repository at this point in the history
  • Loading branch information
etowahadams authored Sep 25, 2023
2 parents c24d96e + fdc8be5 commit d96eb41
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 10 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## [0.10.3](https://github.com/gosling-lang/gosling.js/compare/v0.10.2...v0.10.3) (2023-09-25)


### Bug Fixes

* **core:** first track ID should not be lost after compile ([#972](https://github.com/gosling-lang/gosling.js/issues/972)) ([f73410d](https://github.com/gosling-lang/gosling.js/commit/f73410d7a16435fd99cc14ef3e9c1eaf15de61d0))



## [0.10.2](https://github.com/gosling-lang/gosling.js/compare/v0.10.1...v0.10.2) (2023-09-22)


### Bug Fixes

* **core:** preserve zoom status when new track added ([#971](https://github.com/gosling-lang/gosling.js/issues/971)) ([875a9b5](https://github.com/gosling-lang/gosling.js/commit/875a9b54911fb259b795eab7afad853d1ef3e3b7))
* **core:** rule mark calculation in circular layout ([#967](https://github.com/gosling-lang/gosling.js/issues/967)) ([09a5207](https://github.com/gosling-lang/gosling.js/commit/09a5207fb58c877484911b7158724deec6304f67))



## [0.10.1](https://github.com/gosling-lang/gosling.js/compare/v0.10.0...v0.10.1) (2023-08-02)


Expand Down
8 changes: 7 additions & 1 deletion editor/example/json-spec/responsive-track-wise-comparison.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import type { DomainChrInterval, GoslingSpec, OverlaidTracks, SingleTrack, TemplateTrack } from '@gosling-lang/gosling-schema';
import type {
DomainChrInterval,
GoslingSpec,
OverlaidTracks,
SingleTrack,
TemplateTrack
} from '@gosling-lang/gosling-schema';
import { GOSLING_PUBLIC_DATA } from './gosling-data';

const trackColor = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gosling.js",
"author": "Sehi L'Yi",
"version": "0.10.1",
"version": "0.10.3",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
22 changes: 22 additions & 0 deletions src/compiler/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { EX_SPEC_VISUAL_ENCODING } from '../../editor/example/json-spec/visual-e
import { compile } from './compile';
import { getTheme } from '../core/utils/theme';
import type { GoslingSpec } from '../index';
import { convertToFlatTracks } from './spec-preprocess';
import type { SingleView } from '@gosling-lang/gosling-schema';
import { spreadTracksByData } from '../core/utils/overlay';

describe('compile', () => {
it('compile should not touch the original spec of users', () => {
Expand Down Expand Up @@ -341,5 +344,24 @@ describe('Compiler with UrlToFetchOptions', () => {
{},
urlToFetchOptions
);

describe('Maintain IDs', () => {
it('Overlaid tracks', () => {
const twoTracksWithDiffData: SingleView = {
alignment: 'overlay',
tracks: [
{
id: 'first',
data: { type: 'csv', url: 'http://abc' }
},
{
id: 'second',
data: { type: 'csv', url: 'http://def' }
}
]
};
const flattened = convertToFlatTracks(twoTracksWithDiffData);
const spread = spreadTracksByData(flattened);
expect(spread.map(d => d.id)).toEqual(['first', 'second']);
});
});
4 changes: 2 additions & 2 deletions src/compiler/spec-preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function traverseViewArrangements(spec: GoslingSpec, callback: (tv: Multi
export function convertToFlatTracks(spec: SingleView): Track[] {
if (IsFlatTracks(spec)) {
// This is already `FlatTracks`, so just override the view definition
const base = {...spec, tracks: undefined, id: undefined };
const base = { ...spec, tracks: undefined, id: undefined };
return spec.tracks
.filter(track => !track._invalidTrack)
.map(track => Object.assign(JSON.parse(JSON.stringify(base)), track) as SingleTrack);
Expand All @@ -117,7 +117,7 @@ export function convertToFlatTracks(spec: SingleView): Track[] {
} as Track);
} else {
// Override track definitions from views
const base = {...spec, tracks: undefined, id: undefined };
const base = { ...spec, tracks: undefined, id: undefined };
const newSpec = Object.assign(JSON.parse(JSON.stringify(base)), track) as SingleTrack;
newTracks.push(newSpec);
}
Expand Down
28 changes: 28 additions & 0 deletions src/core/gosling-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ export const GoslingComponent = forwardRef<GoslingRef, GoslingCompProps>((props,
[viewConfig, theme]
);

/**
* This makes sure that all the current zooming status is preserved when new tracks are added
*/
const preverseZoomStatus = (newSpec: gosling.HiGlassSpec, prevSpec: gosling.HiGlassSpec) => {
newSpec.views.forEach(view => {
const viewUid = view.uid!;
const newView = !prevSpec.views.find(v => v.uid === viewUid);
if (newView) {
// 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];
if (linkedViewUid) {
// 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;
}
}
});
};

// TODO: add a `force` parameter since changing `linkingId` might not update vis
const compile = useCallback(() => {
if (props.spec) {
Expand Down Expand Up @@ -121,6 +143,10 @@ export const GoslingComponent = forwardRef<GoslingRef, GoslingCompProps>((props,
if (props.experimental?.reactive && isMountedOnce) {
// Use API to update visualization.
setTimeout(() => {
preverseZoomStatus(
newHiGlassSpec,
hgRef.current?.api.getViewConfig() as gosling.HiGlassSpec
);
hgRef.current?.api.setViewConfig(newHiGlassSpec);
}, DELAY_FOR_CONTAINER_RESIZE_BEFORE_RERENDER);
} else {
Expand All @@ -145,6 +171,8 @@ export const GoslingComponent = forwardRef<GoslingRef, GoslingCompProps>((props,

// TODO: If not necessary, do not update `wrapperSize` (i.e., when responsiveSize is not set)
useEffect(() => {
if (!props.spec?.responsiveSize) return;

const containerElement = document.getElementById(wrapperDivId);
if (!containerElement) return;

Expand Down
2 changes: 1 addition & 1 deletion src/core/mark/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function drawRule(HGC: import('@higlass/types').HGC, trackInfo: any, tile
0.5 // alignment of the line to draw, (0 = inner, 0.5 = middle, 1 = outter)
);

const midR = trackOuterRadius - ((rowPosition + y) / trackHeight) * trackRingSize;
const midR = trackOuterRadius - ((rowPosition + rowHeight - y) / trackHeight) * trackRingSize;
const farR = midR + strokeWidth / 2.0;
const nearR = midR - strokeWidth / 2.0;

Expand Down
16 changes: 14 additions & 2 deletions src/core/utils/overlay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import type { AxisPosition, SingleTrack, OverlaidTrack, Track, ChannelDeep, DataDeep } from '@gosling-lang/gosling-schema';
import type {
AxisPosition,
SingleTrack,
OverlaidTrack,
Track,
ChannelDeep,
DataDeep
} from '@gosling-lang/gosling-schema';
import { IsChannelDeep, IsDataTrack, IsOverlaidTrack, IsSingleTrack, IsDummyTrack } from '@gosling-lang/gosling-schema';

/**
Expand Down Expand Up @@ -77,7 +84,7 @@ export function spreadTracksByData(tracks: Track[]): Track[] {
return [t];
}

const base: Partial<OverlaidTrack> = {...t, id: undefined, overlay: undefined };
const base: Partial<OverlaidTrack> = { ...t, id: undefined, overlay: undefined };
const spread: Track[] = [];
const original: OverlaidTrack = JSON.parse(JSON.stringify(base));
original.overlay = [];
Expand All @@ -88,6 +95,11 @@ export function spreadTracksByData(tracks: Track[]): Track[] {
original.data = subSpec.data;
}

// If the id is undefined, put the first spec to the parent
if (!original.id) {
original.id = subSpec.id;
}

// Determine if this `subSpec` should be added to `overlay` or become a separate track
if (!subSpec.data || isIdenticalDataSpec([original.data, subSpec.data])) {
original.overlay.push(subSpec);
Expand Down
2 changes: 1 addition & 1 deletion src/gosling-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export * from './gosling.schema';
export * from './gosling.schema.guards';
export * from './validate';
export { default as ThemeSchema } from './theme.schema.json';
export { default as GoslingSchema } from './gosling.schema.json';
export { default as GoslingSchema } from './gosling.schema.json';
2 changes: 1 addition & 1 deletion src/higlass-schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './higlass.schema';
export { default as HiGlassSchema } from './higlass.schema.json';
export { default as HiGlassSchema } from './higlass.schema.json';
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export { compile } from './compiler/compile';
export { validateGoslingSpec } from '@gosling-lang/gosling-schema';
export { GoslingComponent } from './core/gosling-component';
export type { GoslingRef } from './core/gosling-component';
export { embed } from './core/gosling-embed';
export { embed } from './core/gosling-embed';

0 comments on commit d96eb41

Please sign in to comment.