This is an automated email from the ASF dual-hosted git repository. wangzx pushed a commit to branch fix-ssr-data-undefined in repository https://gitbox.apache.org/repos/asf/echarts.git
commit 7a26ce56f2df781935b81f127b6377a45ddb39bf Author: plainheart <y...@all-my-life.cn> AuthorDate: Wed Jan 3 00:57:29 2024 +0800 fix(ssr): remove redundant SVG attributes with `undefined` value. --- src/core/echarts.ts | 8 ++++++-- src/util/innerStore.ts | 2 +- test/svg-ssr.html | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/core/echarts.ts b/src/core/echarts.ts index aaf538c72..69978fd34 100644 --- a/src/core/echarts.ts +++ b/src/core/echarts.ts @@ -429,10 +429,14 @@ class ECharts extends Eventful<ECEventDefinition> { zrender.registerSSRDataGetter(el => { const ecData = getECData(el); + const dataIndex = ecData.dataIndex; + if (dataIndex == null) { + return; + } const hashMap = createHashMap(); hashMap.set('series_index', ecData.seriesIndex); - hashMap.set('data_index', ecData.dataIndex); - hashMap.set('ssr_type', ecData.ssrType); + hashMap.set('data_index', dataIndex); + ecData.ssrType && hashMap.set('ssr_type', ecData.ssrType); return hashMap; }); diff --git a/src/util/innerStore.ts b/src/util/innerStore.ts index a1ecb2a78..cf9ede71a 100644 --- a/src/util/innerStore.ts +++ b/src/util/innerStore.ts @@ -75,7 +75,7 @@ export const setCommonECData = (seriesIndex: number, dataType: SeriesDataType, d childECData.seriesIndex = seriesIndex; childECData.dataIndex = dataIdx; childECData.dataType = dataType; - childECData.ssrType === 'chart'; + childECData.ssrType = 'chart'; }); } } diff --git a/test/svg-ssr.html b/test/svg-ssr.html index af9a4dab7..c08e02fa7 100644 --- a/test/svg-ssr.html +++ b/test/svg-ssr.html @@ -41,7 +41,6 @@ under the License. - <script> require([ @@ -118,5 +117,42 @@ under the License. </script> + <script> + require(['echarts'], function (echarts) { + var option = { + legend: {}, + xAxis: { + type: 'category', + data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] + }, + yAxis: { + type: 'value' + }, + series: [ + { + name: 'line', + data: [150, 230, 224, 218, 135, 147, 260], + type: 'line' + } + ] + }; + var myChart = testHelper.create(echarts, 'main1', { + option: option, + renderer: 'svg', + title: 'There should not be SSR attribute with **undefined** value' + }); + const svgDom = myChart.getZr().painter.getSvgDom(); + const undefinedCount = Array.from(svgDom.querySelectorAll('path')) + .filter(p => p.getAttribute('ecmeta_series_index') === 'undefined').length; + myChart.setOption({ + title: { + text: 'UndefinedCount: ' + undefinedCount, + textStyle: { + color: undefinedCount > 0 ? 'red' : 'black' + } + } + }); + }); + </script> </body> </html> --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org