Skip to content

Commit

Permalink
Merge pull request #129 from nomic-ai/type-exports
Browse files Browse the repository at this point in the history
Type exports
  • Loading branch information
bmschmidt authored Aug 15, 2024
2 parents f09eb86 + 2a31246 commit 26ca7a3
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 25 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,18 @@ dist/tiles/*
co2.feather co2.html
dist
docs
tiles
_deepscatter_tmp
interfaces
modules
temp.html
pubmed.html
index3.html
variables
build
classes
c02*
co2*
donations.html
modules.html
.DS_Store
13 changes: 12 additions & 1 deletion src/deepscatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@ export { Deeptable } from './Deeptable';
export { LabelMaker } from './label_rendering';
export { dictionaryFromArrays } from './utilityFunctions';
export { Tile } from './tile';
export * as types from './shared.d';
export type {
APICall,
Encoding,
NumericScaleChannel,
ColorScaleChannel,
BooleanChannel,
DimensionKeys,
Label,
Labelset,
RowFunction,
CompletePrefs,
} from './shared';
2 changes: 1 addition & 1 deletion src/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Zoom } from './interaction';
import type { AestheticSet } from './aesthetics/AestheticSet';
import { timer, Timer } from 'd3-timer';
import { Deeptable } from './Deeptable';
import type * as DS from './shared.d';
import type * as DS from './shared';
import { Table } from 'apache-arrow';
import { StatefulAesthetic } from './aesthetics/StatefulAesthetic';
import { PositionalAesthetic } from './aesthetics/ScaledAesthetic';
Expand Down
33 changes: 15 additions & 18 deletions src/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ import { Deeptable } from './Deeptable';
import { Scatterplot } from './scatterplot';
import { Tile } from './tile';
import { getTileFromRow } from './tixrixqid';
import type * as DS from './shared.d';
import {
Bool,
StructRowProxy,
Utf8,
Vector,
makeData,
} from 'apache-arrow';
import type * as DS from './shared';
import { Bool, StructRowProxy, Utf8, Vector, makeData } from 'apache-arrow';
import { range } from 'd3-array';
interface SelectParams {
name: string;
Expand Down Expand Up @@ -500,13 +494,19 @@ export class DataSelection {
return this;
}

async removePoints(name: string, points: StructRowProxy[]): Promise<DataSelection> {
async removePoints(
name: string,
points: StructRowProxy[],
): Promise<DataSelection> {
return this.add_or_remove_points(name, points, 'remove');
}

// Non-editable behavior:
// if a single point is added, will also adjust the cursor.
async addPoints(name: string, points: StructRowProxy[]): Promise<DataSelection> {
async addPoints(
name: string,
points: StructRowProxy[],
): Promise<DataSelection> {
return this.add_or_remove_points(name, points, 'add');
}

Expand Down Expand Up @@ -537,9 +537,7 @@ export class DataSelection {
// return columns;
// }

public moveCursorToPoint(
point: StructRowProxy,
) {
public moveCursorToPoint(point: StructRowProxy) {
// The point contains a field called 'ix', which increases in each tile;
// we use this for moving because it lets us do binary search for relevant tile.
const rowNumber = point[Symbol.for('rowIndex')] as number;
Expand Down Expand Up @@ -576,9 +574,8 @@ export class DataSelection {
newName: string,
points: StructRowProxy[],
which: 'add' | 'remove',
) : Promise<DataSelection>{

const matches : Record<string, number[]>= {};
): Promise<DataSelection> {
const matches: Record<string, number[]> = {};
for (const point of points) {
const t = getTileFromRow(point, this.deeptable);
const rowNum = point[Symbol.for('rowIndex')] as number;
Expand All @@ -598,12 +595,12 @@ export class DataSelection {
// Then if there are matches.
if (matches[tile.key] !== undefined) {
const mask = Bitmask.from_arrow(original);
for (const rowNum of matches[tile.key]) {
for (const rowNum of matches[tile.key]) {
if (which === 'add') {
mask.set(rowNum);
} else {
mask.unset(rowNum);
}
}
}
return mask.to_arrow();
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/shared.d.ts → src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export type BoolTransformation = (
* https://vega.github.io/vega-lite/docs/encoding.html
*/

type SignedInt = Int8 | Int16 | Int32;
export type WebGlValue = number | [number, number, number];

// The type in JSON. This does not include Date because only
Expand Down Expand Up @@ -594,8 +593,8 @@ export type RowFunction<T> = (
plot?: Scatterplot | undefined,
) => T;

type ZoomRow = [number, number, number];
type ZoomMatrix = [ZoomRow, ZoomRow, ZoomRow];
// type ZoomRow = [number, number, number];
// type ZoomMatrix = [ZoomRow, ZoomRow, ZoomRow];

///////////

Expand Down
2 changes: 1 addition & 1 deletion src/typing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type * as DS from './shared.d';
import type * as DS from './shared';
const transforms = new Set(['linear', 'sqrt', 'log', 'literal']);

export function isTransform(input: unknown): input is DS.Transform {
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"include": [
"src/**/*.ts",
"src/shared.d.ts"
],
"exclude": [
"node_modules/**/*"
Expand Down

0 comments on commit 26ca7a3

Please sign in to comment.