Skip to content

Commit 8624e7a

Browse files
committed
partial commit on resizing
1 parent c1f7d2d commit 8624e7a

File tree

7 files changed

+291
-78
lines changed

7 files changed

+291
-78
lines changed

dist/deepscatter.js

Lines changed: 127 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5601,15 +5601,36 @@ class Zoom {
56015601
constructor(selector2, prefs, plot) {
56025602
this.prefs = prefs;
56035603
this.svg_element_selection = select(selector2);
5604-
this.width = +this.svg_element_selection.attr("width");
5605-
this.height = +this.svg_element_selection.attr("height");
5604+
this._width = plot.width;
5605+
this._height = plot.height;
56065606
this.renderers = /* @__PURE__ */ new Map();
56075607
this.scatterplot = plot;
56085608
this.renderers = /* @__PURE__ */ new Map();
56095609
}
5610+
get width() {
5611+
return this._width;
5612+
}
5613+
get height() {
5614+
return this._height;
5615+
}
5616+
resize(width, height) {
5617+
const { x_, y_ } = this.scales();
5618+
const old_center = [
5619+
x_.invert(this._width / 2),
5620+
y_.invert(this._height / 2)
5621+
];
5622+
this.zoomer.extent([
5623+
[0, 0],
5624+
[width, height]
5625+
]);
5626+
this._width = width;
5627+
this._height = height;
5628+
this.scales(true);
5629+
this.zoom_to(this.transform.k, old_center[0], old_center[1]);
5630+
}
56105631
attach_tiles(tiles) {
5611-
this.tileSet = tiles;
5612-
this.tileSet._zoom = this;
5632+
this.dataset = tiles;
5633+
this.dataset._zoom = this;
56135634
return this;
56145635
}
56155636
attach_renderer(key, renderer) {
@@ -5618,7 +5639,7 @@ class Zoom {
56185639
renderer.zoom.initialize_zoom();
56195640
return this;
56205641
}
5621-
zoom_to(k, x = null, y = null, duration = 4e3) {
5642+
zoom_to(k, x, y, duration = 4e3) {
56225643
const scales2 = this.scales();
56235644
const { svg_element_selection: canvas, zoomer, width, height } = this;
56245645
const t = identity$3.translate(width / 2, height / 2).scale(k).translate(-scales2.x(x), -scales2.y(y));
@@ -5644,7 +5665,6 @@ class Zoom {
56445665
const scales2 = this.scales();
56455666
let [x02, x12] = corners.x.map(scales2.x);
56465667
let [y02, y12] = corners.y.map(scales2.y);
5647-
console.log(this.scatterplot.prefs.zoom_align, "AAH");
56485668
if (this.scatterplot.prefs.zoom_align === "right") {
56495669
const aspect_ratio = this.width / this.height;
56505670
const data_aspect_ratio = (x12 - x02) / (y12 - y02);
@@ -5661,10 +5681,7 @@ class Zoom {
56615681
initialize_zoom() {
56625682
const { width, height, svg_element_selection: canvas } = this;
56635683
this.transform = identity$3;
5664-
const zoomer = zoom().scaleExtent([1 / 3, 1e5]).extent([
5665-
[0, 0],
5666-
[width, height]
5667-
]).on("zoom", (event) => {
5684+
const zoomer = zoom().scaleExtent([1 / 3, 1e5]).on("zoom", (event) => {
56685685
var _a2, _b2, _c2;
56695686
try {
56705687
document.getElementById("tooltipcircle").remove();
@@ -5678,6 +5695,7 @@ class Zoom {
56785695
canvas.call(zoomer);
56795696
this.add_mouseover();
56805697
this.zoomer = zoomer;
5698+
this.resize(width, height);
56815699
}
56825700
set_highlit_points(data) {
56835701
const { x_, y_ } = this.scales();
@@ -5757,22 +5775,22 @@ class Zoom {
57575775
}
57585776
data(dataset) {
57595777
if (dataset === void 0) {
5760-
return this.tileSet;
5778+
return this.dataset;
57615779
}
5762-
this.tileSet = dataset;
5780+
this.dataset = dataset;
57635781
return this;
57645782
}
5765-
scales(equal_units = true) {
5766-
if (this._scales) {
5783+
scales(force = false) {
5784+
if (force !== true && this._scales) {
57675785
this._scales.x_ = this.transform.rescaleX(this._scales.x);
57685786
this._scales.y_ = this.transform.rescaleY(this._scales.y);
57695787
return this._scales;
57705788
}
57715789
const { width, height } = this;
5772-
if (this.tileSet === void 0) {
5790+
if (this.dataset === void 0) {
57735791
throw new Error("Error--scales created before tileSet present.");
57745792
}
5775-
const { extent: extent2 } = this.tileSet;
5793+
const { extent: extent2 } = this.dataset;
57765794
const scales2 = {};
57775795
if (extent2 === void 0) {
57785796
throw new Error("Error--scales created before extent present.");
@@ -15764,11 +15782,29 @@ class Renderer {
1576415782
this.holder.node().firstElementChild
1576515783
).node();
1576615784
this.dataset = tileSet;
15767-
this.width = +select(this.canvas).attr("width");
15768-
this.height = +select(this.canvas).attr("height");
15785+
this._width = this.scatterplot.width;
15786+
this._height = this.scatterplot.height;
1576915787
this.deferred_functions = [];
1577015788
this._use_scale_to_download_tiles = true;
1577115789
}
15790+
get width() {
15791+
return this._width;
15792+
}
15793+
set width(value) {
15794+
this._width = value;
15795+
this.resize(this._width, this._height);
15796+
}
15797+
get height() {
15798+
return this._height;
15799+
}
15800+
set height(value) {
15801+
this._height = value;
15802+
this.resize(this._width, this._height);
15803+
}
15804+
resize(width, height) {
15805+
this._width = width;
15806+
this._height = height;
15807+
}
1577215808
get discard_share() {
1577315809
return 0;
1577415810
}
@@ -24464,6 +24500,7 @@ class ReglRenderer extends Renderer {
2446424500
} else {
2446524501
tileSet.download_most_needed_tiles(prefs.max_points, this.max_ix, 5);
2446624502
}
24503+
regl2.poll();
2446724504
regl2.clear({
2446824505
color: [0.9, 0.9, 0.93, 0],
2446924506
depth: 1
@@ -24706,6 +24743,19 @@ class ReglRenderer extends Renderer {
2470624743
depth: false
2470724744
});
2470824745
}
24746+
resize(width, height) {
24747+
super.resize(width, height);
24748+
this.resize_textures();
24749+
}
24750+
resize_textures() {
24751+
var _a2, _b2, _c2, _d2, _e2, _f2;
24752+
(_a2 = this.fbos.colorpicker) == null ? void 0 : _a2.resize(this.width, this.height);
24753+
(_b2 = this.fbos.contour) == null ? void 0 : _b2.resize(this.width, this.height);
24754+
(_c2 = this.fbos.ping) == null ? void 0 : _c2.resize(this.width, this.height);
24755+
(_d2 = this.fbos.pong) == null ? void 0 : _d2.resize(this.width, this.height);
24756+
(_e2 = this.fbos.lines) == null ? void 0 : _e2.resize(this.width, this.height);
24757+
(_f2 = this.fbos.points) == null ? void 0 : _f2.resize(this.width, this.height);
24758+
}
2470924759
get_image_texture(url) {
2471024760
const { regl: regl2 } = this;
2471124761
this.textures = this.textures || {};
@@ -25282,7 +25332,6 @@ class TileBufferManager {
2528225332
);
2528325333
}
2528425334
}
25285-
console.log({ column });
2528625335
if (column.type.typeId !== 3) {
2528725336
const buffer = new Float32Array(tile.record_batch.numRows);
2528825337
const source_buffer = column.data[0];
@@ -35640,17 +35689,13 @@ class QuadtileSet extends Dataset {
3564035689
if (schema.metadata.has("sidecars")) {
3564135690
const cars = schema.metadata.get("sidecars");
3564235691
const parsed = JSON.parse(cars);
35643-
for (const [k, v] of Object.entries(
35644-
parsed
35645-
)) {
35692+
for (const [k, v] of Object.entries(parsed)) {
3564635693
this.transformations[k] = async function(tile) {
3564735694
const batch = await tile.get_arrow(v);
3564835695
const column = batch.getChild(k);
3564935696
if (column === null) {
3565035697
throw new Error(
35651-
`No column named ${k} in sidecar tile ${batch.schema.fields.map(
35652-
(f) => f.name
35653-
).join(", ")}`
35698+
`No column named ${k} in sidecar tile ${batch.schema.fields.map((f) => f.name).join(", ")}`
3565435699
);
3565535700
}
3565635701
return column;
@@ -36992,11 +37037,22 @@ class Scatterplot {
3699237037
this.mark_ready = function() {
3699337038
};
3699437039
this.bound = false;
37040+
if (width === void 0) {
37041+
width = window.innerWidth;
37042+
height = window.innerHeight;
37043+
window.onresize = () => {
37044+
this.resize(window.innerWidth, window.innerHeight);
37045+
};
37046+
}
3699537047
if (selector2 !== void 0) {
3699637048
this.bind(selector2, width, height);
3699737049
}
36998-
this.width = width;
36999-
this.height = height;
37050+
if (width !== void 0) {
37051+
this._width = width;
37052+
}
37053+
if (height !== void 0) {
37054+
this._height = height;
37055+
}
3700037056
this.ready = new Promise((resolve, reject) => {
3700137057
this.mark_ready = resolve;
3700237058
});
@@ -37009,17 +37065,52 @@ class Scatterplot {
3700937065
* @param selector A selector for the root element of the deepscatter; must already exist.
3701037066
* @param width Width of the plot, in pixels.
3701137067
* @param height Height of the plot, in pixels.
37012-
*/
37068+
*/
37069+
resize(width, height) {
37070+
this._width = width;
37071+
this._height = height;
37072+
if (this.elements === void 0) {
37073+
throw "Must bind plot to DOM element before setting dimensions";
37074+
}
37075+
for (const el of this.elements) {
37076+
el.attr("width", this.width).attr("height", this.height);
37077+
el.selectAll(".deepscatter-render-canvas").attr("width", this.width).attr("height", this.height);
37078+
}
37079+
if (this._renderer !== void 0) {
37080+
this._zoom.resize(this.width, this.height);
37081+
this._renderer.resize(this.width, this.height);
37082+
}
37083+
}
37084+
get width() {
37085+
return this._width;
37086+
}
37087+
set width(w) {
37088+
this._width = w;
37089+
this.resize(w, this.height);
37090+
}
37091+
get height() {
37092+
return this._height;
37093+
}
37094+
set height(h) {
37095+
this._height = h;
37096+
this.resize(this.width, h);
37097+
}
3701337098
bind(selector2, width, height) {
3701437099
this.div = select(selector2).selectAll("div.deepscatter_container").data([1]).join("div").attr("class", "deepscatter_container").style("position", "absolute");
3701537100
if (this.div.empty()) {
3701637101
console.error(selector2);
3701737102
throw "Must pass a valid div selector";
3701837103
}
3701937104
this.elements = [];
37105+
if (height !== void 0) {
37106+
this._height = height;
37107+
}
37108+
if (width !== void 0) {
37109+
this._width = width;
37110+
}
3702037111
for (const d of base_elements) {
3702137112
const container = this.div.append("div").attr("id", `container-for-${d.id}`).style("position", "absolute").style("top", 0).style("left", 0).style("pointer-events", d.id === "deepscatter-svg" ? "auto" : "none");
37022-
const el = container.append(d.nodetype).attr("id", d.id).attr("width", width || window.innerWidth).attr("height", height || window.innerHeight);
37113+
const el = container.append(d.nodetype).attr("id", d.id).attr("class", "deepscatter-render-canvas").attr("width", this.width).attr("height", this.height);
3702337114
if (d.nodetype === "svg") {
3702437115
el.append("g").attr("id", "mousepoints");
3702537116
el.append("g").attr("id", "labelrects");
@@ -37141,7 +37232,7 @@ class Scatterplot {
3714137232
const bkgd = select("#container-for-canvas-2d-background").select("canvas");
3714237233
const ctx = bkgd.node().getContext("2d");
3714337234
ctx.fillStyle = prefs.background_color || "rgba(133, 133, 111, .8)";
37144-
ctx.fillRect(0, 0, window.innerWidth * 2, window.innerHeight * 2);
37235+
ctx.fillRect(0, 0, this.width, this.height);
3714537236
this._renderer.initialize();
3714637237
void this._root.promise.then(() => this.mark_ready());
3714737238
return this.ready;
@@ -37209,7 +37300,7 @@ class Scatterplot {
3720937300
}
3721037301
async make_big_png(xtimes = 3, points = 1e7, timeper = 100) {
3721137302
await this._root.download_to_depth(points);
37212-
const { width, height } = this._renderer;
37303+
const { width, height } = this;
3721337304
this.plotAPI({ duration: 0 });
3721437305
const canvas = document.createElement("canvas");
3721537306
canvas.setAttribute("width", (xtimes * width).toString());
@@ -37242,10 +37333,10 @@ class Scatterplot {
3724237333
);
3724337334
const halfHeight = height / 2 | 0;
3724437335
const bytesPerRow = width * 4;
37245-
var temp = new Uint8Array(width * 4);
37246-
for (var y = 0; y < halfHeight; ++y) {
37247-
var topOffset = y * bytesPerRow;
37248-
var bottomOffset = (height - y - 1) * bytesPerRow;
37336+
const temp = new Uint8Array(width * 4);
37337+
for (const y = 0; y < halfHeight; ++y) {
37338+
const topOffset = y * bytesPerRow;
37339+
const bottomOffset = (height - y - 1) * bytesPerRow;
3724937340
temp.set(pixels.subarray(topOffset, topOffset + bytesPerRow));
3725037341
pixels.copyWithin(
3725137342
topOffset,
@@ -37551,7 +37642,7 @@ class Scatterplot {
3755137642
const context2 = canvas.node().getContext("2d");
3755237643
for (const contour of contours) {
3755337644
context2.fillStyle = "rgba(25, 25, 29, 1)";
37554-
context2.fillRect(0, 0, window.innerWidth * 2, window.innerHeight * 2);
37645+
context2.fillRect(0, 0, this.width, this.height);
3755537646
context2.strokeStyle = "#8a0303";
3755637647
context2.fillStyle = "rgba(30, 30, 34, 1)";
3755737648
context2.lineWidth = max([

dist/deepscatter.umd.cjs

Lines changed: 10 additions & 0 deletions
Large diffs are not rendered by default.

src/Image_Tile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class ImageTile extends BaseTile {
3232

3333
const img = new Image();
3434

35-
const img_width = datum.img_width;
36-
const img_height = datum.img_height;
35+
const img_width = datum.img_width as number;
36+
const img_height = datum.img_height as number;
3737
const objectURL = URL.createObjectURL(new Blob([datum._jpeg]));
3838

3939
if (current_position[1] > 4096 - 18 * 2) {

0 commit comments

Comments
 (0)