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

Method toColor

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

* @function LevelRenderer.Tool.Color.prototype.toColor * @description 颜色值数组转为指定格式颜色。 * @param {Array} data - 颜色值数组。 * @param {string} format - 格式,默认'rgb' * @returns {string} 颜色。

(data, format)

Source from the content-addressed store, hash-verified

404 * @returns {string} 颜色。
405 */
406 toColor(data, format) {
407 format = format || 'rgb';
408 if (data && (data.length === 3 || data.length === 4)) {
409 data = this.map(data,
410 function (c) {
411 return c > 1 ? Math.ceil(c) : c;
412 }
413 );
414
415 if (format.indexOf('hex') > -1) {
416 return '#' + ((1 << 24) + (data[0] << 16) + (data[1] << 8) + (+data[2])).toString(16).slice(1);
417 } else if (format.indexOf('hs') > -1) {
418 var sx = this.map(data.slice(1, 3),
419 function (c) {
420 return c + '%';
421 }
422 );
423 data[1] = sx[0];
424 data[2] = sx[1];
425 }
426
427 if (format.indexOf('a') > -1) {
428 if (data.length === 3) {
429 data.push(1);
430 }
431 data[3] = this.adjust(data[3], [0, 1]);
432 return format + '(' + data.slice(0, 4).join(',') + ')';
433 }
434
435 return format + '(' + data.slice(0, 3).join(',') + ')';
436 }
437 }
438
439 /**
440 * @function LevelRenderer.Tool.Color.prototype.toArray

Callers 5

getStepColorsMethod · 0.95
convertMethod · 0.95
reverseMethod · 0.95
mixMethod · 0.95
alphaMethod · 0.95

Calls 5

mapMethod · 0.95
adjustMethod · 0.95
indexOfMethod · 0.80
pushMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected