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(connector): support offset #5476

Merged
merged 3 commits into from
Aug 29, 2023
Merged

feat(connector): support offset #5476

merged 3 commits into from
Aug 29, 2023

Conversation

pearmini
Copy link
Member

Connector

  • Connector 支持 offset 配置去设置和 Mark 之间的间距。
  • 添加一个 Funnel 的 demo。

案例

import { G2Spec } from '../../../src';

export function alphabetIntervalFunnelConnectorLabel(): G2Spec {
  const data = [
    { text: 'A', value: 12000 },
    { text: 'B', value: 9800 },
    { text: 'C', value: 6789 },
    { text: 'D', value: 4569 },
  ];
  const encodeX = 'text';
  const encodeY = 'value';
  const r = (start, end) => `${(((start - end) / start) * 100).toFixed(2)} %`;
  return {
    type: 'view',
    paddingRight: 60,
    coordinate: { transform: [{ type: 'transpose' }] },
    children: [
      {
        type: 'interval',
        data,
        transform: [{ type: 'symmetryY' }],
        axis: false,
        legend: false,
        encode: {
          x: encodeX,
          y: encodeY,
          color: encodeX,
          shape: 'funnel',
        },
        scale: { x: { paddingOuter: 0, paddingInner: 0 } },
        labels: [
          {
            text: (d) => `${d[encodeX]} ${d[encodeY]}`,
            position: 'inside',
            fontSize: 20,
          },
          {
            text: '',
            render: (d, data, i) =>
              i !== 0
                ? `<div style="height:1px;width:30px;background:#aaa;margin:0 5px;"></div>`
                : '',
            position: 'top-right',
          },
          {
            text: (d, i) => (i !== 0 ? 'Percentage' : ''),
            position: 'top-right',
            textAlign: 'left',
            textBaseline: 'middle',
            fill: '#aaa',
            dx: 40,
          },
          {
            text: (d, i, data) =>
              i !== 0 ? r(data[i - 1][encodeY], data[i][encodeY]) : '',
            position: 'top-right',
            textAlign: 'left',
            textBaseline: 'middle',
            dx: 40,
            dy: 15,
          },
        ],
      },
      {
        type: 'connector',
        data: [
          {
            startX: data[0][encodeX],
            startY: data[data.length - 1][encodeX],
            endX: 0,
            endY: (data[0][encodeY] - data[data.length - 1][encodeY]) / 2,
          },
        ],
        encode: {
          x: 'startX',
          x1: 'startY',
          y: 'endX',
          y1: 'endY',
        },
        labels: [
          {
            text: 'Percentage',
            position: 'left',
            textAlign: 'start',
            textBaseline: 'middle',
            fill: '#aaa',
            dx: 10,
          },
          {
            text: r(data[0][encodeY], data[data.length - 1][encodeY]),
            position: 'left',
            textAlign: 'start',
            dy: 15,
            dx: 10,
            fill: '#000',
          },
        ],
        style: {
          stroke: '#aaa',
          markerEnd: false,
          connectLength1: -12,
          offset2: -20,
        },
      },
    ],
  };
}

@pearmini pearmini requested a review from hustcc August 29, 2023 03:22
@pearmini pearmini force-pushed the feat/funnel-demo branch 2 times, most recently from 551514c to 1c2a7e7 Compare August 29, 2023 05:36
@pearmini pearmini merged commit 437b8c3 into v5 Aug 29, 2023
1 of 2 checks passed
@pearmini pearmini deleted the feat/funnel-demo branch August 29, 2023 06:40
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.

2 participants