Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(static-mark): add axisX and axisY #5188

Merged
merged 2 commits into from
Jun 12, 2023
Merged

feat(static-mark): add axisX and axisY #5188

merged 2 commits into from
Jun 12, 2023

Conversation

pearmini
Copy link
Member

@pearmini pearmini commented Jun 12, 2023

Axis

添加两个 Static Mark(组件):AxisX 和 AxisY,有以下的作用:

  • 只渲染坐标轴(比例尺可视化)
  • 渲染任意坐标轴
  • 数据驱动定位(TODO)

开始使用

// Spec
export function mockAxisXY(): G2Spec {
  return {
    type: 'view',
    padding: 'auto',
    scale: {
      x: {
        type: 'linear',
        domain: [5, 10],
        range: [0, 1],
      },
      y: {
        type: 'linear',
        domain: [5, 10],
        range: [0, 1],
      },
    },
    children: [
      { type: 'axisX', title: 'AxisX' },
      {
        type: 'axisY',
        title: 'AxisY',
        tickCount: 10,
        style: {
          labelFontSize: 14,
          gridLineWidth: 10,
          gridStroke: 'red',
        },
      },
    ],
  };
}
// API
const chart = new Chart({
  container: 'container',
  theme: 'classic',
  padding: 'auto',
});

chart
  .scale('x', {
    type: 'linear',
    domain: [5, 10],
    range: [0, 1],
  })
  .scale('y', {
    type: 'linear',
    domain: [5, 10],
    range: [0, 1],
  });

chart.axisX().title('AxisX');

chart
  .axisY()
  .title('AxisY')
  .attr('tickCount', 10)
  .style('labelFontSize', 14)
  .style('gridLineWidth', 10)
  .style('gridStroke', 'red');

chart.render();

案例

一条轴

export function mockAxisX(): G2Spec {
  return {
    type: 'axisX',
    padding: 'auto',
    height: 80,
    scale: {
      x: {
        type: 'linear',
        domain: [5, 10],
        range: [0, 1],
      },
    },
    tickCount: 10,
  };
}

极坐标系

export function mockAxisXYPolar(): G2Spec {
  return {
    type: 'view',
    padding: 'auto',
    coordinate: { type: 'polar' },
    scale: {
      x: {
        type: 'linear',
        domain: [5, 10],
        range: [0, 1],
      },
      y: {
        type: 'linear',
        domain: [5, 10],
        range: [0, 1],
      },
    },
    children: [
      {
        type: 'axisX',
        title: 'AxisX',
        tickFilter: (_, i, ticks) => i && i !== ticks.length - 1,
      },
      {
        type: 'axisY',
        title: 'AxisY',
        style: {
          labelFontSize: 14,
          gridLineWidth: 10,
          gridStroke: 'red',
        },
      },
    ],
  };
}

多条轴

export function alphabetIntervalAxis(): G2Spec {
  return {
    type: 'view',
    padding: 'auto',
    children: [
      {
        type: 'interval',
        transform: [{ type: 'sortX', by: 'y', reverse: true }],
        data: {
          type: 'fetch',
          value: 'data/alphabet.csv',
        },
        encode: {
          x: 'letter',
          y: 'frequency',
          color: 'steelblue',
        },
      },
      { // 添加一条额外的坐标轴
        type: 'axisY',
        position: 'right',
        scale: {
          y: {
            type: 'linear',
            independent: true,
            domain: [0, 10],
            range: [1, 0],
          },
        },
        style: {
          grid: false,
        },
      },
    ],
  };
}

TODO

  • code
  • tests
  • demos

未来工作

  • 数据驱动定位
  • 添加 legend

@pearmini pearmini merged commit 28e39f0 into v5 Jun 12, 2023
@pearmini pearmini deleted the feat/static-mark branch June 12, 2023 06:17
@Aarebecca
Copy link
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants