How to use the vega-scenegraph.sceneVisit function in vega-scenegraph

To help you get started, we’ve selected a few vega-scenegraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vega / vega-webgl-renderer / src / marks / markItemPath.js View on Github external
function drawGL(context, scene, bounds) {
    visit(scene, function(item) {
      if (bounds && !bounds.intersects(item.bounds)) return; // bounds check

      var x = item.x || 0,
          y = item.y || 0,
          shapeGeom;

      context._tx += x;
      context._ty += y;

      if (context._fullRedraw || item._dirty || !item._geom || item._geom.deleted) {
        shapeGeom = shape(context, item);
        item._geom = geometryForItem(context, item, shapeGeom);
      }
      drawGeometry(item._geom, context, item);

      context._tx -= x;
github vega / vega-webgl-renderer / src / marks / image.js View on Github external
function drawGL(context, scene, bounds) {
  var renderer = this;

  visit(scene, function(item) {
    if (bounds && !bounds.intersects(item.bounds)) return; // bounds check

    var image = getImage(item, renderer),
        x = item.x || 0,
        y = item.y || 0,
        w = item.width || image.width || 0,
        h = item.height || image.height || 0;

    x -= imageXOffset(item.align, w);
    y -= imageYOffset(item.baseline, h);

    if (image.loaded) {
      var imgInfo = loadImageAndCreateTextureInfo(context, image);
      imgInfo.x = x + context._tx + context._origin[0];
      imgInfo.y = y + context._ty + context._origin[1];
      imgInfo.w = w;
github vega / vega-webgl-renderer / src / marks / group.js View on Github external
drawGeometry(group._geom, context, group);

    // set clip and bounds
    if (group.clip) {
      oldClip = context._clip;
      context._clip = [
        context._origin[0] + context._tx,
        context._origin[1] + context._ty,
        context._origin[0] + context._tx + w,
        context._origin[1] + context._ty + h
      ];
    }
    if (bounds) bounds.translate(-gx, -gy);

    // draw group contents
    visit(group, function(item) {
      renderer.draw(context, item, bounds);
    });

    // restore graphics context
    if (bounds) bounds.translate(gx, gy);
    if (group.clip) {
      context._clip = oldClip;
    }

    context._tx -= gx;
    context._ty -= gy;
    context._textContext.restore();
  });
}
github vega / vega-webgl-renderer / src / marks / rule.js View on Github external
function drawGL(context, scene, bounds) {
  visit(scene, function(item) {
    var x1, y1, x2, y2, shapeGeom;
    if (bounds && !bounds.intersects(item.bounds)) return; // bounds check
    if (context._fullRedraw || item._dirty || !item._geom || item._geom.deleted) {
      x1 = item.x || 0;
      y1 = item.y || 0;
      x2 = item.x2 != null ? item.x2 : x1;
      y2 = item.y2 != null ? item.y2 : y1;
      shapeGeom = {
        lines: [[[x1, y1], [x2, y2]]],
        closed: false
      };
      shapeGeom.key = JSON.stringify(shapeGeom.lines);
      item._geom = geometryForItem(context, item, shapeGeom);
    }
    drawGeometry(item._geom, context, item);
  });
github vega / vega-webgl-renderer / src / marks / group.js View on Github external
function drawGL(context, scene, bounds) {
  var renderer = this;

  visit(scene, function(group) {
    var gx = group.x || 0,
        gy = group.y || 0,
        w = group.width || 0,
        h = group.height || 0,
        offset, oldClip;

    // setup graphics context
    context._tx += gx;
    context._ty += gy;
    context._textContext.save();
    context._textContext.translate(gx, gy);

    // draw group background
    if (context._fullRedraw || group._dirty || !group._geom || group._geom.deleted) {
      offset = group.stroke ? 0.5 : 0;
      var shapeGeom = rectangleGL(context, group, offset, offset);
github vega / vega-webgl-renderer / src / marks / rect.js View on Github external
unit[j] = unitItem[j % unitItem.length];
    }
  }

  if (sg) {
    gl.deleteBuffer(sg.posBuffer);
    gl.deleteBuffer(sg.sizeBuffer);
    gl.deleteBuffer(sg.strokeWidthBuffer);
    gl.deleteBuffer(sg.strokeOpacityBuffer);
    gl.deleteBuffer(sg.strokeColorBuffer);
    gl.deleteBuffer(sg.fillOpacityBuffer);
    gl.deleteBuffer(sg.fillColorBuffer);
    gl.deleteBuffer(sg.cornerRadiusBuffer);
  }

  visit(scene, function(item) {
    var x = (item.x || 0) + gl._tx + gl._origin[0],
        y = (item.y || 0) + gl._ty + gl._origin[1],
        fc = color(gl, item, item.fill),
        sc = color(gl, item, item.stroke),
        op = item.opacity == null ? 1 : item.opacity,
        fo = op * ((item.fill == null || item.fill == 'transparent') ? 0 : 1) * (item.fillOpacity == null ? 1 : item.fillOpacity),
        so = op * ((item.stroke == null || item.stroke == 'transparent') ? 0 : 1) * (item.strokeOpacity == null ? 1 : item.strokeOpacity),
        sw = ((item.stroke == null || item.stroke == 'transparent') ? 0 : 1) * (item.strokeWidth == null ? 1 : item.strokeWidth),
        sx = (item.width == null ? 0 : item.width),
        sy = (item.height == null ? 0 : item.height),
        cr = (item.cornerRadius == null ? 0 : item.cornerRadius);

    for (j = 0; j < 6; j += 1, ivpf += 1, ivpf2 += 2, ivpf3 += 3) {
      pos[ivpf3] = x;
      pos[ivpf3 + 1] = y;
      pos[ivpf3 + 2] = 0;
github vega / vega-webgl-renderer / src / marks / path.js View on Github external
function drawGL(context, scene) {
  visit(scene, function(item) {
    var path = item.path;
    if (path == null) return true;

    var x = item.x || 0,
        y = item.y || 0;

    context._tx += x;
    context._ty += y;

    if (context._fullRedraw || item._dirty || !item._geom || item._geom.deleted) {
      var shapeGeom = geometryForPath(context, path);
      item._geom = geometryForItem(context, item, shapeGeom);
    }
    drawGeometry(item._geom, context, item);

    context._tx -= x;
github vega / vega-webgl-renderer / src / marks / symbol.js View on Github external
unit[j] = unitItem[j % unitItem.length];
    }
  }

  if (sg) {
    gl.deleteBuffer(sg.posBuffer);
    gl.deleteBuffer(sg.sizeBuffer);
    gl.deleteBuffer(sg.shapeBuffer);
    gl.deleteBuffer(sg.strokeWidthBuffer);
    gl.deleteBuffer(sg.strokeOpacityBuffer);
    gl.deleteBuffer(sg.strokeColorBuffer);
    gl.deleteBuffer(sg.fillOpacityBuffer);
    gl.deleteBuffer(sg.fillColorBuffer);
  }

  visit(scene, function(item) {
    var x = (item.x || 0) + gl._tx + gl._origin[0],
        y = (item.y || 0) + gl._ty + gl._origin[1],
        fc = color(gl, item, item.fill),
        sc = color(gl, item, item.stroke),
        op = item.opacity == null ? 1 : item.opacity,
        fo = op * ((item.fill == null || item.fill == 'transparent') ? 0 : 1) * (item.fillOpacity == null ? 1 : item.fillOpacity),
        so = op * ((item.stroke == null || item.stroke == 'transparent') ? 0 : 1) * (item.strokeOpacity == null ? 1 : item.strokeOpacity),
        sw = ((item.stroke == null || item.stroke == 'transparent') ? 0 : 1) * (item.strokeWidth == null ? 1 : item.strokeWidth),
        sz = (item.size == null ? 64 : item.size),
        sh = shapeIndex[item.shape] == undefined ? 0 : shapeIndex[item.shape];

    for (j = 0; j < 3; j += 1, ivpf += 1, ivpf3 += 3) {
      pos[ivpf3] = x;
      pos[ivpf3 + 1] = y;
      pos[ivpf3 + 2] = 0;
      size[ivpf] = sz;