Skip to content

Commit

Permalink
fixes to typing, removing unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
bmschmidt committed May 3, 2024
1 parent 1a3e641 commit 0d61843
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/aesthetics/ScaledAesthetic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export abstract class ScaledAesthetic<
> extends Aesthetic<ChannelType, Input, Output> {
protected _scale:
| ScaleContinuousNumeric<Input['domainType'], Output['rangeType']>
| ScaleOrdinal<Input['domainType'], Output['rangeType']>;
| ScaleOrdinal<Input['domainType'], Output['rangeType']>
| null = null;
public default_transform: DS.Transform = 'linear';
abstract default_range: [Output['rangeType'], Output['rangeType']];
protected categorical; // Whether this is built on a dictionary variable.
Expand Down
14 changes: 12 additions & 2 deletions src/glsl/general.vert
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,21 @@ highp float ix_to_random(in float ix, in float seed) {
highp float b = 78.233;
highp float c = 43758.5453;
highp float dt = dot(co.xy, vec2(a, b));
highp float sn = mod(dt, 3.14);
highp float sn = mod(dt, 3.141592654);
return fract(sin(sn) * c);
}

highp float tix_rix_to_random_seed(in float tix, in float rix) {
// For high numbers, taking the log avoids coincidence.
highp float seed2 = log(ix + 2.) + 1.;
vec2 co = vec2(seed2, seed);
highp float a = 12.9898;
highp float b = 78.233;
highp float c = 43758.5453;
highp float dt = dot(co.xy, vec2(a, b));
highp float sn = mod(dt, 3.14);
return fract(sin(sn) * c);
}


// The fill color.
Expand All @@ -374,7 +385,6 @@ vec4 discard_me = vec4(100.0, 100.0, 1.0, 1.0);

// Initialized in the main loop
// mat3 from_coord_to_gl;

const float e = 1.618282;
// I've been convinced.
const float tau = 2. * 3.14159265359;
Expand Down
22 changes: 21 additions & 1 deletion src/scatterplot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class Scatterplot {
ready: Promise<void>;

public click_handler: ClickFunction;
public mouseover_handler: PointMouseoverFunction;
private hooks: Record<string, Hook> = {};
public tooltip_handler: TooltipHTML;
public label_click_handler: LabelClick;
Expand Down Expand Up @@ -585,7 +586,7 @@ export class Scatterplot {
*/

public dim(dimension: DS.Dimension): ConcreteAesthetic {
return this._renderer!.aes.dim(dimension)!.current;
return this._renderer.aes.dim(dimension).current;
}

set tooltip_html(func) {
Expand All @@ -597,6 +598,14 @@ export class Scatterplot {
return this.tooltip_handler.f;
}

get mouseover_callback() {
return this.mouseover_handler.f;
}

set mouseover_callback(func) {
this.mouseover_handler.f = func;
}

set label_click(
func: (d: Record<string, unknown>, scatterplot: Scatterplot) => void,
) {
Expand Down Expand Up @@ -960,6 +969,17 @@ class ChangeToHighlitPointFunction extends SettableFunction<
}
}

class PointMouseoverFunction extends SettableFunction<void, StructRowProxy[]> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
default(points: StructRowProxy[], plot: Scatterplot | undefined = undefined) {
return;
}
}

/**
* A holder for a function that returns the HTML that should appear in a tooltip next to a point.
*/

class TooltipHTML extends SettableFunction<string> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
default(point: StructRowProxy, plot: Scatterplot | undefined = undefined) {
Expand Down
18 changes: 6 additions & 12 deletions src/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,17 +714,15 @@ export class DataSelection {
*
* @param i the index of the row to get
*/
get(i: number | undefined): StructRowProxy {
get(i: number | undefined): StructRowProxy | undefined {
if (i === undefined) {
i = this.cursor;
}
if (i > this.selectionSize) {
throw new Error(
`Index ${i} out of bounds for selection of size ${this.selectionSize}`,
);
undefined;
}
let currentOffset = 0;
let relevantTile: Tile = undefined;
let relevantTile: Tile | undefined = undefined;
let current_tile_ix = 0;
for (const match_length of this.match_count) {
if (i < currentOffset + match_length) {
Expand All @@ -735,7 +733,7 @@ export class DataSelection {
currentOffset += match_length;
}
if (relevantTile === undefined) {
return null;
return undefined;
}
const column = relevantTile.record_batch.getChild(
this.name,
Expand All @@ -745,7 +743,7 @@ export class DataSelection {
for (let j = 0; j < column.length; j++) {
if (column.get(j)) {
if (ix_in_match === offset) {
return relevantTile.record_batch.get(j);
return relevantTile.record_batch.get(j) || undefined;
}
ix_in_match++;
}
Expand All @@ -769,7 +767,7 @@ export class DataSelection {
name: string,
codes: string[] | bigint[] | number[],
key_field: string,
options: IdentifierOptions = {},
// options: IdentifierOptions = {},
): Promise<void> {
if (this.dataset.has_column(name)) {
throw new Error(`Column ${name} already exists, can't create`);
Expand All @@ -788,10 +786,6 @@ export class DataSelection {
console.error('Unable to match type', typeof codes[0]);
}
}

async add_boolean_column(name: string, field: string): Promise<void> {
throw new Error('Method not implemented.');
}
}

function bigintmatcher(field: string, matches: bigint[]) {
Expand Down
34 changes: 27 additions & 7 deletions src/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,20 @@ export class Tile {
url: string;
//public child_locations: string[] = [];

/**
*
* @param key Either the string identifier of the tile,
* OR a `TileManifest` object including an identifier. *
* @param parent The parent tile -- used to navigate through the tree.
* @param dataset The full atlas dataset of which this tile is a part.
*/
constructor(
key: string | Partial<TileManifest>,
key: string | (Partial<TileManifest> & { key: string }),
parent: Tile | null,
dataset: Dataset,
base_url: string,
) {
// If it's just initiated with a key, build that into a minimal manifest.
let manifest: Partial<TileManifest>;
let manifest: Partial<TileManifest> & { key: string };
if (typeof key === 'string') {
manifest = { key };
} else {
Expand All @@ -104,7 +110,6 @@ export class Tile {
// Grab the next identifier off the queue. This should be async safe with the current setup, but
// the logic might fall apart in truly parallel situations.
this.numeric_id = tile_identifier++;
this.url = base_url;

if (isCompleteManifest(manifest)) this.manifest = manifest;

Expand Down Expand Up @@ -290,7 +295,7 @@ export class Tile {
throw new Error('Attempted to set an incomplete manifest.');
}
this._children = manifest.children.map((k: TileManifest | string) => {
return new Tile(k, this, this.dataset, this.url);
return new Tile(k, this, this.dataset);
});
this.highest_known_ix = manifest.max_ix;
this._completeManifest = manifest;
Expand Down Expand Up @@ -402,7 +407,7 @@ export class Tile {
return existing.batch;
}

let url = `${this.url}/${this.key}.feather`;
let url = `${this.dataset.base_url}/${this.key}.feather`;
if (suffix !== null) {
// 3/4/3
// suffix: 'text'
Expand Down Expand Up @@ -602,20 +607,25 @@ export class Tile {
return this._children;
}

// Asynchronously forces generation of all child
// tiles, and then returns them.
async allChildren(): Promise<Array<Tile>> {
if (this._children.length) {
return this._children;
}
if (this._partialManifest?.children) {
for (const child of this.manifest.children) {
const childTile = new Tile(child, this, this.dataset, this.url);
const childTile = new Tile(child, this, this.dataset);
this._children.push(childTile);
}
return this._children;
}
await this.populateManifest();
return this._children;
}

// Quadtree tiles can have their limits calculated based on the structure.
// There are cases where these may not be exact.
get theoretical_extent(): Rectangle {
if (this.dataset.tileStucture === 'other') {
// Only three-length-keys are treated as quadtrees.
Expand Down Expand Up @@ -649,6 +659,16 @@ export function p_in_rect(p: Point, rect: Rectangle | undefined) {
);
}

/**
* Returns the coordinates of a 'macrotile' for any given tile.
* This is an experimental feature that is not part of the public API.
* @deprecated
*
* @param key The key to get the macrotile of
* @param size The size of each macrotile, in z.
* @param parents The implicit parents of each macrotile. (If 2, then the macrotile 0/0/0 would contain all tiles at depth 2 and 3)
* @returns
*/
function macrotile(key: string, size = 2, parents = 2) {
let [z, x, y] = key.split('/').map((d) => parseInt(d));
let moves = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/typing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function isCompleteManifest(
'min_ix',
'max_ix',
'extent',
]) {
] as const) {
if (manifest[k] === undefined) {
return false;
}
Expand Down

0 comments on commit 0d61843

Please sign in to comment.