Skip to content

Commit 89b9a63

Browse files
committed
cleaner deeptable instantiation pattern
1 parent 1f29cc2 commit 89b9a63

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ city_tiles
2929
test_pages
3030
cities.html
3131
assets
32+
atlas.sh

src/Deeptable.ts

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,57 @@ export class Deeptable {
138138
// Must come after manifest is set.
139139
this.base_url = baseUrl;
140140
this.root_tile = new Tile(defaultManifest, null, this);
141-
const preProcessRootTile = this.root_tile.preprocessRootTileInfo();
142-
143141
// At instantiation, the deeptable isn't ready; only once this
144142
// async stuff is done can the deeptable be used.
145143
// TODO: Add an async static method as the preferred initialization method.
146-
this.promise = preProcessRootTile.then(async () => {
144+
this.promise = this._makePromise(defaultManifest);
145+
}
146+
147+
/**
148+
* Loads a quadtree created by version 2.0 or great of the quadfeather package (including manifests).
149+
*
150+
* @param tileProxy A tileProxy to use for fetching tiles. Can be used to wrap authentication.
151+
* @param baseUrl The base URL of the quadfeather data.
152+
*
153+
*/
154+
static async fromQuadfeather({
155+
tileProxy,
156+
baseUrl,
157+
plot = null,
158+
}: {
159+
tileProxy?: DS.TileProxy;
160+
baseUrl: string;
161+
plot?: Scatterplot | null;
162+
}) {
163+
let manifest: DS.TileManifest;
164+
if (tileProxy !== undefined) {
165+
throw new Error('Not yet supported');
166+
} else {
167+
manifest = await loadTileManifest(baseUrl + '/manifest.feather');
168+
}
169+
170+
const dt = new Deeptable({
171+
tileProxy,
172+
tileManifest: manifest,
173+
baseUrl,
174+
rootKey: '0/0/0',
175+
plot,
176+
});
177+
await dt.promise;
178+
return dt;
179+
}
180+
181+
/**
182+
* Internal function to ensure
183+
*/
184+
protected _makePromise(
185+
tileManifest: Partial<DS.TileManifest> & { key: string },
186+
): Promise<void> {
187+
return this.root_tile.preprocessRootTileInfo().then(async () => {
147188
const batch = await this.root_tile.get_arrow(null);
148189
const schema = batch.schema;
149-
if (!tileManifest) {
190+
// TODO: Cleaner check that it's a lazy manifest
191+
if (!tileManifest.max_ix) {
150192
this.root_tile.manifest =
151193
await this.root_tile.deriveManifestInfoFromTileMetadata();
152194
}
@@ -1188,7 +1230,7 @@ export type TileManifest = {
11881230
extent: Rectangle;
11891231
};
11901232

1191-
export async function tileManifest(url: string) {
1233+
export async function loadTileManifest(url: string): Promise<TileManifest> {
11921234
const data = await fetch(url).then((d) => d.arrayBuffer());
11931235
const tb = tableFromIPC(data);
11941236
const rows: RowFormatManifest[] = [...tb].map(

src/scatterplot.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,11 @@ export class Scatterplot {
373373
tileProxy,
374374
}: DS.DataSpec): Promise<DS.Deeptable> {
375375
if (source_url !== undefined) {
376-
this._root = Deeptable.from_quadfeather(source_url, this, tileProxy);
376+
this._root = await Deeptable.fromQuadfeather({
377+
baseUrl: source_url,
378+
plot: this,
379+
tileProxy,
380+
});
377381
} else if (arrow_table !== undefined) {
378382
this._root = Deeptable.fromArrowTable(arrow_table, this);
379383
} else if (arrow_buffer !== undefined) {

0 commit comments

Comments
 (0)