From cff04250d9c2d94eeeaf654e1cfe7320842fda46 Mon Sep 17 00:00:00 2001 From: Weixing Zhang Date: Mon, 12 Mar 2018 17:42:48 +0800 Subject: [PATCH] fix: support area with null data --- package.json | 2 +- src/geom/area.js | 1 - src/geom/shape/util.js | 11 +++++++--- src/plugin/tooltip.js | 50 ++++++++++++++++++++++-------------------- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 32222cae5..20b7a4b44 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@antv/f2", - "version": "3.1.1-beta.9", + "version": "3.1.1-beta.10", "description": "A canvas library which providing 2d draw for G2.", "keywords": [ "canvas", diff --git a/src/geom/area.js b/src/geom/area.js index 68a03bcb4..b60405b0a 100644 --- a/src/geom/area.js +++ b/src/geom/area.js @@ -30,7 +30,6 @@ class Area extends Geom { const yScale = self.getYScale(); const splitArray = ShapeUtil.splitArray(data, yScale.field); cfg.origin = data; // path,line,area 等图的origin 是整个序列 - Util.each(splitArray, function(subData, splitedIndex) { cfg.splitedIndex = splitedIndex; // 传入分割片段索引 用于生成id const points = subData.map(obj => { diff --git a/src/geom/shape/util.js b/src/geom/shape/util.js index 175fec5bf..9100564e6 100644 --- a/src/geom/shape/util.js +++ b/src/geom/shape/util.js @@ -28,13 +28,18 @@ const ShapeUtil = { Util.each(data, function(obj) { yValue = obj._origin ? obj._origin[yField] : obj[yField]; if ((Util.isArray(yValue) && Util.isNil(yValue[0])) || Util.isNil(yValue)) { - arr.push(tmp); - tmp = []; + if (tmp.length) { + arr.push(tmp); + tmp = []; + } } else { tmp.push(obj); } }); - arr.push(tmp); + + if (tmp.length) { + arr.push(tmp); + } return arr; } diff --git a/src/plugin/tooltip.js b/src/plugin/tooltip.js index 1074ebc1b..184296891 100644 --- a/src/plugin/tooltip.js +++ b/src/plugin/tooltip.js @@ -325,30 +325,32 @@ class TooltipController { const type = geom.get('type'); const records = geom.getSnapRecords(point); Util.each(records, record => { - const { x, y, _origin, color } = record; - const tooltipItem = { - x, - y: Util.isArray(y) ? y[1] : y, - color: color || Global.defaultColor, - origin: _origin, - name: getTooltipName(geom, _origin), - value: getTooltipValue(geom, _origin), - title: getTooltipTitle(geom, _origin) - }; - if (marker) { - tooltipItem.marker = Util.mix({ - fill: color || Global.defaultColor - }, marker); - } - items.push(tooltipItem); - - if ([ 'line', 'area', 'path' ].indexOf(type) !== -1) { - tooltipMarkerType = 'circle'; - tooltipMarkerItems.push(tooltipItem); - } else if (type === 'interval' && coord.type === 'cartesian') { - tooltipMarkerType = 'rect'; - tooltipItem.width = geom.getSize(record._origin); - tooltipMarkerItems.push(tooltipItem); + if (record.x && record.y) { + const { x, y, _origin, color } = record; + const tooltipItem = { + x, + y: Util.isArray(y) ? y[1] : y, + color: color || Global.defaultColor, + origin: _origin, + name: getTooltipName(geom, _origin), + value: getTooltipValue(geom, _origin), + title: getTooltipTitle(geom, _origin) + }; + if (marker) { + tooltipItem.marker = Util.mix({ + fill: color || Global.defaultColor + }, marker); + } + items.push(tooltipItem); + + if ([ 'line', 'area', 'path' ].indexOf(type) !== -1) { + tooltipMarkerType = 'circle'; + tooltipMarkerItems.push(tooltipItem); + } else if (type === 'interval' && coord.type === 'cartesian') { + tooltipMarkerType = 'rect'; + tooltipItem.width = geom.getSize(record._origin); + tooltipMarkerItems.push(tooltipItem); + } } }); });