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(interaction): define inline interaction #5857

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

pearmini
Copy link
Member

@pearmini pearmini commented Nov 29, 2023

通过 inline 的方式定义交互。下面是复合 Mark 的一个例子:

function Fill({ color }) {
  return (context) => {
    const { container } = context;
    const [plot] = container.getElementsByClassName(PLOT_CLASS_NAME);
    const fill = (e) => {
      const { target } = e;
      if (target.className !== ELEMENT_CLASS_NAME) return;
      target.style.fill = color;
    };
    plot.addEventListener('pointerover', fill);
    return () => plot.removeEventListener('pointerover', fill);
  };
}

function Mark() {
  return {
    type: 'interval',
    data: {
      type: 'fetch',
      value: 'data/alphabet.csv',
    },
    encode: {
      x: 'letter',
      y: 'frequency',
      color: 'steelblue',
    },
    interaction: {
      fill: { type: Fill, color: 'orange' },
    },
  };
}

export function alphabetIntervalCustom(): G2Spec {
  return { type: Mark };
}

有了这个能力

Copy link
Collaborator

@ai-qing-hai ai-qing-hai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interaction define inline ,

@pearmini pearmini force-pushed the feat/define-inline-interaction branch from 20b21db to 2fd7c47 Compare November 29, 2023 03:26
@pearmini pearmini merged commit 7fc6523 into v5 Nov 29, 2023
3 checks passed
@pearmini pearmini deleted the feat/define-inline-interaction branch November 29, 2023 05:49
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.

None yet

2 participants