Commit 40ac21ec authored by James Long's avatar James Long Committed by Commit Bot

[Lorenz] Add names to class graph buildtarget groupings

Convex hull buildtarget groupings in the class graph now contain a label
above their highest node with the name of the target.

Change-Id: I11509290940fc2540cbaf987d29b6cca7d58ecc0
Bug: 1109274
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340067Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Commit-Queue: James Long <yjlong@google.com>
Cr-Commit-Position: refs/heads/master@{#796171}
parent 6c95405d
...@@ -342,6 +342,10 @@ class GraphView { ...@@ -342,6 +342,10 @@ class GraphView {
this.nodeGroup_ = graphGroup.append('g') this.nodeGroup_ = graphGroup.append('g')
.classed('graph-nodes', true); .classed('graph-nodes', true);
/** @private {*} */ /** @private {*} */
this.hullLabelGroup_ = graphGroup.append('g')
.classed('graph-hull-labels', true)
.attr('pointer-events', 'none');
/** @private {*} */
this.labelGroup_ = graphGroup.append('g') this.labelGroup_ = graphGroup.append('g')
.classed('graph-labels', true) .classed('graph-labels', true)
.attr('pointer-events', 'none'); .attr('pointer-events', 'none');
...@@ -559,6 +563,8 @@ class GraphView { ...@@ -559,6 +563,8 @@ class GraphView {
* @typedef {Object} HullData * @typedef {Object} HullData
* @property {string} key The unique key for the hull. * @property {string} key The unique key for the hull.
* @property {string} color The color to display the hull as. * @property {string} color The color to display the hull as.
* @property {!Array<number>} labelPosition An [x, y] point representing where
* this hull's label should be rendered.
* @property {!Array<!Array<number>>} points A list of [x, y] points making up * @property {!Array<!Array<number>>} points A list of [x, y] points making up
* the hull. * the hull.
*/ */
...@@ -583,9 +589,18 @@ class GraphView { ...@@ -583,9 +589,18 @@ class GraphView {
const [expandX, expandY] = resizeVector(deltaX, deltaY, HULL_EXPANSION); const [expandX, expandY] = resizeVector(deltaX, deltaY, HULL_EXPANSION);
return [nodeX + expandX, nodeY + expandY]; return [nodeX + expandX, nodeY + expandY];
}); });
// A decent heuristic is for the hull's label to be displayed above its
// highest node. Recall that on an SVG, lower y-values are higher.
let highestPoint = [0, Number.POSITIVE_INFINITY];
for (const point of expandedPolygon) {
if (point[1] < highestPoint[1]) {
highestPoint = point;
}
}
resultHulls.push({ resultHulls.push({
key, key,
color: this.hullColorManager_.getColorForHull(key), color: this.hullColorManager_.getColorForHull(key),
labelPosition: highestPoint,
points: expandedPolygon, points: expandedPolygon,
}); });
} }
...@@ -599,6 +614,18 @@ class GraphView { ...@@ -599,6 +614,18 @@ class GraphView {
* the current data. * the current data.
*/ */
updateHullData(hullData) { updateHullData(hullData) {
this.hullLabelGroup_.selectAll('text')
.data(hullData, hull => hull.key)
.join(enter => enter.append('text')
.text(hull => hull.key)
.attr('fill', hull => hull.color)
.attr('dy', -8)
.attr('x', hull => hull.labelPosition[0])
.attr('y', hull => hull.labelPosition[1]),
update => update
.attr('x', hull => hull.labelPosition[0])
.attr('y', hull => hull.labelPosition[1]));
// The SVG path generator for the hull outlines. // The SVG path generator for the hull outlines.
const getHullLine = d3.line().curve(d3.curveCatmullRomClosed.alpha(0.75)); const getHullLine = d3.line().curve(d3.curveCatmullRomClosed.alpha(0.75));
this.hullGroup_.selectAll('path') this.hullGroup_.selectAll('path')
......
...@@ -72,6 +72,14 @@ export default GraphVisualization; ...@@ -72,6 +72,14 @@ export default GraphVisualization;
</script> </script>
<style> <style>
.graph-hull-labels text {
dominant-baseline: baseline;
font-family: sans-serif;
font-size: 10px;
font-weight: bold;
text-anchor: middle;
}
.graph-edges path.non-hovered-edge { .graph-edges path.non-hovered-edge {
opacity: 0.4; opacity: 0.4;
} }
......
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