MCPcopy Create free account
hub / github.com/adobe/leonardo / createColorData

Function createColorData

docs/ui/src/js/utils.js:459–493  ·  view source on GitHub ↗
(color, mode)

Source from the content-addressed store, hash-verified

457}
458
459function createColorData(color, mode) {
460 const f = getChannelsAndFunction(mode);
461 const method = (d) => d3[f.func](d);
462
463 let dataA = color.map(function (d) {
464 let channelValue = method(d)[f.c1];
465 // Need to do some geometry for polar colorspaces
466 if (mode === 'CAM02p' || mode === 'LCH' || mode === 'HSL' || mode === 'HSV' || mode === 'HSLuv') {
467 let s = mode === 'HSL' || mode === 'HSV' ? method(d)[f.c2] * 100 : method(d)[f.c2];
468 let h = channelValue;
469 return filterNaN(convertToCartesian(s, h).x);
470 } else return filterNaN(channelValue);
471 });
472 let dataB = color.map(function (d) {
473 let channelValue = method(d)[f.c3];
474 if (mode === 'HSL' || mode === 'HSV') channelValue = channelValue * 100;
475 return filterNaN(channelValue);
476 });
477 let dataC = color.map(function (d) {
478 let channelValue = method(d)[f.c2];
479 // Need to do some geometry for polar colorspaces
480 if (mode === 'CAM02p' || mode === 'LCH' || mode === 'HSL' || mode === 'HSV' || mode === 'HSLuv') {
481 let s = mode === 'HSL' || mode === 'HSV' ? channelValue * 100 : channelValue;
482 let h = method(d)[f.c1];
483 return filterNaN(convertToCartesian(s, h).y);
484 }
485 return filterNaN(channelValue);
486 });
487
488 return {
489 a: dataA,
490 b: dataB,
491 c: dataC
492 };
493}
494
495function getChannelsAndFunction(mode) {
496 let c1, c2, c3, func, yMin, yMax, yMin2, yMax2, c1Label, c2Label, c3Label;

Callers

nothing calls this directly

Calls 4

getChannelsAndFunctionFunction · 0.85
convertToCartesianFunction · 0.85
methodFunction · 0.70
filterNaNFunction · 0.70

Tested by

no test coverage detected