Commit fd0c62ae authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

DevTools: Make Clear Storage pane pie chart colors stable

Bug: 739865
Change-Id: Ifd4d628816afafe5425c4beb6c4311c7a6465c3d
Reviewed-on: https://chromium-review.googlesource.com/562560Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487566}
parent 4696ce58
// Copyright (c) 2016 The Chromium Authors. All rights reserved. // Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
/** /**
* @implements {SDK.TargetManager.Observer} * @implements {SDK.TargetManager.Observer}
*/ */
Resources.ClearStorageView = class extends UI.ThrottledWidget { Resources.ClearStorageView = class extends UI.ThrottledWidget {
constructor() { constructor() {
super(true, 1000); super(true, 1000);
this._pieColors = [ var types = Protocol.Storage.StorageType;
'rgba(110, 161, 226, 1)', // blue this._pieColors = new Map([
'rgba(229, 113, 113, 1)', // red [types.Appcache, 'rgb(110, 161, 226)'], // blue
'rgba(239, 196, 87, 1)', // yellow [types.Cache_storage, 'rgb(229, 113, 113)'], // red
'rgba(155, 127, 230, 1)', // purple [types.Cookies, 'rgb(239, 196, 87)'], // yellow
'rgba(116, 178, 102, 1)', // green [types.Indexeddb, 'rgb(155, 127, 230)'], // purple
'rgba(255, 167, 36, 1)', // orange [types.Local_storage, 'rgb(116, 178, 102)'], // green
'rgba(203, 220, 56, 1)', // lime [types.Service_workers, 'rgb(255, 167, 36)'], // orange
]; [types.Websql, 'rgb(203, 220, 56)'], // lime
]);
this._reportView = new UI.ReportView(Common.UIString('Clear storage')); this._reportView = new UI.ReportView(Common.UIString('Clear storage'));
this._reportView.registerRequiredCSS('resources/clearStorageView.css'); this._reportView.registerRequiredCSS('resources/clearStorageView.css');
...@@ -27,11 +29,9 @@ Resources.ClearStorageView = class extends UI.ThrottledWidget { ...@@ -27,11 +29,9 @@ Resources.ClearStorageView = class extends UI.ThrottledWidget {
this._securityOrigin = null; this._securityOrigin = null;
this._settings = new Map(); this._settings = new Map();
for (var type for (var type of
of [Protocol.Storage.StorageType.Appcache, Protocol.Storage.StorageType.Cache_storage, [types.Appcache, types.Cache_storage, types.Cookies, types.Indexeddb, types.Local_storage,
Protocol.Storage.StorageType.Cookies, Protocol.Storage.StorageType.Indexeddb, types.Service_workers, types.Websql])
Protocol.Storage.StorageType.Local_storage, Protocol.Storage.StorageType.Service_workers,
Protocol.Storage.StorageType.Websql])
this._settings.set(type, Common.settings.createSetting('clear-storage-' + type, true)); this._settings.set(type, Common.settings.createSetting('clear-storage-' + type, true));
var quota = this._reportView.appendSection(Common.UIString('Usage')); var quota = this._reportView.appendSection(Common.UIString('Usage'));
...@@ -201,14 +201,17 @@ Resources.ClearStorageView = class extends UI.ThrottledWidget { ...@@ -201,14 +201,17 @@ Resources.ClearStorageView = class extends UI.ThrottledWidget {
if (!this._quotaUsage || this._quotaUsage !== response.usage) { if (!this._quotaUsage || this._quotaUsage !== response.usage) {
this._quotaUsage = response.usage; this._quotaUsage = response.usage;
this._resetPieChart(response.usage); this._resetPieChart(response.usage);
var colorIndex = 0; for (var usageForType of response.usageBreakdown.sort((a, b) => b.usage - a.usage)) {
for (var usageForType of response.usageBreakdown) { var value = usageForType.usage;
if (!usageForType.usage) if (!value)
continue; continue;
if (colorIndex === this._pieColors.length) var title = this._getStorageTypeName(usageForType.storageType);
colorIndex = 0; var color = this._pieColors.get(usageForType.storageType) || '#ccc';
this._appendLegendRow( this._pieChart.addSlice(value, color);
this._getStorageTypeName(usageForType.storageType), usageForType.usage, this._pieColors[colorIndex++]); var rowElement = this._pieChartLegend.createChild('div', 'usage-breakdown-legend-row');
rowElement.createChild('span', 'usage-breakdown-legend-value').textContent = Number.bytesToString(value);
rowElement.createChild('span', 'usage-breakdown-legend-swatch').style.backgroundColor = color;
rowElement.createChild('span', 'usage-breakdown-legend-title').textContent = title;
} }
} }
...@@ -224,21 +227,6 @@ Resources.ClearStorageView = class extends UI.ThrottledWidget { ...@@ -224,21 +227,6 @@ Resources.ClearStorageView = class extends UI.ThrottledWidget {
this._pieChartLegend.removeChildren(); this._pieChartLegend.removeChildren();
} }
/**
* @param {string} title
* @param {number} value
* @param {string} color
*/
_appendLegendRow(title, value, color) {
if (!value)
return;
this._pieChart.addSlice(value, color);
var rowElement = this._pieChartLegend.createChild('div');
rowElement.createChild('span', 'usage-breakdown-legend-value').textContent = Number.bytesToString(value);
rowElement.createChild('span', 'usage-breakdown-legend-swatch').style.backgroundColor = color;
rowElement.createChild('span', 'usage-breakdown-legend-title').textContent = title;
}
/** /**
* @param {string} type * @param {string} type
* @return {string} * @return {string}
......
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
min-width: fit-content; min-width: fit-content;
} }
.usage-breakdown-legend-row {
margin: 5px auto;
}
.usage-breakdown-legend-title { .usage-breakdown-legend-title {
display: inline-block; display: inline-block;
} }
......
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