From cdf58ea34e7342b5fdd169d43cccc63309b36103 Mon Sep 17 00:00:00 2001 From: Jinke Li Date: Tue, 23 Jan 2024 11:17:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=87=AA=E5=AE=9A=E4=B9=89=20icon=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=B7=A8=E5=9F=9F=20close=20#2513=20(#2524)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 自定义 icon 支持跨域 close #2513 * docs: 更新序号文档 --- .../unit/common/icons/gui-icon-spec.ts | 40 ++++++++++++++++++- packages/s2-core/src/common/icons/gui-icon.ts | 2 + .../manual/basic/sheet-type/table-mode.zh.md | 5 +-- s2-site/examples/basic/table/demo/table.ts | 1 - 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/packages/s2-core/__tests__/unit/common/icons/gui-icon-spec.ts b/packages/s2-core/__tests__/unit/common/icons/gui-icon-spec.ts index 8f32dcde86..6c33d32faf 100644 --- a/packages/s2-core/__tests__/unit/common/icons/gui-icon-spec.ts +++ b/packages/s2-core/__tests__/unit/common/icons/gui-icon-spec.ts @@ -1,6 +1,6 @@ import { Group } from '@antv/g'; import { registerIcon } from '../../../../src/common/icons'; -import { sleep } from '../../../util/helpers'; +import { sleep, createPivotSheet } from '../../../util/helpers'; import { CustomImage } from '@/engine/CustomImage'; import { GuiIcon } from '@/common/icons/gui-icon'; import { ArrowDown } from '@/common/icons/svg/svgs'; @@ -102,4 +102,42 @@ describe('GuiIcon Tests', () => { 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: [ + { + icons: ['Filter'], + belongsCell: 'colCell', + defaultHide: false, + }, + { + icons: ['Filter'], + belongsCell: 'rowCell', + defaultHide: false, + }, + { + icons: ['Filter'], + belongsCell: 'cornerCell', + defaultHide: false, + }, + ], + }); + + async function render() { + await s2.render(); + s2.getCanvasElement().toDataURL(); + } + + expect(render).not.toThrow(); + }); }); diff --git a/packages/s2-core/src/common/icons/gui-icon.ts b/packages/s2-core/src/common/icons/gui-icon.ts index 6812659e49..fbadf71bf6 100644 --- a/packages/s2-core/src/common/icons/gui-icon.ts +++ b/packages/s2-core/src/common/icons/gui-icon.ts @@ -75,6 +75,8 @@ export class GuiIcon extends Group { * 或者 online 链接 */ img.src = svg; + // https://github.com/antvis/S2/issues/2513 + img.crossOrigin = 'anonymous'; } else { // 传入 svg 字符串(支持颜色fill) if (fill) { diff --git a/s2-site/docs/manual/basic/sheet-type/table-mode.zh.md b/s2-site/docs/manual/basic/sheet-type/table-mode.zh.md index 4d88a0b4d7..edc1f015fb 100644 --- a/s2-site/docs/manual/basic/sheet-type/table-mode.zh.md +++ b/s2-site/docs/manual/basic/sheet-type/table-mode.zh.md @@ -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 } ``` diff --git a/s2-site/examples/basic/table/demo/table.ts b/s2-site/examples/basic/table/demo/table.ts index 54e41c1510..1333265372 100644 --- a/s2-site/examples/basic/table/demo/table.ts +++ b/s2-site/examples/basic/table/demo/table.ts @@ -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);