Commit ddc83fc1 authored by loislo@chromium.org's avatar loislo@chromium.org

DevTools: CPUFlameChart: stick function entry color to the function name and url.

The old color generator had the dependency from line number too and it was a bad idea because
after a change in the source file the entry would change the color.

Also the entry colors had implicit dependency from the order of processing.

BUG=382116
R=alph@chromium.org

Review URL: https://codereview.chromium.org/319363002

git-svn-id: svn://svn.chromium.org/blink/trunk@175787 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent c72e9717
...@@ -232,7 +232,6 @@ WebInspector.FlameChart.ColorGenerator = function(hueSpace, satSpace, lightnessS ...@@ -232,7 +232,6 @@ WebInspector.FlameChart.ColorGenerator = function(hueSpace, satSpace, lightnessS
this._satSpace = satSpace || 67; this._satSpace = satSpace || 67;
this._lightnessSpace = lightnessSpace || 80; this._lightnessSpace = lightnessSpace || 80;
this._colors = {}; this._colors = {};
this._currentColorIndex = 0;
} }
WebInspector.FlameChart.ColorGenerator.prototype = { WebInspector.FlameChart.ColorGenerator.prototype = {
...@@ -253,21 +252,22 @@ WebInspector.FlameChart.ColorGenerator.prototype = { ...@@ -253,21 +252,22 @@ WebInspector.FlameChart.ColorGenerator.prototype = {
{ {
var color = this._colors[id]; var color = this._colors[id];
if (!color) { if (!color) {
color = this._createColor(this._currentColorIndex++); color = this._generateColorForID(id);
this._colors[id] = color; this._colors[id] = color;
} }
return color; return color;
}, },
/** /**
* @param {number} index * @param {string} id
* @return {string} * @return {string}
*/ */
_createColor: function(index) _generateColorForID: function(id)
{ {
var h = this._indexToValueInSpace(index, this._hueSpace); var hash = id.hashCode();
var s = this._indexToValueInSpace(index, this._satSpace); var h = this._indexToValueInSpace(hash, this._hueSpace);
var l = this._indexToValueInSpace(index, this._lightnessSpace); var s = this._indexToValueInSpace(hash, this._satSpace);
var l = this._indexToValueInSpace(hash, this._lightnessSpace);
return "hsl(" + h + ", " + s + "%, " + l + "%)"; return "hsl(" + h + ", " + s + "%, " + l + "%)";
}, },
...@@ -281,7 +281,7 @@ WebInspector.FlameChart.ColorGenerator.prototype = { ...@@ -281,7 +281,7 @@ WebInspector.FlameChart.ColorGenerator.prototype = {
if (typeof space === "number") if (typeof space === "number")
return space; return space;
index %= space.count; index %= space.count;
return space.min + index / space.count * (space.max - space.min); return space.min + Math.floor(index / space.count * (space.max - space.min));
} }
} }
......
...@@ -276,7 +276,7 @@ WebInspector.CPUFlameChartDataProvider.prototype = { ...@@ -276,7 +276,7 @@ WebInspector.CPUFlameChartDataProvider.prototype = {
entryColor: function(entryIndex) entryColor: function(entryIndex)
{ {
var node = this._entryNodes[entryIndex]; var node = this._entryNodes[entryIndex];
return this._colorGenerator.colorForID(node.functionName + ":" + node.url + ":" + node.lineNumber); return this._colorGenerator.colorForID(node.functionName + ":" + node.url);
}, },
/** /**
...@@ -342,10 +342,13 @@ WebInspector.CPUFlameChartDataProvider.prototype = { ...@@ -342,10 +342,13 @@ WebInspector.CPUFlameChartDataProvider.prototype = {
WebInspector.CPUFlameChartDataProvider.colorGenerator = function() WebInspector.CPUFlameChartDataProvider.colorGenerator = function()
{ {
if (!WebInspector.CPUFlameChartDataProvider._colorGenerator) { if (!WebInspector.CPUFlameChartDataProvider._colorGenerator) {
var colorGenerator = new WebInspector.FlameChart.ColorGenerator(); var colorGenerator = new WebInspector.FlameChart.ColorGenerator(
colorGenerator.setColorForID("(idle)::0", "hsl(0, 0%, 94%)"); { min: 180, max: 310, count: 7 },
colorGenerator.setColorForID("(program)::0", "hsl(0, 0%, 80%)"); { min: 50, max: 80, count: 5 },
colorGenerator.setColorForID("(garbage collector)::0", "hsl(0, 0%, 80%)"); { min: 80, max: 90, count: 3 });
colorGenerator.setColorForID("(idle):", "hsl(0, 0%, 94%)");
colorGenerator.setColorForID("(program):", "hsl(0, 0%, 80%)");
colorGenerator.setColorForID("(garbage collector):", "hsl(0, 0%, 80%)");
WebInspector.CPUFlameChartDataProvider._colorGenerator = colorGenerator; WebInspector.CPUFlameChartDataProvider._colorGenerator = colorGenerator;
} }
return WebInspector.CPUFlameChartDataProvider._colorGenerator; return WebInspector.CPUFlameChartDataProvider._colorGenerator;
......
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