sigmajs-triangle-with-contour.js 1.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/**
 * Sigma.js WebGL Renderer Node Program
 * =====================================
 *
 * Simple program rendering nodes as triangles.
 * It does not extend AbstractNodeProgram, which works very differently, and
 * really targets the gl.POINTS drawing methods.
 * @module
 */

import { NodeDisplayData } from "sigma/types";
import { floatColor } from "sigma/utils";
13
import TriangleProgram from "./sigmajs-triangle-abstract";
14 15 16 17 18 19 20 21

const POINTS = 6;
const ATTRIBUTES = 5;

const ANGLE_1 = - (0.5 * Math.PI) / 3;
const ANGLE_2 =   (1.5 * Math.PI) / 3;
const ANGLE_3 =   (3.5 * Math.PI) / 3;

22
export default class NodeProgram extends TriangleProgram {
23
  constructor(gl) {
24
    super(gl, POINTS, ATTRIBUTES);
25 26
  }

27
  triangleDefinitions(data) {
28 29 30 31
    const gray = floatColor('#aaa')
    const size = data.size / 2.3;  // experimental...
    const contourSize = size + 0.8;  // experimental...

32 33
    return [ { x: data.x, y: data.y, size: contourSize, color: '#aaa', angles: [ANGLE_1, ANGLE_2, ANGLE_3] },
             { x: data.x, y: data.y, size: size, color: data.color, angles: [ANGLE_1, ANGLE_2, ANGLE_3] }];
34 35
  }
}