How to use the @antv/scale.getScale function in @antv/scale

To help you get started, we’ve selected a few @antv/scale 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 / components / guide-line.ts View on Github external
private _init() {
    const props = this.plot.options;
    const defaultStyle = this._getDefaultStyle();
    const baseConfig = _.mix(defaultStyle, {
      ...this.cfg,
      type: 'line',
      top: true,
    }) as any;
    if (this.cfg.type) {
      const stateValue = this._getState(this.cfg.type);
      const minValue = this._getState('min');
      const maxValue = this._getState('max');
      const Scale = getScale('linear');
      // 重新组织scale并使用scale的min和max来计算guide point的百分比位置,以避免受nice的影响
      const scale = new Scale(
        _.mix(
          {},
          {
            min: minValue,
            max: maxValue,
            nice: true,
          },
          props.meta
        )
      );
      const percent = `${((stateValue - scale.min) / (scale.max - scale.min)) * 100}%`;
      const start = ['0%', percent];
      const end = ['100%', percent];
      this.config = _.mix(
github antvis / G2Plot / src / combo-plots / util / globalAxis.ts View on Github external
function mergeYAxis(axisInfo, synchroTick: boolean) {
  const isSameScale = sameScaleTest(axisInfo);
  // 默认全部采用左轴的tickCount,具体标度对齐逻辑留待以后优化
  const tickCount = axisInfo[0].scale.tickCount;
  const LinearScale = getScale('linear');
  if (!isSameScale) {
    return axisInfo.map((axis) => {
      const scale = axis.scale;
      const values = calValues(scale, tickCount);
      if (synchroTick) {
        const linearScale: any = new LinearScale({
          min: scale.min,
          max: scale.max,
          ticks: values,
          tickCount,
          color: axis.color,
        } as any);
        linearScale.layer = axis.layer;
        return linearScale;
      } else {
        scale.layer = axis.layer;
github antvis / G2 / packages / g2 / __tests__ / unit / element / area-spec.js View on Github external
import { expect } from 'chai';
import Area from '../../../src/element/area';
import { Canvas } from '@antv/g';
import { getScale } from '@antv/scale';
import { getCoordinate } from '@antv/coord';
import View from '../../utils/view';

const Rect = getCoordinate('rect');
const LinearScale = getScale('linear');
const CatScale = getScale('cat');

describe('Area', () => {
  describe('Default', () => {
    const areaDiv = document.createElement('div');
    areaDiv.id = 'area1';
    document.body.appendChild(areaDiv);

    let areaElement;

    const yearScale = new CatScale({
      field: 'year',
      values: ['1994', '1995', '1996'],
      range: [0, 1],
    });
github antvis / G2 / packages / component / __tests__ / unit / annotation / data-region-spec.js View on Github external
const expect = require('chai').expect;
const { Canvas } = require('@antv/g');
const { getCoordinate } = require('@antv/coord');
const { getScale } = require('@antv/scale');
const { DataRegion } = require('../../../src/annotation');

const Rect = getCoordinate('Rect');
const Cat = getScale('cat');
const Linear = getScale('linear');

describe('Annotation DataRegion', () => {
  const xScale = new Cat({
    field: 'x',
    values: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  });
  const yScale = new Linear({
    field: 'y',
    min: 0,
    max: 1200,
  });
  const coord = new Rect({
    start: { x: 60, y: 460 },
    end: { x: 460, y: 60 },
  });
github antvis / G2 / packages / component / __tests__ / unit / annotation / region-spec.js View on Github external
const expect = require('chai').expect;
const _ = require('@antv/util');
const { Canvas } = require('@antv/g');
const { getCoordinate } = require('@antv/coord');
const { getScale } = require('@antv/scale');
const { Region } = require('../../../src/annotation');

const Rect = getCoordinate('Rect');
const Cat = getScale('cat');
const Linear = getScale('linear');

describe('Annotation Region', () => {
  const xScale = new Cat({
    values: ['一月', '二月', '三月', '四月', '五月'],
  });
  const yScale = new Linear({
    min: 0,
    max: 1200,
  });
  const coord = new Rect({
    start: { x: 60, y: 460 },
    end: { x: 460, y: 60 },
  });
  let canvas, group, div;
github antvis / G2 / packages / component / __tests__ / unit / annotation / html-spec.js View on Github external
const expect = require('chai').expect;
const { Canvas } = require('@antv/g');
const { getCoordinate } = require('@antv/coord');
const { getScale } = require('@antv/scale');
const { Html } = require('../../../src/annotation');

const Rect = getCoordinate('Rect');
const Cat = getScale('cat');
const Linear = getScale('linear');

describe('Annotation Html', () => {
  const xScale = new Cat({
    values: ['一月', '二月', '三月', '四月', '五月'],
  });
  const yScale = new Linear({
    min: 0,
    max: 1200,
  });
  const coord = new Rect({
    start: { x: 60, y: 460 },
    end: { x: 460, y: 60 },
  });
  let canvas, group, div;

  before(() => {
github antvis / G2 / packages / g2 / __tests__ / unit / element / polygon-spec.js View on Github external
import { expect } from 'chai';
import Polygon from '../../../src/element/polygon';
import { Canvas } from '@antv/g';
import { getScale } from '@antv/scale';
import { getCoordinate } from '@antv/coord';
import Theme from '../../../src/theme/default';
import View from '../../utils/view';

const CatScale = getScale('cat');
const LinearScale = getScale('linear');

const Rect = getCoordinate('rect');
describe('Polygon Element X and Y are not all array', () => {
  const polygonDiv = document.createElement('div');
  polygonDiv.id = 'polygon1';
  document.body.appendChild(polygonDiv);

  let polygonElement;

  const nameScale = new CatScale({
    field: 'name',
    values: ['Alexander', 'Marie', 'Maximilian', 'Sophia', 'Lukas', 'Maria', 'Leon', 'Anna', 'Tim', 'Laura'],
    range: [0, 1],
  });

  const dayScale = new CatScale({
github antvis / G2 / packages / component / __tests__ / unit / annotation / arc-spec.js View on Github external
const expect = require('chai').expect;
const { Canvas } = require('@antv/g');
const { getCoordinate } = require('@antv/coord');
const { getScale } = require('@antv/scale');
const { Arc } = require('../../../src/annotation');

const Polar = getCoordinate('polar');
const Cat = getScale('cat');
const Linear = getScale('linear');

describe('Annotation Arc', () => {
  const xScale = new Cat({
    values: ['一月', '二月', '三月', '四月', '五月'],
  });
  const yScale = new Linear({
    min: 0,
    max: 1200,
  });
  const coord = new Polar({
    start: { x: 60, y: 460 },
    end: { x: 460, y: 60 },
    startAngle: -Math.PI,
    endAngle: Math.PI,
  });
  let canvas, group, div;
github antvis / G2 / packages / g2 / __tests__ / unit / element / controller / label / polar-spec.js View on Github external
import { expect } from 'chai';
import * as _ from '@antv/util';
import { Canvas } from '@antv/g';
import { getScale } from '@antv/scale';
import { getCoordinate } from '@antv/coord';
import PolarLabels from '../../../../../src/element/controller/label/components/polar';
import { Global } from '../../../../../src';

const Polar = getCoordinate('polar');
const CatScale = getScale('cat');

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,
    },
github antvis / G2 / packages / g2 / __tests__ / unit / element / base-spec.js View on Github external
import * as _ from '@antv/util';
import { Canvas } from '@antv/g';
import { expect } from 'chai';
import { getCoordinate } from '@antv/coord';
import { getScale } from '@antv/scale';
import Element from '../../../src/element/base';
import Theme from '../../../src/theme/default';
import { registerShapeFactory, registerShape } from '../../../src/element/shape/base';
import { splitPoints, setFillStyle } from '../../../src/element/util/shape';
import View from '../../utils/view';

const Rect = getCoordinate('rect');
const CatScale = getScale('cat');
const LinearScale = getScale('linear');

describe('Element', () => {
  const div = document.createElement('div');
  document.body.appendChild(div);

  const view = new View();
  const coord = new Rect({
    start: {
      x: 0,
      y: 200,
    },
    end: {
      x: 200,
      y: 0,
    },
  });

@antv/scale

Toolkit for mapping abstract data into visual representation.

MIT
Latest version published 6 months ago

Package Health Score

73 / 100
Full package analysis