|
@@ -2,42 +2,45 @@ const jab2hex = jab => d3.jab(...jab).formatHex();
|
|
const rgb2hex = rgb => d3.rgb(...rgb).formatHex();
|
|
const rgb2hex = rgb => d3.rgb(...rgb).formatHex();
|
|
const jab2hue = ([, a, b]) => rad2deg * Math.atan2(b, a);
|
|
const jab2hue = ([, a, b]) => rad2deg * Math.atan2(b, a);
|
|
const rgb2hue = rgb => d3.hsl(d3.rgb(...rgb)).h || 0;
|
|
const rgb2hue = rgb => d3.hsl(d3.rgb(...rgb)).h || 0;
|
|
|
|
+const jab2lit = ([j]) => j;
|
|
|
|
+const rgb2lit = rgb => d3.hsl(d3.rgb(...rgb)).l || 0;
|
|
const hex2rgb = hex => {
|
|
const hex2rgb = hex => {
|
|
const { r, g, b } = d3.color(hex);
|
|
const { r, g, b } = d3.color(hex);
|
|
return [r, g, b];
|
|
return [r, g, b];
|
|
};
|
|
};
|
|
|
|
|
|
-const buildVectorData = (vector, toHue, toHex) => {
|
|
|
|
|
|
+const buildVectorData = (vector, toHue, toLightness, toHex) => {
|
|
const sqMag = vectorDot(vector, vector);
|
|
const sqMag = vectorDot(vector, vector);
|
|
const mag = Math.sqrt(sqMag);
|
|
const mag = Math.sqrt(sqMag);
|
|
const unit = vector.map(c => c / mag);
|
|
const unit = vector.map(c => c / mag);
|
|
const hue = toHue(vector);
|
|
const hue = toHue(vector);
|
|
|
|
+ const lightness = toLightness(vector);
|
|
const hex = toHex(vector);
|
|
const hex = toHex(vector);
|
|
- return { vector, sqMag, mag, unit, hue, hex };
|
|
|
|
|
|
+ return { vector, sqMag, mag, unit, hue, lightness, hex };
|
|
};
|
|
};
|
|
|
|
|
|
-const buildClusterData = (size, inertia, mu1, mu2, mu3, nu1, nu2, nu3, toHue, toHex) => ({
|
|
|
|
|
|
+const buildClusterData = (size, inertia, mu1, mu2, mu3, nu1, nu2, nu3, toHue, toLightness, toHex) => ({
|
|
size, inertia,
|
|
size, inertia,
|
|
- mu: buildVectorData([mu1, mu2, mu3], toHue, toHex),
|
|
|
|
|
|
+ mu: buildVectorData([mu1, mu2, mu3], toHue, toLightness, toHex),
|
|
nu: [nu1, nu2, nu3],
|
|
nu: [nu1, nu2, nu3],
|
|
});
|
|
});
|
|
|
|
|
|
const buildPokemonData = ([name, size, ...values]) => ({
|
|
const buildPokemonData = ([name, size, ...values]) => ({
|
|
name,
|
|
name,
|
|
jab: {
|
|
jab: {
|
|
- total: buildClusterData(size, ...values.slice(0, 7), jab2hue, jab2hex),
|
|
|
|
|
|
+ total: buildClusterData(size, ...values.slice(0, 7), jab2hue, jab2lit, jab2hex),
|
|
clusters: [
|
|
clusters: [
|
|
- buildClusterData(...values.slice(7, 15), jab2hue, jab2hex),
|
|
|
|
- buildClusterData(...values.slice(15, 23), jab2hue, jab2hex),
|
|
|
|
- buildClusterData(...values.slice(23, 31), jab2hue, jab2hex),
|
|
|
|
|
|
+ buildClusterData(...values.slice(7, 15), jab2hue, jab2lit, jab2hex),
|
|
|
|
+ buildClusterData(...values.slice(15, 23), jab2hue, jab2lit, jab2hex),
|
|
|
|
+ buildClusterData(...values.slice(23, 31), jab2hue, jab2lit, jab2hex),
|
|
],
|
|
],
|
|
},
|
|
},
|
|
rgb: {
|
|
rgb: {
|
|
- total: buildClusterData(size, ...values.slice(31, 38), rgb2hue, rgb2hex),
|
|
|
|
|
|
+ total: buildClusterData(size, ...values.slice(31, 38), rgb2hue, rgb2lit, rgb2hex),
|
|
clusters: [
|
|
clusters: [
|
|
- buildClusterData(...values.slice(38, 46), rgb2hue, rgb2hex),
|
|
|
|
- buildClusterData(...values.slice(46, 54), rgb2hue, rgb2hex),
|
|
|
|
- buildClusterData(...values.slice(54, 62), rgb2hue, rgb2hex),
|
|
|
|
|
|
+ buildClusterData(...values.slice(38, 46), rgb2hue, rgb2lit, rgb2hex),
|
|
|
|
+ buildClusterData(...values.slice(46, 54), rgb2hue, rgb2lit, rgb2hex),
|
|
|
|
+ buildClusterData(...values.slice(54, 62), rgb2hue, rgb2lit, rgb2hex),
|
|
],
|
|
],
|
|
},
|
|
},
|
|
});
|
|
});
|