Skip to content

Commit

Permalink
docs: 修复通过 2.0 官网图表示例的 '在 CodeSandbox 中打开', 错误的安装了 1.x 版本的问题 (#2765)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 authored Jun 6, 2024
1 parent f05b5ae commit 2e75fd2
Show file tree
Hide file tree
Showing 48 changed files with 233 additions and 127 deletions.
5 changes: 4 additions & 1 deletion packages/s2-react/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export { Switcher } from './switcher';
export { type SwitcherProps } from './switcher/interface';
export { TooltipComponent } from './tooltip';
export { CustomTooltip } from './tooltip/custom-tooltip';
export type { TooltipRenderProps } from './tooltip/interface';
export type {
TooltipOperatorMenuOptions,
TooltipRenderProps,
} from './tooltip/interface';

export * from './sheets';
export * from './sheets/interface';
9 changes: 9 additions & 0 deletions s2-site/.dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,19 @@ export default defineConfig({
},
},
],
// https://github.com/antvis/dumi-theme-antv/blob/v3/src/slots/CodeEditor/Toolbar.tsx#L116-L120
playground: {
extraLib: '',
devDependencies: {
typescript: 'latest',
react: '18.3.1',
'react-dom': '18.3.1',
},
dependencies: {
antd: 'latest',
'@ant-design/icons': '^5.3.7',
'@antv/s2': '^2.0.0-next',
'@antv/s2-react': '^2.0.0-next',
},
htmlCodeTemplate: `<!DOCTYPE html>
<html>
Expand Down
3 changes: 2 additions & 1 deletion s2-site/examples/analysis/sort/demo/advanced.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// organize-imports-ignore
import React from 'react';
import { S2DataConfig } from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import insertCSS from 'insert-css';
import { S2DataConfig } from '@antv/s2';

import '@antv/s2-react/dist/style.min.css';

Expand Down
3 changes: 2 additions & 1 deletion s2-site/examples/analysis/sort/demo/group-sort.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// organize-imports-ignore
import React from 'react';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import { S2DataConfig } from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import '@antv/s2-react/dist/style.min.css';

fetch('https://render.alipay.com/p/yuyan/180020010001215413/s2/basic.json')
Expand Down
5 changes: 3 additions & 2 deletions s2-site/examples/analysis/sort/demo/table-sort.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// organize-imports-ignore
import React from 'react';
import { S2DataConfig } from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import '@antv/s2-react/dist/style.min.css';
import { Button } from 'antd';
import insertCSS from 'insert-css';
import { orderBy } from 'lodash';
import React from 'react';
import '@antv/s2-react/dist/style.min.css';

fetch('https://assets.antv.antgroup.com/s2/basic-table-mode.json')
.then((res) => res.json())
Expand Down
5 changes: 3 additions & 2 deletions s2-site/examples/case/art/demo/lost-text.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable max-classes-per-file */
// organize-imports-ignore
import React from 'react';
import {
BaseEvent,
CellType,
Expand All @@ -8,9 +10,8 @@ import {
getTheme,
} from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import { Tag } from 'antd';
import React from 'react';
import '@antv/s2-react/dist/style.min.css';
import { Tag } from 'antd';

const Theme: S2Theme = {
rowCell: {
Expand Down
5 changes: 3 additions & 2 deletions s2-site/examples/case/art/demo/mosaic.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// organize-imports-ignore
import React from 'react';
import { LayoutWidthType, ThemeCfg } from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import { ThemeCfg } from '@antv/s2';
import '@antv/s2-react/dist/style.min.css';

// 了解更多: https://observablehq.com/@pearmini/mosaic-antv-s2
Expand Down Expand Up @@ -28,7 +29,7 @@ fetch(
hoverFocus: false,
},
style: {
layoutWidthType: 'compact',
layoutWidthType: LayoutWidthType.Compact,
colCell: {
// 隐藏列头
height: 0,
Expand Down
5 changes: 3 additions & 2 deletions s2-site/examples/case/art/demo/time-spend-abstract.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// organize-imports-ignore
import React from 'react';
import insertCSS from 'insert-css';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import { Image as GImage } from '@antv/g';
import { DataCell, ThemeCfg } from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import '@antv/s2-react/dist/style.min.css';
import insertCSS from 'insert-css';

const paletteLegendMap = [
{
Expand Down
3 changes: 2 additions & 1 deletion s2-site/examples/case/comparison/demo/measure-comparison.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable max-classes-per-file */
// organize-imports-ignore
import React from 'react';
import { Line, Rect } from '@antv/g';
import {
ColCell,
Expand All @@ -11,7 +13,6 @@ import {
} from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import '@antv/s2-react/dist/style.min.css';
import React from 'react';

// 上涨颜色
const UP_COLOR = '#F46649';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// organize-imports-ignore
import React from 'react';
import { Line, Rect } from '@antv/g';

import insertCSS from 'insert-css';
import { Rect } from '@antv/g';
import { ColCell, S2DataConfig, S2Theme } from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import '@antv/s2-react/dist/style.min.css';
import insertCSS from 'insert-css';

const PALETTE_COLORS = [
{
Expand Down
7 changes: 4 additions & 3 deletions s2-site/examples/case/comparison/demo/philosophers.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// organize-imports-ignore
import React from 'react';
import { max, min, replace } from 'lodash';
import insertCSS from 'insert-css';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import { S2DataConfig } from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import '@antv/s2-react/dist/style.min.css';
import insertCSS from 'insert-css';
import { max, min, replace } from 'lodash';

const PALETTE_COLORS = [
'#B8E1FF',
Expand Down
3 changes: 2 additions & 1 deletion s2-site/examples/case/comparison/demo/time-spend.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-disable max-classes-per-file */
// organize-imports-ignore
import React from 'react';
import { Circle, Line } from '@antv/g';
import { DataCell, Frame, ResizeType, ThemeCfg } from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import '@antv/s2-react/dist/style.min.css';
import insertCSS from 'insert-css';
import React from 'react';

const paletteLegendMap = [
{
Expand Down
29 changes: 21 additions & 8 deletions s2-site/examples/case/data-preview/demo/excel.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { S2DataConfig } from '@antv/s2';
/* eslint-disable no-console */
// organize-imports-ignore
import React from 'react';
import { S2DataConfig, type SpreadSheet } from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import React, { useRef, useState } from 'react';
import '@antv/s2-react/dist/style.min.css';

// 初始化配置
const s2Options: SheetComponentOptions = {
width: 600,
height: 400,
seriesNumber: {
enable: true
enable: true,
},
tooltip: { enable: false },
interaction: {
Expand All @@ -22,23 +24,34 @@ const s2Options: SheetComponentOptions = {

// 初始化数据
const s2DataCfg: S2DataConfig = {
fields: { columns: ['province', 'city', 'type', 'price'] },
fields: {
columns: ['province', 'city', 'type', 'price'],
},
sortParams: [],
data: [],
};

const App = ({ data }) => {
const S2Ref = useRef(null);
const [options, setOptions] = useState<SheetComponentOptions>(s2Options);
const [dataCfg, setDataCfg] = useState<S2DataConfig>({ ...s2DataCfg, data });
const s2Ref = React.useRef<SpreadSheet>(null);
const [options, setOptions] =
React.useState<SheetComponentOptions>(s2Options);
const [dataCfg, setDataCfg] = React.useState<S2DataConfig>({
...s2DataCfg,
data,
});

const onMounted = () => {
console.log('s2:', s2Ref.current);
};

return (
<div style={{ position: 'relative' }}>
<SheetComponent
ref={S2Ref}
ref={s2Ref}
dataCfg={dataCfg}
options={options}
sheetType="editable"
onMounted={onMounted}
/>
</div>
);
Expand Down
21 changes: 12 additions & 9 deletions s2-site/examples/case/data-preview/demo/house.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { S2DataConfig, NODE_ID_SEPARATOR } from '@antv/s2';
/* eslint-disable no-console */
// organize-imports-ignore
import React from 'react';
import { NODE_ID_SEPARATOR, S2DataConfig } from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import { InputNumber, Select, Space } from 'antd';
import insertCSS from 'insert-css';
import { every, filter, isNil, last, map, omit } from 'lodash';
import React, { useState } from 'react';

const defaultHouseInfo = {
name: ['15#', '16#', '21#', '22#'],
Expand Down Expand Up @@ -71,6 +73,7 @@ const defaultSortParams: S2DataConfig['sortParams'] = [
},
},
];

const dataConfig: S2DataConfig = {
data: [],
describe: '如何使用 S2 买房',
Expand Down Expand Up @@ -161,7 +164,7 @@ const RangeSelect = (props) => {
const { data, dataName, onChange } = props;
const min = Math.min(...data);
const max = Math.max(...data);
const [info, setInfo] = useState({ min, max });
const [info, setInfo] = React.useState({ min, max });
const handleChange = (value, key) => {
const tempInfo = Object.assign({}, info);

Expand Down Expand Up @@ -196,7 +199,7 @@ const RangeSelect = (props) => {

const SelectList = (props) => {
const { filterData } = props;
const [filterInfo, setFilterInfo] = useState({});
const [filterInfo, setFilterInfo] = React.useState({});

const onChange = ({ key, value }) => {
let tempHouseInfo = Object.assign({}, filterInfo);
Expand Down Expand Up @@ -230,7 +233,7 @@ const SelectList = (props) => {
};

const Sheet = ({ data }) => {
const [dataSource, setDataSource] = useState(data);
const [dataSource, setDataSource] = React.useState(data);

const filterData = (filterInfo) => {
const result = filter(data, (item) => {
Expand Down Expand Up @@ -283,12 +286,12 @@ fetch(
// If you want to copy the code directly, please remember to install the npm package 'insert-css
insertCSS(`
.select-item {
margin: 5px 16px 0 0;
margin: 5px 16px 0 0;
}
.select-list {
display: flex;
flex-wrap: wrap;
margin-bottom: 20px;
display: flex;
flex-wrap: wrap;
margin-bottom: 20px;
}
.select-label {
display: inline-block;
Expand Down
48 changes: 25 additions & 23 deletions s2-site/examples/case/data-preview/demo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
/* eslint-disable max-params */
/* eslint-disable max-classes-per-file */
import React, { useState, useEffect, useRef } from 'react';

import insertCSS from 'insert-css';
// organize-imports-ignore
import React from 'react';
import { Polygon } from '@antv/g';
import {
TableColCell,
CellType,
GuiIcon,
TableCornerCell,
S2Event,
InteractionStateName,
CellType,
S2DataConfig,
S2Event,
TableColCell,
TableCornerCell,
} from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import '@antv/s2-react/dist/style.min.css';
import {
Input,
Divider,
Space,
Button,
Modal,
Radio,
Checkbox,
Divider,
Form,
Input,
Modal,
Popover,
Checkbox,
Radio,
Space,
message,
} from 'antd';
import insertCSS from 'insert-css';
import { get, uniq } from 'lodash';
import '@antv/s2-react/dist/style.min.css';

const { Search } = Input;

Expand Down Expand Up @@ -241,15 +242,16 @@ const scrollToCell = (rowIndex, colIndex, options, facet, interaction) => {
};

const App = ({ data }) => {
const s2Ref = useRef(null);
const s2Ref = React.useRef(null);
const [columns, setColumns] = React.useState(initColumns);
const [searchKey, setSearchKey] = useState('');
const [searchResult, setSearchResult] = useState([]);
const [colModalVisible, setColModalVisible] = useState(false);
const [searchResultActiveIndex, setSearchResultActiveIndex] = useState(-1);
const [searchKey, setSearchKey] = React.useState('');
const [searchResult, setSearchResult] = React.useState([]);
const [colModalVisible, setColModalVisible] = React.useState(false);
const [searchResultActiveIndex, setSearchResultActiveIndex] =
React.useState(-1);
const [form] = Form.useForm();
const [interactedCol, setInteractedCol] = useState('');
const modalCallbackRef = useRef((e) => {});
const [interactedCol, setInteractedCol] = React.useState('');
const modalCallbackRef = React.useRef((e) => {});

const onIconClick = ({ meta }) => {
setInteractedCol(meta.value);
Expand Down Expand Up @@ -301,7 +303,7 @@ const App = ({ data }) => {
showDefaultHeaderActionIcon: false,
};

const [dataCfg, setDataCfg] = useState<S2DataConfig>({
const [dataCfg, setDataCfg] = React.useState<S2DataConfig>({
fields: {
columns,
},
Expand All @@ -310,7 +312,7 @@ const App = ({ data }) => {
filterParams: [],
});

useEffect(() => {
React.useEffect(() => {
setDataCfg((cfg) => ({
...cfg,
fields: { columns },
Expand Down
6 changes: 4 additions & 2 deletions s2-site/examples/case/kpi-strategy/demo/basic.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { DataCell, S2DataConfig, S2Theme } from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
/* eslint-disable no-console */
// organize-imports-ignore
import React from 'react';
import { Line, Rect } from '@antv/g';
import { DataCell, S2DataConfig, S2Theme } from '@antv/s2';
import { SheetComponent, SheetComponentOptions } from '@antv/s2-react';
import '@antv/s2-react/dist/style.min.css';

// 进度条
Expand Down
Loading

0 comments on commit 2e75fd2

Please sign in to comment.