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(line): add trail shape #5137

Merged
merged 1 commit into from
Jun 1, 2023
Merged

feat(line): add trail shape #5137

merged 1 commit into from
Jun 1, 2023

Conversation

pearmini
Copy link
Member

@pearmini pearmini commented Jun 1, 2023

Trail

设计

其余的 Line 的 Shape 是把所有点连接成一条线,但是 Trail 是在相邻的两个点之间画一个类似于笔触的形状,然后拼接成一条宽度变化的线。

案例

export function stocksLineVarSize(): G2Spec {
  return {
    type: 'line',
    data: {
      type: 'fetch',
      value: 'data/stocks.csv',
    },
    encode: {
      x: (d) => new Date(d.date),
      y: 'price',
      color: 'symbol',
      size: 'price',
    },
    legend: { size: false },
    style: { shape: 'trail' },
  };
}
export async function barleyLineTrail(): Promise<G2Spec> {
  const data = await csv('data/barley.csv', autoType);
  const key = (d) => `${d.site},${d.variety}`;
  const keyDelta = rollup(
    data,
    ([a, b]) => {
      if (b.year < a.year) [a, b] = [b, a];
      return b.yield - a.yield;
    },
    key,
  );
  return {
    type: 'facetRect',
    data,
    paddingLeft: 120,
    paddingBottom: 100,
    encode: { x: 'site' },
    children: [
      {
        type: 'line',
        frame: false,
        encode: {
          x: (d) => `${d.year}`,
          y: 'variety',
          series: 'variety',
          color: (d) => keyDelta.get(key(d)),
          size: 'yield',
        },
        tooltip: { title: '', items: [{ field: 'year' }, { field: 'yield' }] },
        legend: { size: false, color: { title: 'yield delta' } },
        scale: {
          size: { range: [0, 12] },
          color: { palette: 'rdBu' },
        },
        style: { shape: 'trail' },
        interaction: { tooltip: { series: false } },
      },
    ],
  };
}

TODO

  • code
  • tests
  • demo
  • docs

@pearmini pearmini requested a review from hustcc June 1, 2023 03:59
@pearmini pearmini merged commit 34937ea into v5 Jun 1, 2023
@pearmini pearmini deleted the feat/line-var-size branch June 1, 2023 04:56
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