How to use @antv/g-canvas - 4 common examples

To help you get started, we’ve selected a few @antv/g-canvas 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 / src / animate / animation / sector-path-update.ts View on Github external
function getAngle(startPoint: number[], arcPath: PathCommand) {
  let { startAngle, endAngle } = getArcParams(startPoint, arcPath);

  if (!isNumberEqual(startAngle, -Math.PI * 0.5) && startAngle < -Math.PI * 0.5) {
    startAngle += Math.PI * 2;
  }
  if (!isNumberEqual(endAngle, -Math.PI * 0.5) && endAngle < -Math.PI * 0.5) {
    endAngle += Math.PI * 2;
  }

  if (arcPath[5] === 0) {
    // 逆时针,需要将 startAngle 和 endAngle 转置,因为 G2 极坐标系为顺时针方向
    [startAngle, endAngle] = [endAngle, startAngle];
  }

  if (isNumberEqual(startAngle, Math.PI * 1.5)) {
    startAngle = Math.PI * -0.5;
  }
github antvis / G6 / tests / unit / shape / edge-spec.ts View on Github external
import Canvas from '@antv/g-canvas/lib/canvas';
import '../../../src/shape/edge'
import '../../../src/shape/edges'
import Shape from '../../../src/shape/shape'

const div = document.createElement('div');
div.id = 'edge-shape';
document.body.appendChild(div);

const canvas = new Canvas({
  container: 'edge-shape',
  width: 600,
  height: 600
});

describe('shape edge test', () => {
  describe('basic method test', () => {
    it('get factory', () => {
      const factory = Shape.getFactory('edge');
      expect(factory).not.toEqual(undefined);
    });
    it('get default', () => {
      const factory = Shape.getFactory('edge');
      const shape = factory.getShape();
      expect(shape.type).toEqual('line');
    });
github antvis / G6 / tests / unit / shape / node-spec.ts View on Github external
import Shape from '../../../src/shape/shape'
import Global from '../../../src/global';
import Canvas from '@antv/g-canvas/lib/canvas';
import Node from '../../../src/item/node';
import { translate } from '../../../src/util/math'
import Graph from '../../../src/graph/graph'
import '../../../src/shape/node'
import '../../../src/shape/nodes'
import { IGroup } from '@antv/g-canvas/lib/interfaces';

const div = document.createElement('div');
div.id = 'node-shape';
document.body.appendChild(div);

const canvas = new Canvas({
  container: 'node-shape',
  width: 500,
  height: 500
});

describe('shape node test', () => {
  describe('basic method test', () => {
    it('get factory', () => {
      const factory = Shape.getFactory('node');
      expect(factory).not.toBe(undefined);
    });
    it('get default', () => {
      const factory = Shape.getFactory('node');
      const shape = factory.getShape();
      expect(shape.type).toBe('circle');
    });
github antvis / G6 / src / graph / graph.ts View on Github external
private initCanvas() {
    let container: string | HTMLElement = this.get('container')
    if(isString(container)) {
      container = document.getElementById(container)
      this.set('container', container)
    }

    if(!container) {
      throw new Error('invalid container')
    }

    const width: number = this.get('width')
    const height: number = this.get('height')
    const pixelRatio: number = this.get('pixelRatio')

    const canvas = new GCanvas({
      container,
      width,
      height,
      pixelRatio
    })

    this.set('canvas', canvas)

    this.initGroups()
  }

@antv/g-canvas

A renderer implemented by Canvas 2D API

MIT
Latest version published 25 days ago

Package Health Score

89 / 100
Full package analysis