MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / getData

Method getData

src/common/overlay/levelRenderer/Color.js:763–820  ·  view source on GitHub ↗

* @function LevelRenderer.Tool.Color.prototype.getData * @description 获取颜色值数组,返回值范围。 * RGB 范围[0-255] * HSL/HSV/HSB 范围[0-1] * A透明度范围[0-1] * 支持格式: * #rgb * #rrggbb * rgb(r,g,b) * rgb(r%,g%,b%) * rgba(r,g,b,a) * hsb(h,s,b) // hsv与hsb等价 * hsb(h

(color)

Source from the content-addressed store, hash-verified

761 * @returns {Array.<number>} 颜色值数组或null
762 */
763 getData(color) {
764 color = this.normalize(color);
765 var r = color.match(this.colorRegExp);
766 if (r === null) {
767 throw new Error('The color format error'); // 颜色格式错误
768 }
769 var d;
770 var a;
771 var data = [];
772 var rgb;
773
774 if (r[2]) {
775 // #rrggbb
776 d = r[2].replace('#', '').split('');
777 rgb = [d[0] + d[1], d[2] + d[3], d[4] + d[5]];
778 data = this.map(rgb,
779 function (c) {
780 return Color.prototype.adjust.call(this, parseInt(c, 16), [0, 255]);
781 }
782 );
783
784 } else if (r[4]) {
785 // rgb rgba
786 var rgba = (r[4]).split(',');
787 a = rgba[3];
788 rgb = rgba.slice(0, 3);
789 data = this.map(
790 rgb,
791 function (c) {
792 c = Math.floor(
793 c.indexOf('%') > 0 ? parseInt(c, 0) * 2.55 : c
794 );
795 return Color.prototype.adjust.call(this, c, [0, 255]);
796 }
797 );
798
799 if (typeof a !== 'undefined') {
800 data.push(this.adjust(parseFloat(a), [0, 1]));
801 }
802 } else if (r[5] || r[6]) {
803 // hsb hsba hsl hsla
804 var hsxa = (r[5] || r[6]).split(',');
805 var h = parseInt(hsxa[0], 0) / 360;
806 var s = hsxa[1];
807 var x = hsxa[2];
808 a = hsxa[3];
809 data = this.map([s, x],
810 function (c) {
811 return Color.prototype.adjust.call(this, parseFloat(c) / 100, [0, 1]);
812 }
813 );
814 data.unshift(h);
815 if (typeof a !== 'undefined') {
816 data.push(this.adjust(parseFloat(a), [0, 1]));
817 }
818 }
819 return data;
820 }

Callers 9

getStepColorsMethod · 0.95
convertMethod · 0.95
liftMethod · 0.95
reverseMethod · 0.95
mixMethod · 0.95
alphaMethod · 0.95
string2RGBADataFunction · 0.45
Color.jsFile · 0.45
getStepColorsMethod · 0.45

Calls 6

normalizeMethod · 0.95
mapMethod · 0.95
adjustMethod · 0.95
matchMethod · 0.80
indexOfMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected