Skip to content

Commit

Permalink
typescript reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
bmschmidt committed Feb 8, 2023
1 parent 1f86360 commit 650806d
Show file tree
Hide file tree
Showing 16 changed files with 316 additions and 330 deletions.
16 changes: 4 additions & 12 deletions dist/deepscatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17157,15 +17157,6 @@ void main() {
}
`;
const frag_shader = "#ifdef GL_OES_standard_derivatives\n#extension GL_OES_standard_derivatives : enable\n#endif\n\nprecision mediump float;\n#define GLSLIFY 1\n\nvarying vec4 fill;\nvarying vec2 letter_pos;\nvarying float point_size;\n\nuniform float u_only_color;\nuniform float u_color_picker_mode;\n//uniform float u_use_glyphset;\n//uniform sampler2D u_glyphset;\n\nfloat delta = 0.0, alpha = 1.0;\n\nbool out_of_circle(in vec2 coord) {\n vec2 cxy = 2.0 * coord - 1.0;\n float r_sq = dot(cxy, cxy);\n if (r_sq > 1.03) {return true;}\n return false;\n}\n\nbool out_of_hollow_circle(in vec2 coord) {\n vec2 cxy = 2.0 * coord - 1.0;\n float r_sq = dot(cxy, cxy);\n if (r_sq > 1.01) {return true;}\n float distance_from_edge = (1.0 - r_sq) * point_size;\n if (distance_from_edge > 4.0) {return true;}\n return false;\n}\n\nbool out_of_triangle(in vec2 coord) {\n if (coord.y > (2. * abs(coord.x - .5))) {\n return false;\n }\n return true;\n}\n\nvoid main() {\n if (u_only_color >= -1.5) {\n gl_FragColor = vec4(0., 0., 0., 1./255.);\n return;\n }\n\n float alpha = fill.a;\n// if (u_use_glyphset == 0. || point_size < 5.0) {\n if (out_of_circle(gl_PointCoord)) {\n discard;\n return;\n }\n vec2 cxy = 2.0 * gl_PointCoord - 1.0;\n float r = dot(cxy, cxy);\n #ifdef GL_OES_standard_derivatives\n delta = fwidth(r);\n alpha *= (1.0 - smoothstep(1.0 - delta, 1.0 + delta, r));\n #endif\n/* } else {\n vec2 coords = letter_pos + gl_PointCoord/8.;\n// vec2 coords = vec2(.2, .2);\n vec4 sprite = texture2D(u_glyphset, coords);\n alpha *= (sprite.a); \n// fill = vec4(1.0, 1.0, 1.0, alpha); \n if (alpha <= 0.03) discard;\n }*/\n // Pre-blend the alpha channel.\n if (u_color_picker_mode >= 1.) {\n // no alpha when color picking; we use all four channels for that.\n gl_FragColor = fill;\n } else {\n gl_FragColor = vec4(fill.rgb * alpha, alpha);\n }\n\n}\n";
function isOpChannel(input) {
return input.op !== void 0;
}
function isLambdaChannel(input) {
return input.lambda !== void 0;
}
function isConstantChannel(input) {
return input.constant !== void 0;
}
var lodash = { exports: {} };
/**
* @license
Expand Down Expand Up @@ -23723,15 +23714,13 @@ class Color extends Aesthetic {
this.aesthetic_map.set_color(this.id, this.texture_buffer);
}
update(encoding) {
console.log("UPDATING COLOR");
if (isConstantChannel(encoding)) {
encoding.constant = Color.convert_color(encoding.constant);
}
super.update(encoding);
this.current_encoding = encoding;
if (!isConstantChannel(encoding)) {
if (encoding.range && typeof encoding.range[0] === "string") {
console.log("encoding to buffer");
this.encode_for_textures(encoding.range);
this.post_to_regl_buffer();
} else if (encoding.range) {
Expand Down Expand Up @@ -36010,7 +35999,7 @@ class LabelMaker extends Renderer {
);
this.bind_zoom(scatterplot._renderer.zoom);
}
start(ticks2 = 1e6) {
start(ticks2 = 1e9) {
if (this.timer) {
this.timer.stop();
}
Expand Down Expand Up @@ -36039,6 +36028,9 @@ class LabelMaker extends Renderer {
this.label_key = label_key;
for (const feature of featureset.features) {
const { properties, geometry } = feature;
if (properties === null) {
continue;
}
if (geometry.type === "Point") {
const size = (_a2 = properties[size_key]) != null ? _a2 : 16;
let label = "";
Expand Down
168 changes: 85 additions & 83 deletions docs/classes/default.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"scripts": {
"dev": "vite --port 3344 --host",
"build": "vite build",
"prepublish": "vite build && npx typedoc --ignoreCompilerErrors src/deepscatter.ts",
"prepublishOnly": "vite build && typedoc --skipErrorChecking src/deepscatter.ts",
"test": "playwright test",
"lint": "eslint src"
},
Expand Down
6 changes: 3 additions & 3 deletions src/Aesthetic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
import type Scatterplot from './deepscatter';
import type { Regl, Texture2D } from 'regl';
import type { TextureSet } from './AestheticSet';
import {
/*import {
isOpChannel,
isLambdaChannel,
isConstantChannel,
FunctionalChannel,
ConstantBool,
BooleanChannel,
} from './types';
} from './';*/
import type {
Channel,
OpChannel,
Expand All @@ -27,7 +27,7 @@ import type {
OpArray,
JitterChannel,
JitterRadiusMethod,
} from './types';
} from './';
import type { QuadtileSet } from './Dataset';
import { Vector, tableToIPC, makeVector } from 'apache-arrow';
import { StructRowProxy } from 'apache-arrow/row/struct';
Expand Down
1 change: 0 additions & 1 deletion src/AestheticSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { Regl, Texture2D } from 'regl';
import { stateful_aesthetics } from './StatefulAesthetic';
import type Scatterplot from './deepscatter';
import type { QuadtileSet } from './Dataset';
import type { Encoding } from './types';
import type { StatefulAesthetic } from './StatefulAesthetic';

export class AestheticSet {
Expand Down
4 changes: 0 additions & 4 deletions src/ColorAesthetic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import {
} from 'd3-scale';
import { rgb } from 'd3-color';
import * as d3Chromatic from 'd3-scale-chromatic';
import type { ColorChannel } from './types';
const palette_size = 4096;
import { randomLcg } from 'd3-random';
import { isOpChannel, isLambdaChannel, isConstantChannel } from './types';

/*function to_buffer(data: number[] | number[][]) {
output.set(data.flat());
Expand Down Expand Up @@ -244,15 +242,13 @@ export class Color extends Aesthetic<
}

update(encoding: ColorChannel) {
console.log('UPDATING COLOR');
if (isConstantChannel(encoding)) {
encoding.constant = Color.convert_color(encoding.constant);
}
super.update(encoding);
this.current_encoding = encoding;
if (!isConstantChannel(encoding)) {
if (encoding.range && typeof encoding.range[0] === 'string') {
console.log('encoding to buffer');
this.encode_for_textures(encoding.range);
this.post_to_regl_buffer();
} else if (encoding.range) {
Expand Down
1 change: 0 additions & 1 deletion src/Dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { Tile, Rectangle, QuadTile, ArrowTile, p_in_rect } from './tile';
import { range, min, max, bisectLeft, extent, sum } from 'd3-array';
import { APICall, PointUpdate } from './types';
import Scatterplot from './deepscatter';
import {
RecordBatch,
Expand Down
4 changes: 2 additions & 2 deletions src/StatefulAesthetic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const dimensions = {
y0: Y0,
} as const;

type concrete_aesthetics =
export type ConcreteAesthetic =
| X
| Y
| Size
Expand All @@ -37,7 +37,7 @@ import type { QuadtileSet } from './Dataset';
import type { Regl } from 'regl';
import type { TextureSet } from './AestheticSet';

export abstract class StatefulAesthetic<T extends concrete_aesthetics> {
export abstract class StatefulAesthetic<T extends ConcreteAesthetic> {
// An aesthetic that tracks two states--current and last.
// The point is to handle transitions.
// It might make sense to handle more than two states, but there are
Expand Down
14 changes: 5 additions & 9 deletions src/deepscatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@ import merge from 'lodash.merge';
import Zoom from './interaction';
import { ReglRenderer } from './regl_rendering';
import { Dataset } from './Dataset';
import type {
APICall,
LambdaChannel,
onZoomCallback,
OpChannel,
} from './types';
import type { StructRowProxy } from 'apache-arrow';
import type { FeatureCollection } from 'geojson';
import { LabelMaker, LabelOptions } from './label_rendering';
import { Renderer } from './rendering';
import type { Tile } from './tile';

import type { ConcreteAesthetic } from './StatefulAesthetic';
// DOM elements that deepscatter uses.
const base_elements = [
{
Expand Down Expand Up @@ -51,6 +45,7 @@ export default class Scatterplot<T extends Tile> {
// The queue of draw calls are a chain of promises.
private plot_queue: Promise<void> = Promise.resolve(0);
public prefs: APICall;
// Whether the scatterplot has finished loading.
ready: Promise<void>;
public click_handler: ClickFunction;
public tooltip_handler: TooltipHTML;
Expand Down Expand Up @@ -147,7 +142,7 @@ export default class Scatterplot<T extends Tile> {
*
* @param name The name of the new column to be created. If it already exists, this will throw an error in invocation
* @param codes The codes to be assigned labels. This can be either a list of ids (in which case all ids will have the value 1.0 assigned)
* **or** a keyed of values like {'Rome': 3, 'Vienna': 13} in which case the numeric values will be used.
* **or** a keyed of values like `{'Rome': 3, 'Vienna': 13}` in which case the numeric values will be used.
* @param key_field The field in which to look for the identifiers.
*/
add_identifier_column(
Expand Down Expand Up @@ -185,6 +180,7 @@ export default class Scatterplot<T extends Tile> {
* @param name A unique key to associate with this labelset. Labels can be enabled or disabled using this key.
* @param label_key The text field in which the labels are stored in the geojson object.
* @param size_key A field in the dataset to associate with the *size* of the labels.
* @param label_options Additional custom passed to the labeller.
*
* Usage:
*
Expand Down Expand Up @@ -447,7 +443,7 @@ export default class Scatterplot<T extends Tile> {
* @returns
*/

public dim(dimension: string) : <T extends Aesthetic> {
public dim(dimension: string): ConcreteAesthetic {
return this._renderer.aes.dim(dimension).current as T;
}

Expand Down
Loading

0 comments on commit 650806d

Please sign in to comment.