How to use the @antv/g.Canvas function in @antv/g

To help you get started, we’ve selected a few @antv/g 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 antvis / G2 / packages / g2 / __tests__ / unit / element / interval-spec.js View on Github external
describe('Interval Element', () => {
  const div = document.createElement('div');
  div.id = 'interval';
  document.body.appendChild(div);

  const canvas = new Canvas({
    containerId: 'interval',
    renderer: 'canvas',
    width: 200,
    height: 200,
    pixelRatio: 2,
  });
  // const container = canvas.addGroup();
  const rectCoord = new Rect({
    start: {
      x: 0,
      y: 180,
    },
    end: {
      x: 180,
      y: 0,
    },
github antvis / G2 / packages / g2 / __tests__ / unit / element / point-spec.js View on Github external
values: ScatterData.map((d) => d.GDP),
  });
  const lifeExpectancyScale = new LinearScale({
    field: 'LifeExpectancy',
    values: ScatterData.map((d) => d.LifeExpectancy),
  });
  const populationScale = new LinearScale({
    field: 'Population',
    values: ScatterData.map((d) => d.Population),
  });
  const shapeIdentityScale = new IdentityScale({
    field: 'circle',
    values: ['circle'],
  });

  const canvas = new Canvas({
    containerDOM: div,
    renderer: 'svg',
    width: 400,
    height: 400,
    pixelRatio: 2,
  });
  const container = canvas.addGroup();

  it('constructor', () => {
    pointElement = new Point({
      data: ScatterData,
      scales: {
        GDP: gdpScale,
        LifeExpectancy: lifeExpectancyScale,
        Population: populationScale,
        circle: shapeIdentityScale,
github antvis / G6 / test / unit / item / item-spec.js View on Github external
const expect = require('chai').expect;
const G = require('@antv/g');
const Item = require('../../../src/item/item');
const div = document.createElement('div');
div.id = 'item-spec';
document.body.appendChild(div);

const canvas = new G.Canvas({
  containerId: 'item-spec',
  width: 500,
  height: 500
});

describe('item test', () => {
  it('new item & destroy', () => {
    const group = new G.Group({});
    const item = new Item({
      model: { a: 1, b: 2 },
      group
    });
    item.set({
      a: 11,
      b: 22
    });
github antvis / G2 / packages / component / __tests__ / unit / annotation / line-spec.js View on Github external
before(() => {
    div = document.createElement('div');
    div.id = 'c1';
    document.body.appendChild(div);

    canvas = new Canvas({
      containerId: 'c1',
      width: 500,
      height: 500,
      pixelRatio: 2,
    });
    group = canvas.addGroup();
  });
github antvis / G2 / packages / g2 / __tests__ / unit / element / controller / label / polar-spec.js View on Github external
describe('polar labels', function() {
  const div = document.createElement('div');
  document.body.appendChild(div);

  const canvas = new Canvas({
    containerDOM: div,
    width: 500,
    height: 500,
  });

  const coord = new Polar({
    start: {
      x: 0,
      y: 100,
    },
    end: {
      x: 100,
      y: 0,
    },
  });
github antvis / G2 / packages / component / __tests__ / unit / annotation / text-spec.js View on Github external
before(() => {
    div = document.createElement('div');
    div.id = 'c1';
    document.body.appendChild(div);

    canvas = new Canvas({
      containerId: 'c1',
      width: 500,
      height: 500,
      pixelRatio: 2,
    });
    group = canvas.addGroup();
  });
github antvis / G2Plot / src / plots / line / interaction / range.ts View on Github external
public _initCanvas() {
    const width = this.domWidth;
    const height = this.height;
    const canvas = new Canvas({
      width,
      height,
      containerDOM: this.domContainer,
      capture: false,
    });
    const node = canvas.get('el');
    node.style.position = 'absolute';
    node.style.top = 0;
    node.style.left = 0;
    node.style.zIndex = 3;
    this.canvas = canvas;
  }
  public _initBackground() {
github antvis / G6 / plugins / minimap / index.js View on Github external
const size = self.get('size');
    const className = self.get('className');
    let parentNode = self.get('container');
    const container = createDOM('<div style="width:' + size[0] + 'px; height:' + size[1] + 'px" class="' + className + '"></div>');
    if (isString(parentNode)) {
      parentNode = document.getElementById(parentNode);
    }
    if (parentNode) {
      parentNode.appendChild(container);
    } else {
      graph.get('container').appendChild(container);
    }
    self.set('container', container);
    const containerDOM = createDOM('<div class="g6-minimap-container"></div>');
    container.appendChild(containerDOM);
    const canvas = new G.Canvas({
      containerDOM,
      width: size[0],
      height: size[1],
      pixelRatio: graph.get('pixelRatio')
    });
    self.set('canvas', canvas);
    self.updateCanvas();
  }
  initViewport() {
github antvis / G2Plot / src / base / controller / canvas.ts View on Github external
private initGCanvas() {
    /** 创建canvas */
    const { renderer = 'canvas', pixelRatio } = this.plot;
    const { width, height } = this.getCanvasSize();
    this.canvas = new Canvas({
      containerDOM: this.containerDOM,
      width,
      height,
      renderer,
      pixelRatio,
    });
    this.width = width;
    this.height = height;
    this.updateCanvasTheme();
  }
}