How to use the @antv/g2.registerElementLabels function in @antv/g2

To help you get started, we’ve selected a few @antv/g2 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 / G2Plot / src / plots / pie / component / label / outer-label.ts View on Github external
const offset = labelOptions.offset;
    return offset === undefined ? DEFAULT_OFFSET : offset <= CROOK_DISTANCE ? 1 : offset - CROOK_DISTANCE;
  }

  public getDefaultOffset(point) {
    const offset = super.getDefaultOffset(point);
    return offset === undefined ? DEFAULT_OFFSET : offset <= CROOK_DISTANCE ? 1 : offset - CROOK_DISTANCE;
  }

  private getCrookDistance(): number {
    const offset = this.getOffsetOfLabel();
    return offset > CROOK_DISTANCE ? CROOK_DISTANCE : 0;
  }
}

registerElementLabels('outer', OuterPieLabel);
github antvis / G2Plot / src / plots / matrix / component / label.ts View on Github external
}
  }

  public _mappingColor(band, gray) {
    let reflect;
    _.each(band, (b) => {
      const map = b as Point;
      if (gray >= map.from && gray < map.to) {
        reflect = map.color;
      }
    });
    return reflect;
  }
}

registerElementLabels('matrixLabel', MatrixLabels);
github antvis / G2Plot / src / plots / stack-area / component / label / area-label.ts View on Github external
const labels = renderer.get('group').get('children');
    const view = this.get('element').get('view');
    _.each(labels, (label, index) => {
      const scaleFactor = this.scaleFactor[index];
      label.attr('fontSize', DEFAULT_SIZE);
      label.transform([
        ['t', -label.attr('x'), -label.attr('y')],
        ['s', scaleFactor, scaleFactor],
        ['t', label.attr('x'), label.attr('y')],
      ]);
    });
    view.get('canvas').draw();
  }
}

registerElementLabels('area', AreaLabel);
github antvis / G2Plot / src / plots / bar / component / label / bar-label.ts View on Github external
label.attr('fill', 'black');
    }
  }

  public _mappingColor(band, gray) {
    let reflect;
    _.each(band, (b) => {
      const map = b as Point;
      if (gray >= map.from && gray < map.to) {
        reflect = map.color;
      }
    });
    return reflect;
  }
}
registerElementLabels('barLabel', BarLabels);
github antvis / G2Plot / src / plots / line / component / label / point-label.ts View on Github external
const anchorsBBox = renderer.get('items').map((item: Item) => {
      return {
        x: item.start.x - 4,
        y: item.start.y - 4,
        width: 8,
        height: 8,
      };
    });
    /*layout(labels, anchorsBBox, view.get('panelRange'), {
      nsweeps: 10,
    });*/
    view.get('canvas').draw();
  }
}

registerElementLabels('point', LinePointLabels);
github antvis / G2Plot / src / plots / stack-area / component / label / area-label.ts View on Github external
const labels = renderer.get('group').get('children');
    const view = this.get('element').get('view');
    _.each(labels, (label, index) => {
      const scaleFactor = this.scaleFactor[index];
      label.attr('fontSize', DEFAULT_SIZE);
      label.transform([
        ['t', -label.attr('x'), -label.attr('y')],
        ['s', scaleFactor, scaleFactor],
        ['t', label.attr('x'), label.attr('y')],
      ]);
    });
    view.get('canvas').draw();
  }
}

registerElementLabels('area', AreaLabel);
github antvis / G2Plot / src / plots / stack-bar / component / label / stack-bar-label.ts View on Github external
import { BarLabels } from '../../../bar/component/label/bar-label';

class StackBarLabels extends BarLabels {
  public adjustPosition(label, shape) {
    const labelRange = label.getBBox();
    const shapeRange = shape.getBBox();
    if (shapeRange.width <= labelRange.width) {
      label.attr('opacity', 0);
      label.attr('fillOpacity', 0);
      label.attr('strokeOpacity', 0);
      label.set('capture', false);
    }
  }
}

registerElementLabels('stackBarLabel', StackBarLabels);
github antvis / G2Plot / src / plots / stack-column / component / label / stack-column-label.ts View on Github external
import { ColumnLabels } from '../../../column/component/label/column-label';

class StackColumnLabels extends ColumnLabels {
  public adjustPosition(label, shape) {
    const labelRange = label.getBBox();
    const shapeRange = shape.getBBox();
    if (shapeRange.height <= labelRange.height) {
      label.attr('opacity', 0);
      label.attr('fillOpacity', 0);
      label.attr('strokeOpacity', 0);
      label.set('capture', false);
    }
  }
}

registerElementLabels('stackColumnLabel', StackColumnLabels);
github antvis / G2Plot / src / plots / pie / component / label / upgrade-label / index.ts View on Github external
return originItems;
  }

  /** 获取label offset, 不允许 <= 0 */
  public getOffsetOfLabel(labelItem?: LabelItem): number {
    const offset = (labelItem && labelItem.offset) || DEFAULT_OFFSET;
    return offset > 0 ? offset : 1;
  }

  /** 获取offset betwee label-text and label-line */
  private getTextLineOffset(labelItem?: LabelItem): number {
    return Math.min(this.getOffsetOfLabel(labelItem), DEFAULT_TEXT_LINE_OFFSET);
  }
}

registerElementLabels('upgrade-pie', UpgradePieLabels);
github antvis / G2Plot / src / plots / stack-area / component / label / line-label.ts View on Github external
view.get('canvas').draw();
  }

  public _adjustColor(shapeId, shapes) {
    let color;
    each(shapes, (shape) => {
      const id = shape.id;
      if (id === shapeId) {
        color = shape.attr('fill');
      }
    });
    return color;
  }
}

registerElementLabels('areaLine', AreaLineElementLabels);