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

fix: 自定义 icon 支持跨域 close #2513 #2524

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion packages/s2-core/__tests__/unit/common/icons/gui-icon-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Group, Shape } from '@antv/g-canvas';
import { registerIcon } from '../../../../src/common/icons';
import { sleep } from '../../../util/helpers';
import { createPivotSheet, sleep } from '../../../util/helpers';
import { GuiIcon } from '@/common/icons/gui-icon';
import { ArrowDown } from '@/common/icons/svg/svgs';

Expand Down Expand Up @@ -51,7 +51,7 @@
.spyOn(console, 'error')
.mockImplementationOnce(() => {});

const icon = new GuiIcon({

Check warning on line 54 in packages/s2-core/__tests__/unit/common/icons/gui-icon-spec.ts

View workflow job for this annotation

GitHub Actions / lint (18)

'icon' is assigned a value but never used
name: 'test',
x: 0,
y: 0,
Expand Down Expand Up @@ -100,4 +100,42 @@
icon.setImageAttrs({ fill: 'red' });
expect(spy).toHaveBeenCalled();
});

// https://github.com/antvis/S2/issues/2513
test('should support cross origin for online url', () => {
const s2 = createPivotSheet({
width: 200,
height: 200,
customSVGIcons: [
{
name: 'Filter',
svg: 'https://gw.alipayobjects.com/zos/antfincdn/gu1Fsz3fw0/filter%26sort_filter.svg',
},
],
headerActionIcons: [
{
iconNames: ['Filter'],
belongsCell: 'colCell',
defaultHide: false,
},
{
iconNames: ['Filter'],
belongsCell: 'rowCell',
defaultHide: false,
},
{
iconNames: ['Filter'],
belongsCell: 'cornerCell',
defaultHide: false,
},
],
});

function render() {
s2.render();
s2.getCanvasElement().toDataURL();
}

expect(render).not.toThrowError();
});
});
2 changes: 2 additions & 0 deletions packages/s2-core/src/common/icons/gui-icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export class GuiIcon extends Group {
// 3、线上支持的图片地址
if (svg.includes(SVG_CONTENT_TYPE) || this.isOnlineLink(svg)) {
img.src = svg;
// https://github.com/antvis/S2/issues/2513
img.crossOrigin = 'anonymous';
} else {
// 传入 svg 字符串(支持颜色fill)
if (fill) {
Expand Down
5 changes: 2 additions & 3 deletions s2-site/docs/manual/basic/sheet-type/table-mode.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ s2.render();

### 序号

在 `s2Options` 中传入 `showSeriesNumber` 即可展示内置的序号,可以自定义序号列标题。[查看 demo](/examples/basic/table#table)
在 `s2Options` 中传入 `showSeriesNumber` 即可展示内置的序号。[查看 demo](/examples/basic/table#table)

```ts
const s2Options = {
showSeriesNumber: true,
seriesNumberText: '自定义序号标题' // 默认 "序号"
showSeriesNumber: true
}
```

Expand Down
1 change: 0 additions & 1 deletion s2-site/examples/basic/table/demo/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ fetch('https://assets.antv.antgroup.com/s2/basic-table-mode.json')
width: 600,
height: 480,
showSeriesNumber: true,
// seriesNumberText: '自定义序号标题',
};

const s2 = new TableSheet(container, s2DataConfig, s2Options);
Expand Down
Loading