SHA256
Добавить Canvas v4 для исследования связей
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// Цвета и геометрия V4: чистые функции без DOM и загрузки картинок.
|
||||
export const ORB_DIAMETER = 58;
|
||||
export const PALETTES = {
|
||||
dark: {
|
||||
family: [255, 159, 94], friend: [120, 179, 255], close_friend: [255, 76, 92],
|
||||
business: [190, 150, 255], contact: [170, 190, 220], self: [140, 240, 255],
|
||||
shine: [0, 229, 255], text: '#e7ebf3', shadow: 'rgba(0, 0, 0, .78)', bg: '#172431',
|
||||
},
|
||||
light: {
|
||||
family: [184, 92, 20], friend: [38, 96, 196], close_friend: [214, 38, 55],
|
||||
business: [108, 62, 200], contact: [92, 98, 121], self: [6, 86, 122],
|
||||
shine: [10, 127, 179], text: '#202332', shadow: 'rgba(255, 255, 255, .86)', bg: '#e6edf3',
|
||||
},
|
||||
};
|
||||
|
||||
export const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
||||
export const rgba = (rgb, alpha = 1) => `rgba(${rgb[0]},${rgb[1]},${rgb[2]},${alpha})`;
|
||||
export const color = (palette, type) => palette[type] || palette.contact;
|
||||
export const keyOf = (id) => String(id ?? '').toLowerCase();
|
||||
|
||||
export function hash01(value) {
|
||||
let h = 2166136261;
|
||||
for (const ch of String(value)) { h ^= ch.charCodeAt(0); h = Math.imul(h, 16777619); }
|
||||
return (h >>> 0) / 4294967296;
|
||||
}
|
||||
// Градиент на концах кривой: исходящий тип -> обратный тип (если он известен).
|
||||
// У одностороннего отношения линия затухает к адресату, без бегущих штрихов.
|
||||
export function edgeGradient(ctx, geometry, ref, palette) {
|
||||
const forward = color(palette, ref.relationType || 'friend');
|
||||
const reverse = color(palette, ref.reverseRelationType || ref.relationType || 'friend');
|
||||
const grad = ctx.createLinearGradient(geometry.x1, geometry.y1, geometry.x2, geometry.y2);
|
||||
grad.addColorStop(0, rgba(forward, 0.98));
|
||||
grad.addColorStop(1, rgba(reverse, ref.mutual === false ? 0.035 : 0.98));
|
||||
return grad;
|
||||
}
|
||||
// V3 рисует светлую сердцевину, а не ещё один толстый насыщенный цветной слой.
|
||||
// Здесь слегка высветляем цвет для сохранения сине-красного перехода взаимной связи.
|
||||
export function edgeCoreGradient(ctx, geometry, ref, palette) {
|
||||
const tint = (rgb, alpha) => rgba(rgb.map((v) => Math.round(v * .36 + 255 * .64)), alpha);
|
||||
const forward = color(palette, ref.relationType || 'friend');
|
||||
const reverse = color(palette, ref.reverseRelationType || ref.relationType || 'friend');
|
||||
const grad = ctx.createLinearGradient(geometry.x1, geometry.y1, geometry.x2, geometry.y2);
|
||||
grad.addColorStop(0, tint(forward, .98));
|
||||
grad.addColorStop(1, tint(reverse, ref.mutual === false ? .035 : .98));
|
||||
return grad;
|
||||
}
|
||||
|
||||
export function geometryFor(parent, child, zoom, cx, cy) {
|
||||
const fx = cx.x + parent.x * zoom, fy = cx.y + parent.y * zoom;
|
||||
const tx = cx.x + child.x * zoom, ty = cx.y + child.y * zoom;
|
||||
const dx = tx - fx, dy = ty - fy;
|
||||
const len = Math.hypot(dx, dy) || 1;
|
||||
const ux = dx / len, uy = dy / len;
|
||||
const startR = ORB_DIAMETER * (parent.visualSmall ? .25 : .5) * zoom;
|
||||
const endR = ORB_DIAMETER * (child.visualSmall ? .25 : .5) * zoom;
|
||||
const x1 = fx + ux * startR, y1 = fy + uy * startR;
|
||||
const x2 = tx - ux * endR, y2 = ty - uy * endR;
|
||||
const mx = (x1 + x2) / 2, my = (y1 + y2) / 2;
|
||||
const bow = clamp(Math.hypot(x2 - x1, y2 - y1) * .10, 7, 22) *
|
||||
(hash01(`${parent.id}|${child.id}|edge`) > .5 ? 1 : -1);
|
||||
const cpx = mx - uy * bow * 2, cpy = my + ux * bow * 2;
|
||||
return { x1, y1, x2, y2, cpx, cpy, ux, uy, mx, my, bow };
|
||||
}
|
||||
Reference in New Issue
Block a user