Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/common/Color.js

Issue 2879943003: DevTools: render product badges behind the setting. (Closed)
Patch Set: removed module from the list. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro 3 * Copyright (C) 2009 Joseph Pecoraro
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 Padding: Common.Color.fromRGBA([147, 196, 125, .55]), 810 Padding: Common.Color.fromRGBA([147, 196, 125, .55]),
811 PaddingLight: Common.Color.fromRGBA([147, 196, 125, .4]), 811 PaddingLight: Common.Color.fromRGBA([147, 196, 125, .4]),
812 Border: Common.Color.fromRGBA([255, 229, 153, .66]), 812 Border: Common.Color.fromRGBA([255, 229, 153, .66]),
813 BorderLight: Common.Color.fromRGBA([255, 229, 153, .5]), 813 BorderLight: Common.Color.fromRGBA([255, 229, 153, .5]),
814 Margin: Common.Color.fromRGBA([246, 178, 107, .66]), 814 Margin: Common.Color.fromRGBA([246, 178, 107, .66]),
815 MarginLight: Common.Color.fromRGBA([246, 178, 107, .5]), 815 MarginLight: Common.Color.fromRGBA([246, 178, 107, .5]),
816 EventTarget: Common.Color.fromRGBA([255, 196, 196, .66]), 816 EventTarget: Common.Color.fromRGBA([255, 196, 196, .66]),
817 Shape: Common.Color.fromRGBA([96, 82, 177, 0.8]), 817 Shape: Common.Color.fromRGBA([96, 82, 177, 0.8]),
818 ShapeMargin: Common.Color.fromRGBA([96, 82, 127, .6]) 818 ShapeMargin: Common.Color.fromRGBA([96, 82, 127, .6])
819 }; 819 };
820
821 Common.Color.Generator = class {
822 /**
823 * @param {!{min: number, max: number}|number=} hueSpace
824 * @param {!{min: number, max: number, count: (number|undefined)}|number=} sat Space
825 * @param {!{min: number, max: number, count: (number|undefined)}|number=} lig htnessSpace
826 * @param {!{min: number, max: number, count: (number|undefined)}|number=} alp haSpace
827 */
828 constructor(hueSpace, satSpace, lightnessSpace, alphaSpace) {
829 this._hueSpace = hueSpace || {min: 0, max: 360};
830 this._satSpace = satSpace || 67;
831 this._lightnessSpace = lightnessSpace || 80;
832 this._alphaSpace = alphaSpace || 1;
833 /** @type {!Map<string, string>} */
834 this._colors = new Map();
835 }
836
837 /**
838 * @param {string} id
839 * @param {string} color
840 */
841 setColorForID(id, color) {
842 this._colors.set(id, color);
843 }
844
845 /**
846 * @param {string} id
847 * @return {string}
848 */
849 colorForID(id) {
850 var color = this._colors.get(id);
851 if (!color) {
852 color = this._generateColorForID(id);
853 this._colors.set(id, color);
854 }
855 return color;
856 }
857
858 /**
859 * @param {string} id
860 * @return {string}
861 */
862 _generateColorForID(id) {
863 var hash = String.hashCode(id);
864 var h = this._indexToValueInSpace(hash, this._hueSpace);
865 var s = this._indexToValueInSpace(hash >> 8, this._satSpace);
866 var l = this._indexToValueInSpace(hash >> 16, this._lightnessSpace);
867 var a = this._indexToValueInSpace(hash >> 24, this._alphaSpace);
868 return `hsla(${h}, ${s}%, ${l}%, ${a})`;
869 }
870
871 /**
872 * @param {number} index
873 * @param {!{min: number, max: number, count: (number|undefined)}|number} spac e
874 * @return {number}
875 */
876 _indexToValueInSpace(index, space) {
877 if (typeof space === 'number')
878 return space;
879 var count = space.count || space.max - space.min;
880 index %= count;
881 return space.min + Math.floor(index / (count - 1) * (space.max - space.min)) ;
882 }
883 };
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/BUILD.gn ('k') | third_party/WebKit/Source/devtools/front_end/inspector.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698