Commit fd8d55e7 authored by James Long's avatar James Long Committed by Commit Bot

[Lorenz] Check/uncheck nodes in filter on double-click

A shortcut has been added to check/uncheck nodes in the filter on
double-click in the visualization. The behavior is the same as clicking
the button manually on the node details panel.

Bug: 1106106
Change-Id: Idd08b152d956216c250657d0062c920507297f41
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333446
Commit-Queue: James Long <yjlong@google.com>
Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795206}
parent 72aa4e7c
...@@ -268,6 +268,13 @@ class HullColorManager { ...@@ -268,6 +268,13 @@ class HullColorManager {
* @param {!GraphNode} node The node that was clicked. * @param {!GraphNode} node The node that was clicked.
*/ */
/**
* A callback to be triggered whenever a node is double-clicked in the
* visualization.
* @callback OnNodeDoubleClickedCallback
* @param {!GraphNode} node The node that was double-clicked.
*/
/** /**
* Returns the group a node is in, or `null` if the node shouldn't be grouped. * Returns the group a node is in, or `null` if the node shouldn't be grouped.
* @callback GetNodeGroupCallback * @callback GetNodeGroupCallback
...@@ -299,6 +306,8 @@ class GraphView { ...@@ -299,6 +306,8 @@ class GraphView {
this.getNodeGroup_ = null; this.getNodeGroup_ = null;
/** @private @type {?OnNodeClickedCallback} */ /** @private @type {?OnNodeClickedCallback} */
this.onNodeClicked_ = null; this.onNodeClicked_ = null;
/** @private @type {?OnNodeDoubleClickedCallback} */
this.onNodeDoubleClicked_ = null;
const svg = d3.select('#graph-svg'); const svg = d3.select('#graph-svg');
const graphGroup = svg.append('g'); // Contains entire graph (for zoom/pan). const graphGroup = svg.append('g'); // Contains entire graph (for zoom/pan).
...@@ -314,7 +323,8 @@ class GraphView { ...@@ -314,7 +323,8 @@ class GraphView {
.scaleExtent([0.25, 10]) .scaleExtent([0.25, 10])
.on('zoom', () => .on('zoom', () =>
graphGroup.attr('transform', d3.event.transform), graphGroup.attr('transform', d3.event.transform),
)); ))
.on('dblclick.zoom', null);
// The order of these groups decide the SVG paint order (since we append // The order of these groups decide the SVG paint order (since we append
// sequentially), we want hulls below edges below nodes below labels. // sequentially), we want hulls below edges below nodes below labels.
...@@ -390,6 +400,16 @@ class GraphView { ...@@ -390,6 +400,16 @@ class GraphView {
this.onNodeClicked_ = onNodeClicked; this.onNodeClicked_ = onNodeClicked;
} }
/**
* Binds the event when a node is double-clicked in the graph to a given
* callback.
* @param {!OnNodeDoubleClickedCallback} onNodeDoubleClicked The callback to
* bind to.
*/
registerOnNodeDoubleClicked(onNodeDoubleClicked) {
this.onNodeDoubleClicked_ = onNodeDoubleClicked;
}
/** /**
* Assigns the node group accessor to a given function. * Assigns the node group accessor to a given function.
* @param {!GetNodeGroupCallback} getNodeGroup The function to assign to. * @param {!GetNodeGroupCallback} getNodeGroup The function to assign to.
...@@ -690,6 +710,7 @@ class GraphView { ...@@ -690,6 +710,7 @@ class GraphView {
return enter.append('circle') return enter.append('circle')
.attr('r', 5) .attr('r', 5)
.attr('stroke', node => getNodeColor(node)) .attr('stroke', node => getNodeColor(node))
.on('dblclick', node => this.onNodeDoubleClicked_(node))
.on('mousedown', node => this.onNodeClicked_(node)) .on('mousedown', node => this.onNodeClicked_(node))
.on('mouseenter', node => { .on('mouseenter', node => {
this.hoveredNodeManager_.setHoveredNode(node); this.hoveredNodeManager_.setHoveredNode(node);
......
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
:page-model="pageModel" :page-model="pageModel"
:display-settings-data="displaySettingsData" :display-settings-data="displaySettingsData"
:get-node-group="getNodeGroup" :get-node-group="getNodeGroup"
@[CUSTOM_EVENTS.NODE_CLICKED]="graphNodeClicked"/> @[CUSTOM_EVENTS.NODE_CLICKED]="graphNodeClicked"
@[CUSTOM_EVENTS.NODE_DOUBLE_CLICKED]="graphNodeDoubleClicked"/>
<div id="node-details-container"> <div id="node-details-container">
<GraphDisplaySettings <GraphDisplaySettings
:display-settings-data="displaySettingsData"/> :display-settings-data="displaySettingsData"/>
...@@ -198,6 +199,16 @@ const ClassGraphPage = { ...@@ -198,6 +199,16 @@ const ClassGraphPage = {
graphNodeClicked: function(node) { graphNodeClicked: function(node) {
this.pageModel.selectedNodeDetailsData.selectedNode = node; this.pageModel.selectedNodeDetailsData.selectedNode = node;
}, },
/**
* @param {!GraphNode} node The double-clicked node.
*/
graphNodeDoubleClicked: function(node) {
if (node.visualizationState.selectedByFilter) {
this.filterUncheckNode(node.id);
} else {
this.filterAddOrCheckNode(node.id);
}
},
}, },
}; };
......
...@@ -62,6 +62,8 @@ const GraphVisualization = { ...@@ -62,6 +62,8 @@ const GraphVisualization = {
this.graphView = new GraphView(); this.graphView = new GraphView();
this.graphView.registerOnNodeClicked( this.graphView.registerOnNodeClicked(
node => this.$emit(CUSTOM_EVENTS.NODE_CLICKED, node)); node => this.$emit(CUSTOM_EVENTS.NODE_CLICKED, node));
this.graphView.registerOnNodeDoubleClicked(
node => this.$emit(CUSTOM_EVENTS.NODE_DOUBLE_CLICKED, node));
this.graphView.registerGetNodeGroup(this.getNodeGroup); this.graphView.registerGetNodeGroup(this.getNodeGroup);
}, },
}; };
......
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
]" ]"
:page-model="pageModel" :page-model="pageModel"
:display-settings-data="displaySettingsData" :display-settings-data="displaySettingsData"
@[CUSTOM_EVENTS.NODE_CLICKED]="graphNodeClicked"/> @[CUSTOM_EVENTS.NODE_CLICKED]="graphNodeClicked"
@[CUSTOM_EVENTS.NODE_DOUBLE_CLICKED]="graphNodeDoubleClicked"/>
<div id="node-details-container"> <div id="node-details-container">
<GraphDisplaySettings <GraphDisplaySettings
:display-settings-data="displaySettingsData"/> :display-settings-data="displaySettingsData"/>
...@@ -174,6 +175,16 @@ const PackageGraphPage = { ...@@ -174,6 +175,16 @@ const PackageGraphPage = {
graphNodeClicked: function(node) { graphNodeClicked: function(node) {
this.pageModel.selectedNodeDetailsData.selectedNode = node; this.pageModel.selectedNodeDetailsData.selectedNode = node;
}, },
/**
* @param {!GraphNode} node The double-clicked node.
*/
graphNodeDoubleClicked: function(node) {
if (node.visualizationState.selectedByFilter) {
this.filterUncheckNode(node.id);
} else {
this.filterAddOrCheckNode(node.id);
}
},
}, },
}; };
......
...@@ -12,6 +12,7 @@ const CUSTOM_EVENTS = { ...@@ -12,6 +12,7 @@ const CUSTOM_EVENTS = {
FILTER_UNCHECK_ALL: 'filter-uncheck-all', FILTER_UNCHECK_ALL: 'filter-uncheck-all',
FILTER_SUBMITTED: 'filter-submitted', FILTER_SUBMITTED: 'filter-submitted',
NODE_CLICKED: 'node-clicked', NODE_CLICKED: 'node-clicked',
NODE_DOUBLE_CLICKED: 'node-double-clicked',
}; };
export { export {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment