Skip to content

Commit

Permalink
fix: misc typing improvements with strict
Browse files Browse the repository at this point in the history
  • Loading branch information
bmschmidt committed Apr 3, 2024
1 parent 634fe93 commit 947618f
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 177 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
}
}
],
"typescript-eslint/no-unnecessary-type-assertion": "off",
"unicorn/consistent-destructuring": "off",
"unicorn/new-for-builtins": "off",
"unicorn/prevent-abbreviations": "off",
Expand Down
39 changes: 18 additions & 21 deletions src/aesthetics/Aesthetic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { TextureSet } from './AestheticSet';
import {
isConstantChannel,
} from '../typing';
import { isConstantChannel } from '../typing';
import { Type, Vector } from 'apache-arrow';
import { StructRowProxy } from 'apache-arrow/row/struct';
import { isNumber } from 'lodash';
Expand All @@ -22,7 +20,7 @@ import { Scatterplot } from '../scatterplot';
export abstract class Aesthetic<
ChannelType extends DS.ChannelType,
Input extends DS.InType = DS.NumberIn,
Output extends DS.OutType = DS.NumberOut
Output extends DS.OutType = DS.NumberOut,
> {
public abstract default_constant: Output['rangeType'];
public abstract default_range: [Output['rangeType'], Output['rangeType']];
Expand All @@ -31,24 +29,23 @@ export abstract class Aesthetic<
public _texture_buffer: Float32Array | Uint8Array | null = null;
protected abstract _func?: (d: Input['domainType']) => Output['rangeType'];
public aesthetic_map: TextureSet;
public column : Vector<Input['arrowType']> | null;
public column: Vector<Input['arrowType']> | null = null;

// cache of the d3 scale
public encoding: ChannelType;
public id: string;
constructor(
encoding: ChannelType | null,
scatterplot: Scatterplot,
aesthetic_map: TextureSet,
id: string
id: string,
) {
this.aesthetic_map = aesthetic_map;
if (this.aesthetic_map === undefined) {

throw new Error('Aesthetic map is undefined');
}
if (typeof this.aesthetic_map === 'function') {
throw new Error("WTF")
throw new Error('WTF');
}
this.scatterplot = scatterplot;

Expand All @@ -57,7 +54,7 @@ export abstract class Aesthetic<

if (encoding === undefined) {
throw new Error(
'Updates with undefined should be handled upstream of the aesthetic.'
'Updates with undefined should be handled upstream of the aesthetic.',
);
}

Expand All @@ -68,7 +65,7 @@ export abstract class Aesthetic<

if (isNumber(encoding)) {
throw new Error(
`As of deepscatter 3.0, you must pass {constant: ${encoding}}, not just "${encoding}`
`As of deepscatter 3.0, you must pass {constant: ${encoding}}, not just "${encoding}`,
);
}

Expand All @@ -86,17 +83,17 @@ export abstract class Aesthetic<
}

abstract apply(point: Datum): Output['rangeType'];

abstract toGLType(val: Output['rangeType']): Output['glType'];

get webGLDomain() {
console.log("No method for webGLDomain")
return [0, 1] as [number, number]
console.log('No method for webGLDomain');
return [0, 1] as [number, number];
}
default_data(): Uint8Array | Float32Array | Array<number> {
const default_value = this.toGLType(this.default_constant);
return Array(this.aesthetic_map.texture_size).fill(
default_value
default_value,
) as Array<number>;
}

Expand All @@ -118,7 +115,7 @@ export abstract class Aesthetic<
return this.aesthetic_map.get_position(this.id);
}

get texture_buffer() : Uint8Array {
get texture_buffer(): Uint8Array {
if (this._texture_buffer) {
return this._texture_buffer as Uint8Array;
}
Expand All @@ -133,14 +130,14 @@ export abstract class Aesthetic<

arrow_column(): Vector<Input['arrowType']> | null {
if (this.column) {
return this.column
return this.column;
}
if (this.field === null || this.field === undefined) {
return this.column = null;
return (this.column = null);
}
return this.column = this.dataset.root_tile.record_batch.getChild(this.field) as Vector<
Input['arrowType']
>;
return (this.column = this.dataset.root_tile.record_batch.getChild(
this.field,
) as Vector<Input['arrowType']>);
}

is_dictionary(): boolean {
Expand Down
39 changes: 19 additions & 20 deletions src/interaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable no-underscore-dangle */
/* eslint-disable @typescript-eslint/unbound-method */

import { select } from 'd3-selection';
import { timer } from 'd3-timer';
import { D3ZoomEvent, zoom, zoomIdentity } from 'd3-zoom';
Expand Down Expand Up @@ -78,7 +80,6 @@ export class Zoom {
.translate(width / 2, height / 2)
.scale(k)
.translate(-scales.x(x), -scales.y(y));

canvas.transition().duration(duration).call(zoomer.transform, t);
}

Expand All @@ -102,9 +103,9 @@ export class Zoom {
.style('background', 'ivory'),
(update) =>
update.html((d) =>
this.scatterplot.tooltip_html(d.data, this.scatterplot)
this.scatterplot.tooltip_html(d.data, this.scatterplot),
),
(exit) => exit.call((e) => e.remove())
(exit) => exit.call((e) => e.remove()),
);

els
Expand Down Expand Up @@ -150,11 +151,7 @@ export class Zoom {
[width, height],
])
.on('zoom', (event: D3ZoomEvent<Element, unknown>) => {
try {
document.getElementById('tooltipcircle').remove();
} catch (error) {
// console.log(error);
}
document.getElementById('tooltipcircle')?.remove();
this.transform = event.transform;
this.restart_timer(10 * 1000);

Expand All @@ -179,19 +176,19 @@ export class Zoom {

const annotations: Annotation[] = data.map((d) => {
return {
x: x_((xdim.apply(d))),
y: y_((ydim.apply(d))),
data: d,
dx: 0,
dy: 30,
}
})
x: x_(xdim.apply(d)),
y: y_(ydim.apply(d)),
data: d,
dx: 0,
dy: 30,
};
});
this.html_annotation(annotations);

const sel = this.svg_element_selection.select('#mousepoints');
sel
.selectAll('circle.label')
.data(data, (d_ : StructRowProxy) => d_.ix as number) // Unique identifier to not remove existing.
.data(data, (d_: StructRowProxy) => d_.ix as number) // Unique identifier to not remove existing.
.join(
(enter) =>
enter
Expand All @@ -208,7 +205,7 @@ export class Zoom {
(exit) =>
exit.call((e) => {
e.remove();
})
}),
)
.on('click', (ev, dd) => {
this.scatterplot.click_function(dd, this.scatterplot);
Expand Down Expand Up @@ -238,14 +235,16 @@ export class Zoom {
});
}

current_corners(): Rectangle | undefined {
current_corners(): Rectangle {
// The corners of the current zoom transform, in data coordinates.
const { width, height } = this;

// Use the rescaled versions of the scales.
const scales = this.scales();
if (scales === undefined) {
return;
throw new Error(
'Attempting to get map view before scales have been created',
);
}
const { x_, y_ } = scales;

Expand Down Expand Up @@ -386,7 +385,7 @@ export class Zoom {

export function window_transform(
x_scale: ScaleLinear<number, number, never>,
y_scale: ScaleLinear<number, number, never>
y_scale: ScaleLinear<number, number, never>,
) {
// width and height are svg parameters; x and y scales project from the data x and y into the
// the webgl space.
Expand Down
Loading

0 comments on commit 947618f

Please sign in to comment.