
Antv S2 Expert
Implement AntV S2 pivot tables and custom cell rendering with TypeScript when solo builders need spreadsheet-grade analytics UI.
Overview
AntV S2 Expert is an agent skill for the Build phase that guides custom AntV S2 pivot and table cell rendering in TypeScript.
Install
npx skills add https://github.com/antvis/chart-visualization-skills --skill antv-s2-expertWhat is this skill?
- Custom DataCell by extending DataCell and overriding drawBackgroundShape
- PivotSheet setup with rows, columns, values fields and S2Options registration via dataCell callback
- TableSheet note: extend TableDataCell for non-pivot table mode
- GImage background patterns using cell bbox from getBBoxByType
- interaction.hoverHighlight toggles for cleaner custom cell visuals
Adoption & trust: 811 installs on skills.sh; 337 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need a pivot or spreadsheet UI but default S2 cells cannot show custom graphics, backgrounds, or interaction tweaks.
Who is it for?
Indie SaaS founders building analytics grids, ops consoles, or embedded reporting with @antv/s2.
Skip if: Simple one-chart dashboards better served by basic chart libraries, or backends with no browser UI.
When should I use this skill?
When implementing AntV S2 pivot or table sheets with custom cell drawing, S2Options, or @antv/g shapes in TypeScript.
What do I get? / Deliverables
You get working PivotSheet config plus documented DataCell extension patterns agents can paste and adapt for your dataset.
- S2DataConfig and S2Options snippet with custom dataCell factory
- Custom DataCell or TableDataCell class with overridden draw methods
Recommended Skills
Journey fit
How it compares
AntV S2 pivot/table integration skill—not a generic D3 tutorial or non-grid chart-only package.
Common Questions / FAQ
Who is antv-s2-expert for?
Solo and small-team frontend developers shipping data-dense pivot UIs with AntV S2 who want agent help on cell customization.
When should I use antv-s2-expert?
During Build → frontend when wiring S2DataConfig, custom DataCell classes, and interaction options for production dashboards.
Is antv-s2-expert safe to install?
Custom cells may load remote image URLs in examples; review upstream code and the Security Audits panel on this Prism page before install.
SKILL.md
READMESKILL.md - Antv S2 Expert
# Custom Cell Rendering Examples ## Example 1: Custom DataCell with Background Image Extend `DataCell` to override the `drawBackgroundShape` method and add a custom background image to data cells. ```typescript import { PivotSheet, DataCell, S2DataConfig, S2Options } from '@antv/s2'; import { Image as GImage } from '@antv/g'; /** * Custom DataCell - adds a background image to data cells. * For TableSheet, extend TableDataCell instead. * See: https://github.com/antvis/S2/blob/next/packages/s2-core/src/cell/data-cell.ts */ class CustomDataCell extends DataCell { // Override the background drawing method to add a background image drawBackgroundShape() { const url = 'https://gw.alipayobjects.com/zos/antfincdn/og1XQOMyyj/1e3a8de1-3b42-405d-9f82-f92cb1c10413.png'; this.backgroundShape = this.appendChild( new GImage({ style: { ...this.getBBoxByType(), src: url, }, }), ); } } const s2DataConfig: S2DataConfig = { fields: { rows: ['province', 'city'], columns: ['type', 'sub_type'], values: ['number'], }, meta: [/* ... */], data: [/* ... */], }; const s2Options: S2Options = { width: 600, height: 480, interaction: { // Disable hover cross-highlight for visual clarity hoverHighlight: false, }, // Register custom DataCell via the dataCell callback dataCell: (viewMeta, spreadsheet) => { return new CustomDataCell(viewMeta, spreadsheet); }, }; const s2 = new PivotSheet(container, s2DataConfig, s2Options); await s2.render(); ``` ## Example 2: Custom TableDataCell with Conditional Styling Extend `TableDataCell` to override `getBackgroundColor` and `getTextStyle` for conditional formatting based on cell data. ```typescript import { TableColCell, TableDataCell, TableSheet, type S2DataConfig, type S2Options, } from '@antv/s2'; /** * Custom TableDataCell - conditional background color and text styling. * See: https://github.com/antvis/S2/blob/next/packages/s2-core/src/cell/table-data-cell.ts */ class CustomDataCell extends TableDataCell { getBackgroundColor() { // Highlight cells with value >= 6000 if (this.meta.fieldValue >= 6000) { return { backgroundColor: 'red', backgroundColorOpacity: 0.2, }; } return super.getBackgroundColor(); } getTextStyle() { const defaultTextStyle = super.getTextStyle(); // Bold centered text for the first column (series number) if (this.meta.colIndex === 0) { return { ...defaultTextStyle, fontWeight: 600, textAlign: 'center', }; } // Alternating row style for specific columns if (this.meta.rowIndex % 2 === 0 && this.meta.colIndex > 0) { return { ...defaultTextStyle, fontSize: 16, fill: '#396', textAlign: 'left', }; } // Highlight high-value data if (this.meta.fieldValue >= 600) { return { ...defaultTextStyle, fontSize: 14, fontWeight: 700, fill: '#f63', textAlign: 'center', }; } return super.getTextStyle(); } } /** * Custom TableColCell - conditional text styling for column headers. * See: https://github.com/antvis/S2/blob/next/packages/s2-core/src/cell/table-col-cell.ts */ class CustomColCell extends TableColCell { getTextStyle() { const defaultTextStyle = super.getTextStyle(); // Style even-indexed columns if (this.meta.colIndex % 2 === 0) { return { ...defaultTextStyle, fontSize: 16, fill: '#396', textAlign: 'left', }; } return super.getTextStyle(); } } const s2Options: S2Options = { width: 600, height: 480, seriesNumber: { enable: true, }, // Register custom cells via callbacks colCell: (node, spreadsheet, headerConfig) => { return new CustomColCell(node, spreadsheet, headerConfig); }, dataCell: (viewMeta, spreadsheet) => { return new Custom