mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-07 22:48:12 +08:00
scaling omitted from event handlers (#789)
* scaling omitted from event handlers * fix smoke tests
This commit is contained in:
@@ -27,7 +27,7 @@ export const datasets = {
|
|||||||
lasso: [
|
lasso: [
|
||||||
{
|
{
|
||||||
"coordinates-as-percent": { x1: 0.05, y1: 0.25, x2: 0.15, y2: 0.35 },
|
"coordinates-as-percent": { x1: 0.05, y1: 0.25, x2: 0.15, y2: 0.35 },
|
||||||
count: "43"
|
count: "104"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
categorical: [
|
categorical: [
|
||||||
@@ -92,7 +92,7 @@ export const datasets = {
|
|||||||
},
|
},
|
||||||
lasso: {
|
lasso: {
|
||||||
"coordinates-as-percent": { x1: 0.45, y1: 0.05, x2: 0.5, y2: 0.1 },
|
"coordinates-as-percent": { x1: 0.45, y1: 0.05, x2: 0.5, y2: 0.1 },
|
||||||
count: "65"
|
count: "76"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
scatter: {
|
scatter: {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import React from "react";
|
|||||||
import * as d3 from "d3";
|
import * as d3 from "d3";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import mat4 from "gl-mat4";
|
import mat4 from "gl-mat4";
|
||||||
|
import vec3 from "gl-vec3";
|
||||||
import _regl from "regl";
|
import _regl from "regl";
|
||||||
import memoize from "memoize-one";
|
import memoize from "memoize-one";
|
||||||
import {
|
import {
|
||||||
@@ -294,11 +295,10 @@ class Graph extends React.Component {
|
|||||||
mode !== prevState.mode ||
|
mode !== prevState.mode ||
|
||||||
stateChanges.svg
|
stateChanges.svg
|
||||||
) {
|
) {
|
||||||
const { tool, container, transform } = this.state;
|
const { tool, container } = this.state;
|
||||||
this.selectionToolUpdate(
|
this.selectionToolUpdate(
|
||||||
stateChanges.tool ? stateChanges.tool : tool,
|
stateChanges.tool ? stateChanges.tool : tool,
|
||||||
stateChanges.container ? stateChanges.container : container,
|
stateChanges.container ? stateChanges.container : container
|
||||||
stateChanges.transform ? stateChanges.transform : transform
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,7 +466,7 @@ class Graph extends React.Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
brushToolUpdate(tool, container, transform) {
|
brushToolUpdate(tool, container) {
|
||||||
/*
|
/*
|
||||||
this is called from componentDidUpdate(), so be very careful using
|
this is called from componentDidUpdate(), so be very careful using
|
||||||
anything from this.state, which may be updated asynchronously.
|
anything from this.state, which may be updated asynchronously.
|
||||||
@@ -480,14 +480,8 @@ class Graph extends React.Component {
|
|||||||
if there is a selection, make sure the brush tool matches
|
if there is a selection, make sure the brush tool matches
|
||||||
*/
|
*/
|
||||||
const screenCoords = [
|
const screenCoords = [
|
||||||
this.mapPointToScreen(
|
this.mapPointToScreen(currentSelection.brushCoords.northwest),
|
||||||
currentSelection.brushCoords.northwest,
|
this.mapPointToScreen(currentSelection.brushCoords.southeast)
|
||||||
transform
|
|
||||||
),
|
|
||||||
this.mapPointToScreen(
|
|
||||||
currentSelection.brushCoords.southeast,
|
|
||||||
transform
|
|
||||||
)
|
|
||||||
];
|
];
|
||||||
if (!toolCurrentSelection) {
|
if (!toolCurrentSelection) {
|
||||||
/* tool is not selected, so just move the brush */
|
/* tool is not selected, so just move the brush */
|
||||||
@@ -514,7 +508,7 @@ class Graph extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lassoToolUpdate(tool, container, transform) {
|
lassoToolUpdate(tool, container) {
|
||||||
/*
|
/*
|
||||||
this is called from componentDidUpdate(), so be very careful using
|
this is called from componentDidUpdate(), so be very careful using
|
||||||
anything from this.state, which may be updated asynchronously.
|
anything from this.state, which may be updated asynchronously.
|
||||||
@@ -525,7 +519,7 @@ class Graph extends React.Component {
|
|||||||
if there is a current selection, make sure the lasso tool matches
|
if there is a current selection, make sure the lasso tool matches
|
||||||
*/
|
*/
|
||||||
const polygon = currentSelection.polygon.map(p =>
|
const polygon = currentSelection.polygon.map(p =>
|
||||||
this.mapPointToScreen(p, transform)
|
this.mapPointToScreen(p)
|
||||||
);
|
);
|
||||||
tool.move(polygon);
|
tool.move(polygon);
|
||||||
} else {
|
} else {
|
||||||
@@ -533,7 +527,7 @@ class Graph extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectionToolUpdate(tool, container, transform) {
|
selectionToolUpdate(tool, container) {
|
||||||
/*
|
/*
|
||||||
this is called from componentDidUpdate(), so be very careful using
|
this is called from componentDidUpdate(), so be very careful using
|
||||||
anything from this.state, which may be updated asynchronously.
|
anything from this.state, which may be updated asynchronously.
|
||||||
@@ -541,10 +535,10 @@ class Graph extends React.Component {
|
|||||||
const { selectionTool } = this.props;
|
const { selectionTool } = this.props;
|
||||||
switch (selectionTool) {
|
switch (selectionTool) {
|
||||||
case "brush":
|
case "brush":
|
||||||
this.brushToolUpdate(tool, container, transform);
|
this.brushToolUpdate(tool, container);
|
||||||
break;
|
break;
|
||||||
case "lasso":
|
case "lasso":
|
||||||
this.lassoToolUpdate(tool, container, transform);
|
this.lassoToolUpdate(tool, container);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* punt? */
|
/* punt? */
|
||||||
@@ -608,6 +602,7 @@ class Graph extends React.Component {
|
|||||||
|
|
||||||
// get aspect ratio
|
// get aspect ratio
|
||||||
const aspect = gl.drawingBufferWidth / gl.drawingBufferHeight;
|
const aspect = gl.drawingBufferWidth / gl.drawingBufferHeight;
|
||||||
|
const scale = aspect < 1 ? 1 / aspect : 1;
|
||||||
|
|
||||||
// compute inverse view matrix
|
// compute inverse view matrix
|
||||||
const inverse = mat4.invert([], camera.view());
|
const inverse = mat4.invert([], camera.view());
|
||||||
@@ -616,35 +611,37 @@ class Graph extends React.Component {
|
|||||||
const x = (2 * pin[0]) / (responsive.width - this.graphPaddingRight) - 1;
|
const x = (2 * pin[0]) / (responsive.width - this.graphPaddingRight) - 1;
|
||||||
const y = 2 * (1 - pin[1] / (responsive.height - this.graphPaddingTop)) - 1;
|
const y = 2 * (1 - pin[1] / (responsive.height - this.graphPaddingTop)) - 1;
|
||||||
const pout = [
|
const pout = [
|
||||||
x * inverse[14] * aspect + inverse[12],
|
x * inverse[14] * aspect * scale + inverse[12],
|
||||||
-(y * inverse[14] + inverse[13])
|
-(y * inverse[14] * scale + inverse[13])
|
||||||
];
|
];
|
||||||
|
|
||||||
return [glScaleX.invert(pout[0]), glScaleY.invert(pout[1])];
|
const xy = [glScaleX.invert(pout[0]), glScaleY.invert(pout[1])];
|
||||||
|
return xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapPointToScreen(xyCell, transform) {
|
mapPointToScreen(xyCell) {
|
||||||
/*
|
/*
|
||||||
Map an XY coordinate from cell/point domain to screen range. Inverse
|
Map an XY coordinate from cell/point domain to screen range. Inverse
|
||||||
of mapScreenToPoint()
|
of mapScreenToPoint()
|
||||||
*/
|
*/
|
||||||
const { responsive } = this.props;
|
const { responsive } = this.props;
|
||||||
const { regl, camera } = this.state;
|
const { regl, camera, transform } = this.state;
|
||||||
const { glScaleX, glScaleY } = transform;
|
const { glScaleX, glScaleY } = transform;
|
||||||
|
|
||||||
const gl = regl._gl;
|
const gl = regl._gl;
|
||||||
|
|
||||||
// get aspect ratio
|
// get aspect ratio
|
||||||
const aspect = gl.drawingBufferWidth / gl.drawingBufferHeight;
|
const aspect = gl.drawingBufferWidth / gl.drawingBufferHeight;
|
||||||
|
const scale = aspect < 1 ? 1 / aspect : 1;
|
||||||
|
|
||||||
// compute inverse view matrix
|
// compute inverse view matrix
|
||||||
const inverse = mat4.invert([], camera.view());
|
let inverse = mat4.invert([], camera.view());
|
||||||
|
|
||||||
// variable names are choosen to reflect inverse of those used
|
// variable names are choosen to reflect inverse of those used
|
||||||
// in mapScreenToPoint().
|
// in mapScreenToPoint().
|
||||||
const pout = [glScaleX(xyCell[0]), glScaleY(xyCell[1])];
|
const pout = [glScaleX(xyCell[0]), glScaleY(xyCell[1])];
|
||||||
const x = (pout[0] - inverse[12]) / aspect / inverse[14];
|
const x = (pout[0] - inverse[12]) / aspect / scale / inverse[14];
|
||||||
const y = (-pout[1] - inverse[13]) / inverse[14];
|
const y = (-pout[1] - inverse[13]) / scale / inverse[14];
|
||||||
|
|
||||||
const pin = [
|
const pin = [
|
||||||
Math.round(((x + 1) * (responsive.width - this.graphPaddingRight)) / 2),
|
Math.round(((x + 1) * (responsive.width - this.graphPaddingRight)) / 2),
|
||||||
|
|||||||
Reference in New Issue
Block a user