Commit 7578f765 authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

PM: Add a bit of color to the chrome://discards graph.

This makes it easier to visually associate frames to their process.
Also make the nodes slightly bigger and turn the stroke around them
black for better contrast, as the colors are fairly muted.

Change-Id: I80b9a817bbed852aa558fbfcacc6d28690f477b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1586228
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654865}
parent 317793b7
...@@ -21,7 +21,11 @@ const kFrameNodesBottomMargin = kProcessNodesYRange + 50; ...@@ -21,7 +21,11 @@ const kFrameNodesBottomMargin = kProcessNodesYRange + 50;
/** @implements {d3.ForceNode} */ /** @implements {d3.ForceNode} */
class GraphNode { class GraphNode {
constructor(id) { constructor(id) {
/** @type {number} */
this.id = id; this.id = id;
/** @type {string} */
this.color = 'black';
// Implementation of the d3.ForceNode interface. // Implementation of the d3.ForceNode interface.
// See https://github.com/d3/d3-force#simulation_nodes. // See https://github.com/d3/d3-force#simulation_nodes.
this.index = null; this.index = null;
...@@ -72,12 +76,22 @@ class GraphNode { ...@@ -72,12 +76,22 @@ class GraphNode {
linkTargets() { linkTargets() {
return []; return [];
} }
/**
* Selects a color string from an id.
* @param {number} id: The id the returned color is selected from.
* @return {string}
*/
selectColor(id) {
return d3.schemeSet3[Math.abs(id) % 12];
}
} }
class PageNode extends GraphNode { class PageNode extends GraphNode {
/** @param {resourceCoordinator.mojom.WebUIPageInfo} page */ /** @param {!resourceCoordinator.mojom.WebUIPageInfo} page */
constructor(page) { constructor(page) {
super(page.id); super(page.id);
/** @type {!resourceCoordinator.mojom.WebUIPageInfo} */
this.page = page; this.page = page;
this.y = kPageNodesTargetY; this.y = kPageNodesTargetY;
} }
...@@ -114,10 +128,12 @@ class PageNode extends GraphNode { ...@@ -114,10 +128,12 @@ class PageNode extends GraphNode {
} }
class FrameNode extends GraphNode { class FrameNode extends GraphNode {
/** @param {resourceCoordinator.mojom.WebUIFrameInfo} frame */ /** @param {!resourceCoordinator.mojom.WebUIFrameInfo} frame */
constructor(frame) { constructor(frame) {
super(frame.id); super(frame.id);
/** @type {!resourceCoordinator.mojom.WebUIFrameInfo} frame */
this.frame = frame; this.frame = frame;
this.color = this.selectColor(frame.processId);
} }
/** override */ /** override */
...@@ -145,8 +161,10 @@ class ProcessNode extends GraphNode { ...@@ -145,8 +161,10 @@ class ProcessNode extends GraphNode {
/** @param {!resourceCoordinator.mojom.WebUIProcessInfo} process */ /** @param {!resourceCoordinator.mojom.WebUIProcessInfo} process */
constructor(process) { constructor(process) {
super(process.id); super(process.id);
/** {!resourceCoordinator.mojom.WebUIProcessInfo} */ /** @type {!resourceCoordinator.mojom.WebUIProcessInfo} */
this.process = process; this.process = process;
this.color = this.selectColor(process.id);
} }
/** override */ /** override */
...@@ -281,21 +299,24 @@ class Graph { ...@@ -281,21 +299,24 @@ class Graph {
const circles = node.enter() const circles = node.enter()
.append('circle') .append('circle')
.attr('r', 7.5) .attr('r', 9)
.attr('fill', 'green') // New nodes appear green. .attr('fill', 'green') // New nodes appear green.
.call(drag); .call(drag);
circles.append('title'); circles.append('title');
// Transition new nodes to black over 2 seconds. // Transition new nodes to their chosen color in 2 seconds.
circles.transition().duration(2000).attr('fill', 'black').attr('r', 5); circles.transition()
.duration(2000)
.attr('fill', d => d.color)
.attr('r', 6);
} }
// Give dead notes a distinguishing class to exclude them from the selection // Give dead nodes a distinguishing class to exclude them from the selection
// above. Interrupt any ongoing transitions, then transition them out. // above. Interrupt any ongoing transitions, then transition them out.
node.exit() node.exit()
.classed('dead', true) .classed('dead', true)
.interrupt() .interrupt()
.attr('r', 7.5) .attr('r', 9)
.attr('fill', 'red') .attr('fill', 'red')
.transition() .transition()
.duration(2000) .duration(2000)
......
...@@ -24,7 +24,7 @@ URL. As result, this document needs to be self-contained, hence inline scripts. ...@@ -24,7 +24,7 @@ URL. As result, this document needs to be self-contained, hence inline scripts.
} }
.nodes circle { .nodes circle {
stroke: #fff; stroke: #000;
stroke-width: 1.5px; stroke-width: 1.5px;
} }
</style> </style>
......
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