Skip to content

Commit

Permalink
Fix bounds issue on website
Browse files Browse the repository at this point in the history
  • Loading branch information
bovee committed May 21, 2022
1 parent 4f5ba42 commit 4f35ee5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
35 changes: 21 additions & 14 deletions entab-js/example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ const app = PetiteVue.createApp({
if (url.searchParams.get("p")) {
this.graph.parser = url.searchParams.get("p");
}
this.graph.xaxis = url.searchParams.get("x") || "";
this.graph.yaxis = url.searchParams.get("y") || "";
this.graph.caxis = url.searchParams.get("c") || "";
this.graph.cmap = url.searchParams.get("m") || "Turbo";
this.graph.xaxis = url.searchParams.get("x") || this.graph.xaxis;
this.graph.yaxis = url.searchParams.get("y") || this.graph.yaxis;
this.graph.caxis = url.searchParams.get("c") || this.graph.caxis;
this.graph.cmap = url.searchParams.get("m") || this.graph.cmap;
});
url.searchParams.get("u");
}
Expand Down Expand Up @@ -250,8 +250,8 @@ const app = PetiteVue.createApp({
caxis,
cmap: "Turbo",
// used for setting the zoom on the graph
xbounds: bounds[xaxis].slice(1, 3),
ybounds: bounds[yaxis].slice(1, 3),
xbounds: [xaxis].concat(bounds[xaxis].slice(1, 3)),
ybounds: [yaxis].concat(bounds[yaxis].slice(1, 3)),
};
this.statusMessage = "";
} catch (e) {
Expand Down Expand Up @@ -336,6 +336,13 @@ const app = PetiteVue.createApp({
if (!this.graph.buffer) {
return;
}
// update the bounds if the x or y axises have changed
if (this.graph.xaxis !== this.graph.xbounds[0]) {
this.graph.xbounds = [this.graph.xaxis].concat(this.graph.bounds[this.graph.xaxis].slice(1, 3));
}
if (this.graph.yaxis !== this.graph.ybounds[0]) {
this.graph.ybounds = [this.graph.yaxis].concat(this.graph.bounds[this.graph.yaxis].slice(1, 3));
}
this.statusType = "";
this.statusMessage = "Plotting…";
let reader;
Expand All @@ -348,7 +355,7 @@ const app = PetiteVue.createApp({
return;
}

const xScale = d3.scaleLinear(this.graph.xbounds, [0, width]);
const xScale = d3.scaleLinear(this.graph.xbounds.slice(1, 3), [0, width]);
chart.append("g")
.attr("transform", `translate(0,${height})`)
.call(d3.axisBottom(xScale))
Expand All @@ -373,7 +380,7 @@ const app = PetiteVue.createApp({
let xRange;
let xDensity;
if (this.graph.yaxis) {
const yScale = d3.scaleLinear(this.graph.ybounds, [height, 0]);
const yScale = d3.scaleLinear(this.graph.ybounds.slice(1, 3), [height, 0]);
chart.append("g")
.call(d3.axisLeft(yScale))
.classed("axis", true);
Expand All @@ -384,11 +391,11 @@ const app = PetiteVue.createApp({
zoomTimeout = setTimeout(() => zoomTimeout = null, 500);
return;
} else if (!evt.selection) {
this.graph.xbounds = this.graph.bounds[this.graph.xaxis].slice(1, 3);
this.graph.ybounds = this.graph.bounds[this.graph.yaxis].slice(1, 3);
this.graph.xbounds = [this.graph.xaxis].concat(this.graph.bounds[this.graph.xaxis].slice(1, 3));
this.graph.ybounds = [this.graph.yaxis].concat(this.graph.bounds[this.graph.yaxis].slice(1, 3));
} else {
this.graph.xbounds = [sel[0][0], sel[1][0]].map(xScale.invert).sort((a, b) => a - b);
this.graph.ybounds = [sel[0][1], sel[1][1]].map(yScale.invert).sort((a, b) => a - b);
this.graph.xbounds = [this.graph.xbounds[0]].concat([sel[0][0], sel[1][0]].map(xScale.invert).sort((a, b) => a - b));
this.graph.ybounds = [this.graph.ybounds[0]].concat([sel[0][1], sel[1][1]].map(yScale.invert).sort((a, b) => a - b));
}
this.render();
});
Expand All @@ -400,9 +407,9 @@ const app = PetiteVue.createApp({
zoomTimeout = setTimeout(() => zoomTimeout = null, 500);
return;
} else if (!evt.selection) {
this.graph.xbounds = this.graph.bounds[this.graph.xaxis].slice(1, 3);
this.graph.xbounds = [this.graph.xaxis].concat(this.graph.bounds[this.graph.xaxis].slice(1, 3));
} else {
this.graph.xbounds = evt.selection.map(xScale.invert).sort((a, b) => a - b);
this.graph.xbounds = [this.graph.xaxis].concat(evt.selection.map(xScale.invert).sort((a, b) => a - b));
}
this.render();
});
Expand Down
11 changes: 10 additions & 1 deletion entab/src/readers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,17 @@ mod test {
use super::*;

#[test]
#[cfg(all(feature = "compression", feature = "std"))]
fn test_bad_fuzzes() -> Result<(), EtError> {
let data: &[u8] = &[40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 253, 47, 253, 0, 106, 1, 14, 19];
let data: &[u8] = &[
40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40,
181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181,
47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47,
253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253,
0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0,
106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106, 99, 1, 14, 64, 40, 181, 47, 253, 0, 106,
99, 1, 14, 64, 40, 253, 47, 253, 0, 106, 1, 14, 19,
];

let (mut reader, _) = get_reader(data, None, None)?;
assert!(reader.next_record().is_err());
Expand Down

0 comments on commit 4f35ee5

Please sign in to comment.