mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-07 00:28:13 +08:00
brush on zoom procedural deselect
This commit is contained in:
@@ -164,28 +164,29 @@ class Graph extends React.Component {
|
|||||||
nextProps.responsive.width !== this.props.responsive.width
|
nextProps.responsive.width !== this.props.responsive.width
|
||||||
) {
|
) {
|
||||||
/* clear out whatever was on the div, even if nothing, but usually the brushes etc */
|
/* clear out whatever was on the div, even if nothing, but usually the brushes etc */
|
||||||
d3
|
d3.select("#graphAttachPoint")
|
||||||
.select("#graphAttachPoint")
|
|
||||||
.selectAll("*")
|
.selectAll("*")
|
||||||
.remove();
|
.remove();
|
||||||
const { svg } = setupSVGandBrushElements(
|
const { svg, brush, brushContainer } = setupSVGandBrushElements(
|
||||||
this.handleBrushSelectAction.bind(this),
|
this.handleBrushSelectAction.bind(this),
|
||||||
this.handleBrushDeselectAction.bind(this),
|
this.handleBrushDeselectAction.bind(this),
|
||||||
nextProps.responsive,
|
nextProps.responsive,
|
||||||
this.graphPaddingTop
|
this.graphPaddingTop
|
||||||
);
|
);
|
||||||
this.setState({ svg });
|
this.setState({ svg, brush, brushContainer });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleBrushSelectAction() {
|
handleBrushSelectAction() {
|
||||||
/*
|
/* This conditional handles procedural brush deselect. Brush emits an event on procedural deselect because it is move: null */
|
||||||
|
if (d3.event.selection) {
|
||||||
|
/*
|
||||||
No idea why d3 event scope works like this
|
No idea why d3 event scope works like this
|
||||||
but apparently
|
but apparently
|
||||||
it does
|
it does
|
||||||
https://bl.ocks.org/EfratVil/0e542f5fc426065dd1d4b6daaa345a9f
|
https://bl.ocks.org/EfratVil/0e542f5fc426065dd1d4b6daaa345a9f
|
||||||
*/
|
*/
|
||||||
const s = d3.event.selection;
|
const s = d3.event.selection;
|
||||||
/*
|
/*
|
||||||
event describing brush position:
|
event describing brush position:
|
||||||
@-------|
|
@-------|
|
||||||
| |
|
| |
|
||||||
@@ -193,33 +194,47 @@ class Graph extends React.Component {
|
|||||||
|-------@
|
|-------@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// compute inverse view matrix
|
// compute inverse view matrix
|
||||||
const inverse = mat4.invert([], this.state.camera.view());
|
const inverse = mat4.invert([], this.state.camera.view());
|
||||||
|
|
||||||
// transform screen coordinates -> cell coordinates
|
// transform screen coordinates -> cell coordinates
|
||||||
const invert = pin => {
|
const invert = pin => {
|
||||||
const x =
|
const x =
|
||||||
2 * pin[0] / (this.props.responsive.height - this.graphPaddingTop) - 1;
|
(2 * pin[0]) / (this.props.responsive.height - this.graphPaddingTop) -
|
||||||
const y =
|
1;
|
||||||
2 *
|
const y =
|
||||||
(1 - pin[1] / (this.props.responsive.height - this.graphPaddingTop)) -
|
2 *
|
||||||
1;
|
(1 -
|
||||||
const pout = [x * inverse[14] + inverse[12], y * inverse[14] + inverse[13]];
|
pin[1] / (this.props.responsive.height - this.graphPaddingTop)) -
|
||||||
return [(pout[0] + 1) / 2, (pout[1] + 1) / 2];
|
1;
|
||||||
};
|
const pout = [
|
||||||
|
x * inverse[14] + inverse[12],
|
||||||
|
y * inverse[14] + inverse[13]
|
||||||
|
];
|
||||||
|
return [(pout[0] + 1) / 2, (pout[1] + 1) / 2];
|
||||||
|
};
|
||||||
|
|
||||||
const brushCoords = {
|
const brushCoords = {
|
||||||
northwest: invert([s[0][0], s[0][1]]),
|
northwest: invert([s[0][0], s[0][1]]),
|
||||||
southeast: invert([s[1][0], s[1][1]])
|
southeast: invert([s[1][0], s[1][1]])
|
||||||
};
|
};
|
||||||
|
|
||||||
this.props.dispatch({
|
this.props.dispatch({
|
||||||
type: "graph brush selection change",
|
type: "graph brush selection change",
|
||||||
brushCoords
|
brushCoords
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handleBrushDeselectAction() {
|
handleBrushDeselectAction() {
|
||||||
if (!d3.event.selection) {
|
if (d3.event && !d3.event.selection) {
|
||||||
|
this.props.dispatch({
|
||||||
|
type: "graph brush deselect"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!d3.event) {
|
||||||
|
/* this line clears the brush procedurally, ie., zoom button clicked, not a click away from brush on svg */
|
||||||
|
this.state.svg.select(".graph_brush").call(this.state.brush.move, null);
|
||||||
this.props.dispatch({
|
this.props.dispatch({
|
||||||
type: "graph brush deselect"
|
type: "graph brush deselect"
|
||||||
});
|
});
|
||||||
@@ -302,6 +317,7 @@ class Graph extends React.Component {
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
this.handleBrushDeselectAction();
|
||||||
this.setState({ mode: "zoom" });
|
this.setState({ mode: "zoom" });
|
||||||
}}
|
}}
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
Reference in New Issue
Block a user