Skip to content

Conversation

leondt1
Copy link

@leondt1 leondt1 commented Oct 10, 2025

PR includes

image

@leondt1 leondt1 requested a review from Yzing October 10, 2025 09:16
@gemini-code-assist
Copy link

Summary of Changes

Hello @leondt1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly upgrades the chart advising functionality by integrating the gpt-vis library for direct chart rendering. The changes involve adding new dependencies, creating a dedicated rendering module, extending the Advisor API with a render method, and refining the internal type system and pipeline outputs to support this new visualization capability. These updates aim to provide a more seamless and powerful experience for generating and displaying advised charts.

Highlights

  • GPT-Vis Integration: Introduced the @antv/gpt-vis library to enable direct rendering of advised charts, enhancing the visualization capabilities of the ava/advisor module.
  • New Rendering Module: Added a new render module (packages/ava/src/render/render.tsx) responsible for mapping advised chart configurations to gpt-vis components (Line, Area, Column, Bar) and rendering them.
  • Advisor API Extension: The Advisor class now includes a render method, allowing users to directly render chart configurations generated by the advisor.
  • Type System Refinement: Refactored core data types, renaming FieldDataType to Data and FieldMetaType to Meta, and introducing new types like AdviseStageOutput, RenderParams, TrendData, and DistributionData for improved clarity and consistency across the pipeline.
  • Pipeline Output Adjustment: Modified the AdviseChartPipeline to return a more structured AdviseStageOutput object, which now contains adviseCharts, metas, and data, streamlining the output for subsequent rendering.
  • ESLint Configuration Update: Updated the .eslintrc.js to allow unused variables prefixed with _ and disabled the no-underscore-dangle rule, providing more flexibility for internal variable naming.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant new feature to render charts using @antv/gpt-vis. The changes are extensive, touching the advisor pipeline, data types, and adding new rendering logic with React components. Overall, the direction is good, but there are several issues to address. I've found a bug in the pipeline logic, some unused code, and a few areas where the new rendering API is either misleading or incomplete. Specifically, the handling of rendering parameters like the container and UI configurations needs to be improved for a robust and clear API. I've also pointed out a minor code style issue for better maintainability.

Comment on lines +9 to +126
type RenderChartParams = { encode: AdviseChart['encode']; data: Data; metasMap: Record<string, Meta> };

const getTrendOrDistributionSpec = <T extends keyof DataTypeMap>(
params: RenderChartParams & {
category: T;
}
) => {
const { encode, data, metasMap, category } = params;
const newEncode = ENCODE_TO_GPT_VIS_ENCODE[category];
const xFieldKey = encode.x[0];
const yFieldKey = encode.y[0];
const sFieldKey = encode.s?.[0];
const newXFieldKey = newEncode.x;
const newYFieldKey = newEncode.y;
const newSFieldKey = newEncode.s;
const axisXTitle = metasMap[xFieldKey]?.name;
const axisYTitle = metasMap[yFieldKey]?.name;
const newData = data.map((item) => {
return {
[newXFieldKey]: item[xFieldKey],
[newYFieldKey]: item[yFieldKey],
...(newSFieldKey && sFieldKey ? { [newSFieldKey]: item[sFieldKey] } : {}),
};
}) as DataTypeMap[T];

return {
data: newData,
axisXTitle,
axisYTitle,
};
};

export const CHART_RENDER_MAP = {
[CHART_NAME.line]: (params: RenderChartParams) => {
const { data, axisXTitle, axisYTitle } = getTrendOrDistributionSpec<'TREND'>({ ...params, category: 'TREND' });
return (
<Line
data={data}
axisXTitle={axisXTitle}
axisYTitle={axisYTitle}
theme="default"
containerStyle={{ height: 300 }}
style={{
lineWidth: 2,
backgroundColor: '#fff',
}}
/>
);
},
[CHART_NAME.area]: (params: RenderChartParams) => {
const { data, axisXTitle, axisYTitle } = getTrendOrDistributionSpec<'TREND'>({ ...params, category: 'TREND' });
return (
<Area
data={data}
axisXTitle={axisXTitle}
axisYTitle={axisYTitle}
theme="default"
containerStyle={{ height: 300 }}
style={{
lineWidth: 2,
backgroundColor: '#fff',
}}
/>
);
},
[CHART_NAME.column]: (params: RenderChartParams) => {
const { data, axisXTitle, axisYTitle } = getTrendOrDistributionSpec<'DISTRIBUTION'>({
...params,
category: 'DISTRIBUTION',
});
return (
<Column
data={data}
stack={false}
group
axisXTitle={axisXTitle}
axisYTitle={axisYTitle}
theme="default"
containerStyle={{ height: 300 }}
style={{
backgroundColor: '#fff',
}}
/>
);
},
[CHART_NAME.bar]: (params: RenderChartParams) => {
const { data, axisXTitle, axisYTitle } = getTrendOrDistributionSpec<'DISTRIBUTION'>({
...params,
category: 'DISTRIBUTION',
});
return (
<Bar
data={data}
stack={false}
group
axisXTitle={axisXTitle}
axisYTitle={axisYTitle}
theme="default"
containerStyle={{ height: 300 }}
style={{
backgroundColor: '#fff',
}}
/>
);
},
};

export const renderChart = (params: RenderParams) => {
const { chartConfig, data, metas } = params;
const { type, encode } = chartConfig;
const metasMap = transMetasToMap(metas);
const render = CHART_RENDER_MAP[type];
return render({
encode,
data,
metasMap,
});
};

Choose a reason for hiding this comment

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

high

The uiConfig property from RenderParams (which includes width, height, and palette) is being ignored when rendering charts. Instead, properties like height are hardcoded (e.g., containerStyle={{ height: 300 }}), which prevents users from customizing the chart's appearance.

To fix this, you should:

  1. Update RenderChartParams to include uiConfig.
  2. Update renderChart to pass uiConfig to the chart-specific render functions.
  3. Update the functions in CHART_RENDER_MAP to use the width and height from uiConfig.
type RenderChartParams = { encode: AdviseChart['encode']; data: Data; metasMap: Record<string, Meta>, uiConfig?: RenderParams['uiConfig'] };

const getTrendOrDistributionSpec = <T extends keyof DataTypeMap>(
  params: RenderChartParams & {
    category: T;
  }
) => {
  const { encode, data, metasMap, category } = params;
  const newEncode = ENCODE_TO_GPT_VIS_ENCODE[category];
  const xFieldKey = encode.x[0];
  const yFieldKey = encode.y[0];
  const sFieldKey = encode.s?.[0];
  const newXFieldKey = newEncode.x;
  const newYFieldKey = newEncode.y;
  const newSFieldKey = newEncode.s;
  const axisXTitle = metasMap[xFieldKey]?.name;
  const axisYTitle = metasMap[yFieldKey]?.name;
  const newData = data.map((item) => {
    return {
      [newXFieldKey]: item[xFieldKey],
      [newYFieldKey]: item[yFieldKey],
      ...(newSFieldKey && sFieldKey ? { [newSFieldKey]: item[sFieldKey] } : {}),
    };
  }) as DataTypeMap[T];

  return {
    data: newData,
    axisXTitle,
    axisYTitle,
  };
};

export const CHART_RENDER_MAP = {
  [CHART_NAME.line]: (params: RenderChartParams) => {
    const { data, axisXTitle, axisYTitle } = getTrendOrDistributionSpec<'TREND'>({ ...params, category: 'TREND' });
    return (
      <Line
        data={data}
        axisXTitle={axisXTitle}
        axisYTitle={axisYTitle}
        theme="default"
        containerStyle={{ height: params.uiConfig?.height ?? 300, width: params.uiConfig?.width }}
        style={{
          lineWidth: 2,
          backgroundColor: '#fff',
        }}
      />
    );
  },
  [CHART_NAME.area]: (params: RenderChartParams) => {
    const { data, axisXTitle, axisYTitle } = getTrendOrDistributionSpec<'TREND'>({ ...params, category: 'TREND' });
    return (
      <Area
        data={data}
        axisXTitle={axisXTitle}
        axisYTitle={axisYTitle}
        theme="default"
        containerStyle={{ height: params.uiConfig?.height ?? 300, width: params.uiConfig?.width }}
        style={{
          lineWidth: 2,
          backgroundColor: '#fff',
        }}
      />
    );
  },
  [CHART_NAME.column]: (params: RenderChartParams) => {
    const { data, axisXTitle, axisYTitle } = getTrendOrDistributionSpec<'DISTRIBUTION'>({
      ...params,
      category: 'DISTRIBUTION',
    });
    return (
      <Column
        data={data}
        stack={false}
        group
        axisXTitle={axisXTitle}
        axisYTitle={axisYTitle}
        theme="default"
        containerStyle={{ height: params.uiConfig?.height ?? 300, width: params.uiConfig?.width }}
        style={{
          backgroundColor: '#fff',
        }}
      />
    );
  },
  [CHART_NAME.bar]: (params: RenderChartParams) => {
    const { data, axisXTitle, axisYTitle } = getTrendOrDistributionSpec<'DISTRIBUTION'>({
      ...params,
      category: 'DISTRIBUTION',
    });
    return (
      <Bar
        data={data}
        stack={false}
        group
        axisXTitle={axisXTitle}
        axisYTitle={axisYTitle}
        theme="default"
        containerStyle={{ height: params.uiConfig?.height ?? 300, width: params.uiConfig?.width }}
        style={{
          backgroundColor: '#fff',
        }}
      />
    );
  },
};

export const renderChart = (params: RenderParams) => {
  const { chartConfig, data, metas, uiConfig } = params;
  const { type, encode } = chartConfig;
  const metasMap = transMetasToMap(metas);
  const render = CHART_RENDER_MAP[type];
  return render({
    encode,
    data,
    metasMap,
    uiConfig,
  });
};

Comment on lines +89 to +90
/** render DOM container */
container: HTMLElement;

Choose a reason for hiding this comment

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

high

The RenderParams interface includes a container: HTMLElement property, which implies that the render method will render the chart into this DOM element. However, the current implementation of renderChart in render.tsx does not use this property and instead returns a React element. This is misleading for users of the API.

To fix this, you could either:

  1. Implement the rendering logic inside renderChart using react-dom to mount the component into the provided container.
  2. Adjust the API to reflect its behavior. This would involve removing the container property and perhaps renaming the render method to something like getChartComponent to clarify that it returns a renderable component, not that it performs the rendering itself.

Given this is a library, the second option is often preferred as it gives consumers more control. If you choose this path, the container property should be removed.

'@typescript-eslint/camelcase': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/type-annotation-spacing': 0,
'no-plusplus': 0,

Choose a reason for hiding this comment

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

medium

The no-plusplus rule is defined at line 29 and then removed here. While this has no functional impact since it was already disabled, it's good practice to keep the ESLint configuration clean. This change is fine, but you could also remove the initial declaration on line 29 in a follow-up to avoid redundancy.

Comment on lines +36 to +37
let _llmCompleted = false;
let _llmCostTime = '';

Choose a reason for hiding this comment

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

medium

These variables, _llmCompleted and _llmCostTime, are assigned but their values are never used. It appears they are remnants from a previous implementation where they were part of the result. To improve code clarity and remove dead code, they should be deleted.


export interface AdviseChart {
/** chart type */
chartType: string;

Choose a reason for hiding this comment

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

medium

The property chartType has been renamed to type. This is a good change for consistency. However, type is a very generic name and can sometimes conflict with other properties or keywords in TypeScript/JavaScript. Consider if a more specific name like chartType (as it was before) or chartName would be clearer and less prone to conflicts, especially in a complex interface.

@Yzing Yzing merged commit e5ed01e into v4 Oct 11, 2025
@Yzing Yzing deleted the render-1010 branch October 11, 2025 02: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