@antv/g2plot 2.3.39 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.en-US.md +0 -1
  3. package/README.md +0 -1
  4. package/dist/g2plot.min.js +18 -3
  5. package/dist/g2plot.min.js.map +1 -1
  6. package/esm/adaptor/conversion-tag.js +3 -3
  7. package/esm/adaptor/conversion-tag.js.map +1 -1
  8. package/esm/index.d.ts +9 -1
  9. package/esm/index.js +9 -1
  10. package/esm/index.js.map +1 -1
  11. package/esm/plots/area/adaptor.js +15 -5
  12. package/esm/plots/area/adaptor.js.map +1 -1
  13. package/esm/plots/area/constants.d.ts +2 -0
  14. package/esm/plots/area/constants.js +2 -0
  15. package/esm/plots/area/constants.js.map +1 -1
  16. package/esm/plots/area/index.js +11 -4
  17. package/esm/plots/area/index.js.map +1 -1
  18. package/esm/plots/bar/adaptor.d.ts +7 -2
  19. package/esm/plots/bar/adaptor.js +67 -25
  20. package/esm/plots/bar/adaptor.js.map +1 -1
  21. package/esm/plots/bar/index.js +1 -2
  22. package/esm/plots/bar/index.js.map +1 -1
  23. package/esm/plots/line/adaptor.js +30 -15
  24. package/esm/plots/line/adaptor.js.map +1 -1
  25. package/esm/plots/line/constants.d.ts +2 -0
  26. package/esm/plots/line/constants.js +3 -0
  27. package/esm/plots/line/constants.js.map +1 -1
  28. package/esm/plots/line/index.js +8 -1
  29. package/esm/plots/line/index.js.map +1 -1
  30. package/esm/plots/line/interactions/marker-active.js +8 -11
  31. package/esm/plots/line/interactions/marker-active.js.map +1 -1
  32. package/esm/plots/sankey/helper.js +16 -2
  33. package/esm/plots/sankey/helper.js.map +1 -1
  34. package/esm/plots/sankey/types.d.ts +51 -8
  35. package/esm/plots/sankey/types.js.map +1 -1
  36. package/esm/plots/sunburst/adaptor.js +1 -11
  37. package/esm/plots/sunburst/adaptor.js.map +1 -1
  38. package/esm/plots/sunburst/constant.js +1 -0
  39. package/esm/plots/sunburst/constant.js.map +1 -1
  40. package/esm/plots/sunburst/types.d.ts +1 -1
  41. package/esm/plots/sunburst/types.js.map +1 -1
  42. package/esm/plots/venn/types.d.ts +1 -1
  43. package/esm/plots/venn/types.js.map +1 -1
  44. package/esm/utils/data.js +2 -0
  45. package/esm/utils/data.js.map +1 -1
  46. package/esm/utils/geometry.js +2 -1
  47. package/esm/utils/geometry.js.map +1 -1
  48. package/lib/adaptor/conversion-tag.js +3 -3
  49. package/lib/adaptor/conversion-tag.js.map +1 -1
  50. package/lib/index.d.ts +9 -1
  51. package/lib/index.js +13 -5
  52. package/lib/index.js.map +1 -1
  53. package/lib/plots/area/adaptor.js +13 -3
  54. package/lib/plots/area/adaptor.js.map +1 -1
  55. package/lib/plots/area/constants.d.ts +2 -0
  56. package/lib/plots/area/constants.js +3 -1
  57. package/lib/plots/area/constants.js.map +1 -1
  58. package/lib/plots/area/index.js +10 -3
  59. package/lib/plots/area/index.js.map +1 -1
  60. package/lib/plots/bar/adaptor.d.ts +7 -2
  61. package/lib/plots/bar/adaptor.js +69 -26
  62. package/lib/plots/bar/adaptor.js.map +1 -1
  63. package/lib/plots/bar/index.js +1 -2
  64. package/lib/plots/bar/index.js.map +1 -1
  65. package/lib/plots/line/adaptor.js +29 -14
  66. package/lib/plots/line/adaptor.js.map +1 -1
  67. package/lib/plots/line/constants.d.ts +2 -0
  68. package/lib/plots/line/constants.js +4 -1
  69. package/lib/plots/line/constants.js.map +1 -1
  70. package/lib/plots/line/index.js +7 -0
  71. package/lib/plots/line/index.js.map +1 -1
  72. package/lib/plots/line/interactions/marker-active.js +8 -11
  73. package/lib/plots/line/interactions/marker-active.js.map +1 -1
  74. package/lib/plots/sankey/helper.js +16 -2
  75. package/lib/plots/sankey/helper.js.map +1 -1
  76. package/lib/plots/sankey/types.d.ts +51 -8
  77. package/lib/plots/sankey/types.js.map +1 -1
  78. package/lib/plots/sunburst/adaptor.js +1 -11
  79. package/lib/plots/sunburst/adaptor.js.map +1 -1
  80. package/lib/plots/sunburst/constant.js +1 -0
  81. package/lib/plots/sunburst/constant.js.map +1 -1
  82. package/lib/plots/sunburst/types.d.ts +1 -1
  83. package/lib/plots/sunburst/types.js.map +1 -1
  84. package/lib/plots/venn/types.d.ts +1 -1
  85. package/lib/plots/venn/types.js.map +1 -1
  86. package/lib/utils/data.js +2 -0
  87. package/lib/utils/data.js.map +1 -1
  88. package/lib/utils/geometry.js +2 -1
  89. package/lib/utils/geometry.js.map +1 -1
  90. package/package.json +8 -7
  91. package/src/adaptor/conversion-tag.ts +3 -3
  92. package/src/index.ts +9 -1
  93. package/src/plots/area/adaptor.ts +16 -5
  94. package/src/plots/area/constants.ts +3 -0
  95. package/src/plots/area/index.ts +10 -3
  96. package/src/plots/bar/adaptor.ts +94 -47
  97. package/src/plots/bar/index.ts +1 -2
  98. package/src/plots/line/adaptor.ts +35 -14
  99. package/src/plots/line/constants.ts +4 -0
  100. package/src/plots/line/index.ts +8 -1
  101. package/src/plots/line/interactions/marker-active.ts +9 -12
  102. package/src/plots/sankey/helper.ts +26 -9
  103. package/src/plots/sankey/types.ts +52 -8
  104. package/src/plots/sunburst/adaptor.ts +9 -13
  105. package/src/plots/sunburst/constant.ts +1 -0
  106. package/src/plots/sunburst/types.ts +1 -1
  107. package/src/plots/venn/types.ts +1 -1
  108. package/src/utils/data.ts +1 -0
  109. package/src/utils/geometry.ts +2 -1
  110. package/esm/plots/bar/utils.d.ts +0 -6
  111. package/esm/plots/bar/utils.js +0 -8
  112. package/esm/plots/bar/utils.js.map +0 -1
  113. package/lib/plots/bar/utils.d.ts +0 -6
  114. package/lib/plots/bar/utils.js +0 -12
  115. package/lib/plots/bar/utils.js.map +0 -1
  116. package/src/plots/bar/utils.ts +0 -9
package/lib/utils/data.js CHANGED
@@ -11,6 +11,8 @@ var pick_1 = require("./pick");
11
11
  * @param field
12
12
  */
13
13
  function adjustYMetaByZero(data, field) {
14
+ if (!data)
15
+ return {};
14
16
  // 过滤出数字数据
15
17
  var numberData = data.filter(function (datum) {
16
18
  var v = util_1.get(datum, [field]);
@@ -1 +1 @@
1
- {"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/utils/data.ts"],"names":[],"mappings":";;;;AAAA,mCAAmD;AAGnD,yCAAyC;AACzC,+BAA8B;AAE9B;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,IAAU,EAAE,KAAa;IACzD,UAAU;IACV,IAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAC,KAAY;QAC1C,IAAM,CAAC,GAAG,UAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9B,OAAO,eAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,IAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,UAAC,KAAY,IAAK,OAAA,UAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAxB,CAAwB,CAAC,CAAC;IAC5E,IAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,UAAC,KAAY,IAAK,OAAA,UAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAxB,CAAwB,CAAC,CAAC;IAE5E,oFAAoF;IACpF,IAAI,MAAM,EAAE;QACV,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;KACnB;IACD,IAAI,MAAM,EAAE;QACV,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;KACnB;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAlBD,8CAkBC;AAED;;;;;;;GAOG;AACH,SAAgB,2BAA2B,CACzC,IAAU,EACV,WAAmB,EACnB,WAAmB,EACnB,WAAmB,EACnB,SAAwB;IAAxB,0BAAA,EAAA,cAAwB;IAExB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAA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EAAE,GAAG,CAAC,CAAC,EAAE,EAAX,CAAW,CAAC;QAC1D,KAAK,OAAA;KACN,CAAC;AACJ,CAAC;AAzDD,kEAyDC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,IAAqB,EAAE,KAAa;IACrE,IAAM,WAAW,GAAG,aAAM,CAAC,IAAI,EAAE,UAAC,CAAC;QACjC,IAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;QACnB,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,WAAW;IACX,eAAG,CAAC,iBAAK,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,qCAAqC,CAAC,CAAC;IAE3F,OAAO,WAAW,CAAC;AACrB,CAAC;AAVD,gDAUC","sourcesContent":["import { get, isNumber, filter } from '@antv/util';\nimport { Data, Datum, Meta, Options } from '../types';\nimport { Node, NodeLinkData } from '../types/relation-data';\nimport { LEVEL, log } from './invariant';\nimport { pick } from './pick';\n\n/**\n * 查看数据是否是全负数、或者全正数\n * @param data\n * @param field\n */\nexport function adjustYMetaByZero(data: Data, field: string): Meta {\n // 过滤出数字数据\n const numberData = data.filter((datum: Datum) => {\n const v = get(datum, [field]);\n return isNumber(v) && !isNaN(v);\n });\n\n const gtZero = numberData.every((datum: Datum) => get(datum, [field]) >= 0);\n const ltZero = numberData.every((datum: Datum) => get(datum, [field]) <= 0);\n\n // 目前是增量更新,对 { min: 0, max: undefined } 进行 update({ max: 0 }) 会得到 { min: 0, max: 0 }\n if (gtZero) {\n return { min: 0 };\n }\n if (ltZero) {\n return { max: 0 };\n }\n return {};\n}\n\n/**\n * 转换数据格式为带有节点与边的数据格式\n * @param data\n * @param sourceField\n * @param targetField\n * @param weightField\n * @param rawFields 存放一些原数据\n */\nexport function transformDataToNodeLinkData(\n data: Data,\n sourceField: string,\n targetField: string,\n weightField: string,\n rawFields: string[] = []\n): NodeLinkData {\n if (!Array.isArray(data)) {\n return {\n nodes: [],\n links: [],\n };\n }\n\n // const nodes = [];\n const links = [];\n // 先使用对象方式存储\n const nodesMap: Record<string, Node> = {};\n let nodesIndex = -1;\n // 数组变换成 chord layout 的数据结构\n data.forEach((datum: Datum) => {\n const source = datum[sourceField];\n const target = datum[targetField];\n const weight = datum[weightField];\n\n const rawData = pick(datum, rawFields);\n\n // source node\n if (!nodesMap[source]) {\n nodesMap[source] = {\n id: ++nodesIndex,\n name: source,\n ...rawData,\n };\n }\n if (!nodesMap[target]) {\n nodesMap[target] = {\n id: ++nodesIndex,\n name: target,\n ...rawData,\n };\n }\n // links\n links.push({\n source: nodesMap[source].id,\n target: nodesMap[target].id,\n // sourceName: source,\n // targetName: target,\n value: weight,\n ...rawData,\n });\n });\n return {\n // 需要按照 id 的顺序\n nodes: Object.values(nodesMap).sort((a, b) => a.id - b.id),\n links,\n };\n}\n\n/**\n * 处理不合法的数据(过滤 非数值型 和 NaN,保留 null)\n * @param data\n * @param angleField\n */\nexport function processIllegalData(data: Options['data'], field: string) {\n const processData = filter(data, (d) => {\n const v = d[field];\n return v === null || (typeof v === 'number' && !isNaN(v));\n });\n\n // 打印异常数据情况\n log(LEVEL.WARN, processData.length === data.length, 'illegal data existed in chart data.');\n\n return processData;\n}\n"]}
1
+ {"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/utils/data.ts"],"names":[],"mappings":";;;;AAAA,mCAAmD;AAGnD,yCAAyC;AACzC,+BAA8B;AAE9B;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,IAAU,EAAE,KAAa;IACzD,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,UAAU;IACV,IAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAC,KAAY;QAC1C,IAAM,CAAC,GAAG,UAAG,CAAC,KAAK,EAAE,CAAC,KAAK,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CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,WAAW;IACX,eAAG,CAAC,iBAAK,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,qCAAqC,CAAC,CAAC;IAE3F,OAAO,WAAW,CAAC;AACrB,CAAC;AAVD,gDAUC","sourcesContent":["import { get, isNumber, filter } from '@antv/util';\nimport { Data, Datum, Meta, Options } from '../types';\nimport { Node, NodeLinkData } from '../types/relation-data';\nimport { LEVEL, log } from './invariant';\nimport { pick } from './pick';\n\n/**\n * 查看数据是否是全负数、或者全正数\n * @param data\n * @param field\n */\nexport function adjustYMetaByZero(data: Data, field: string): Meta {\n if (!data) return {};\n // 过滤出数字数据\n const numberData = data.filter((datum: Datum) => {\n const v = get(datum, [field]);\n return isNumber(v) && !isNaN(v);\n });\n\n const gtZero = numberData.every((datum: Datum) => get(datum, [field]) >= 0);\n const ltZero = numberData.every((datum: Datum) => get(datum, [field]) <= 0);\n\n // 目前是增量更新,对 { min: 0, max: undefined } 进行 update({ max: 0 }) 会得到 { min: 0, max: 0 }\n if (gtZero) {\n return { min: 0 };\n }\n if (ltZero) {\n return { max: 0 };\n }\n return {};\n}\n\n/**\n * 转换数据格式为带有节点与边的数据格式\n * @param data\n * @param sourceField\n * @param targetField\n * @param weightField\n * @param rawFields 存放一些原数据\n */\nexport function transformDataToNodeLinkData(\n data: Data,\n sourceField: string,\n targetField: string,\n weightField: string,\n rawFields: string[] = []\n): NodeLinkData {\n if (!Array.isArray(data)) {\n return {\n nodes: [],\n links: [],\n };\n }\n\n // const nodes = [];\n const links = [];\n // 先使用对象方式存储\n const nodesMap: Record<string, Node> = {};\n let nodesIndex = -1;\n // 数组变换成 chord layout 的数据结构\n data.forEach((datum: Datum) => {\n const source = datum[sourceField];\n const target = datum[targetField];\n const weight = datum[weightField];\n\n const rawData = pick(datum, rawFields);\n\n // source node\n if (!nodesMap[source]) {\n nodesMap[source] = {\n id: ++nodesIndex,\n name: source,\n ...rawData,\n };\n }\n if (!nodesMap[target]) {\n nodesMap[target] = {\n id: ++nodesIndex,\n name: target,\n ...rawData,\n };\n }\n // links\n links.push({\n source: nodesMap[source].id,\n target: nodesMap[target].id,\n // sourceName: source,\n // targetName: target,\n value: weight,\n ...rawData,\n });\n });\n return {\n // 需要按照 id 的顺序\n nodes: Object.values(nodesMap).sort((a, b) => a.id - b.id),\n links,\n };\n}\n\n/**\n * 处理不合法的数据(过滤 非数值型 和 NaN,保留 null)\n * @param data\n * @param angleField\n */\nexport function processIllegalData(data: Options['data'], field: string) {\n const processData = filter(data, (d) => {\n const v = d[field];\n return v === null || (typeof v === 'number' && !isNaN(v));\n });\n\n // 打印异常数据情况\n log(LEVEL.WARN, processData.length === data.length, 'illegal data existed in chart data.');\n\n return processData;\n}\n"]}
@@ -8,7 +8,8 @@ var util_1 = require("@antv/util");
8
8
  * @param type
9
9
  */
10
10
  function findGeometry(view, type) {
11
- return view.geometries.find(function (g) { return g.type === type; });
11
+ var geometries = getAllGeometriesRecursively(view);
12
+ return geometries.find(function (g) { return g.type === type; });
12
13
  }
13
14
  exports.findGeometry = findGeometry;
14
15
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"geometry.js","sourceRoot":"","sources":["../../src/utils/geometry.ts"],"names":[],"mappings":";;;AACA,mCAAyC;AAEzC;;;;GAIG;AACH,SAAgB,YAAY,CAAC,IAAU,EAAE,IAAY;IACnD,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAC,CAAW,IAAK,OAAA,CAAC,CAAC,IAAI,KAAK,IAAI,EAAf,CAAe,CAAC,CAAC;AAChE,CAAC;AAFD,oCAEC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,IAAU;IACvC,OAAO,aAAM,CACX,IAAI,CAAC,UAAU,EACf,UAAC,CAAY,EAAE,QAAkB;QAC/B,OAAO,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC;AARD,wCAQC;AAED;;GAEG;AACH,SAAgB,yBAAyB,CAAC,IAAU;IAClD,IAAI,UAAG,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE;QAC1C,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC;KAC7B;IAED,OAAO,aAAM,CACX,IAAI,CAAC,KAAK,EACV,UAAC,GAAc,EAAE,OAAa;QAC5B,OAAO,GAAG,CAAC,MAAM,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC,EACD,cAAc,CAAC,IAAI,CAAC,CACrB,CAAC;AACJ,CAAC;AAZD,8DAYC;AAED;;GAEG;AACH,SAAgB,2BAA2B,CAAC,IAAU;IACpD,IAAI,UAAG,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE;QAC1C,OAAO,IAAI,CAAC,UAAU,CAAC;KACxB;IAED,OAAO,aAAM,CACX,IAAI,CAAC,KAAK,EACV,UAAC,GAAe,EAAE,OAAa;QAC7B,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC,EACD,IAAI,CAAC,UAAU,CAChB,CAAC;AACJ,CAAC;AAZD,kEAYC","sourcesContent":["import { Geometry, View, Element } from '@antv/g2';\nimport { reduce, get } from '@antv/util';\n\n/**\n * 在 View 中查找第一个指定 type 类型的 geometry\n * @param view\n * @param type\n */\nexport function findGeometry(view: View, type: string): Geometry {\n return view.geometries.find((g: Geometry) => g.type === type);\n}\n\n/**\n * 获取 View 的 所有 elements\n */\nexport function getAllElements(view: View): Element[] {\n return reduce(\n view.geometries,\n (r: Element[], geometry: Geometry) => {\n return r.concat(geometry.elements);\n },\n []\n );\n}\n\n/**\n * 递归获取 View 的 所有 elements, 包括 View 的子 View\n */\nexport function getAllElementsRecursively(view: View): Element[] {\n if (get(view, ['views', 'length'], 0) <= 0) {\n return getAllElements(view);\n }\n\n return reduce(\n view.views,\n (ele: Element[], subView: View) => {\n return ele.concat(getAllElementsRecursively(subView));\n },\n getAllElements(view)\n );\n}\n\n/**\n * 递归获取 View 的 所有 geometries, 包括 View 的子 View\n */\nexport function getAllGeometriesRecursively(view: View): Geometry[] {\n if (get(view, ['views', 'length'], 0) <= 0) {\n return view.geometries;\n }\n\n return reduce(\n view.views,\n (ele: Geometry[], subView: View) => {\n return ele.concat(subView.geometries);\n },\n view.geometries\n );\n}\n"]}
1
+ {"version":3,"file":"geometry.js","sourceRoot":"","sources":["../../src/utils/geometry.ts"],"names":[],"mappings":";;;AACA,mCAAyC;AAEzC;;;;GAIG;AACH,SAAgB,YAAY,CAAC,IAAU,EAAE,IAAY;IACnD,IAAM,UAAU,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAC;IACrD,OAAO,UAAU,CAAC,IAAI,CAAC,UAAC,CAAW,IAAK,OAAA,CAAC,CAAC,IAAI,KAAK,IAAI,EAAf,CAAe,CAAC,CAAC;AAC3D,CAAC;AAHD,oCAGC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,IAAU;IACvC,OAAO,aAAM,CACX,IAAI,CAAC,UAAU,EACf,UAAC,CAAY,EAAE,QAAkB;QAC/B,OAAO,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC;AARD,wCAQC;AAED;;GAEG;AACH,SAAgB,yBAAyB,CAAC,IAAU;IAClD,IAAI,UAAG,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE;QAC1C,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC;KAC7B;IAED,OAAO,aAAM,CACX,IAAI,CAAC,KAAK,EACV,UAAC,GAAc,EAAE,OAAa;QAC5B,OAAO,GAAG,CAAC,MAAM,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC,EACD,cAAc,CAAC,IAAI,CAAC,CACrB,CAAC;AACJ,CAAC;AAZD,8DAYC;AAED;;GAEG;AACH,SAAgB,2BAA2B,CAAC,IAAU;IACpD,IAAI,UAAG,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE;QAC1C,OAAO,IAAI,CAAC,UAAU,CAAC;KACxB;IAED,OAAO,aAAM,CACX,IAAI,CAAC,KAAK,EACV,UAAC,GAAe,EAAE,OAAa;QAC7B,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC,EACD,IAAI,CAAC,UAAU,CAChB,CAAC;AACJ,CAAC;AAZD,kEAYC","sourcesContent":["import { Geometry, View, Element } from '@antv/g2';\nimport { reduce, get } from '@antv/util';\n\n/**\n * 在 View 中查找第一个指定 type 类型的 geometry\n * @param view\n * @param type\n */\nexport function findGeometry(view: View, type: string): Geometry {\n const geometries = getAllGeometriesRecursively(view);\n return geometries.find((g: Geometry) => g.type === type);\n}\n\n/**\n * 获取 View 的 所有 elements\n */\nexport function getAllElements(view: View): Element[] {\n return reduce(\n view.geometries,\n (r: Element[], geometry: Geometry) => {\n return r.concat(geometry.elements);\n },\n []\n );\n}\n\n/**\n * 递归获取 View 的 所有 elements, 包括 View 的子 View\n */\nexport function getAllElementsRecursively(view: View): Element[] {\n if (get(view, ['views', 'length'], 0) <= 0) {\n return getAllElements(view);\n }\n\n return reduce(\n view.views,\n (ele: Element[], subView: View) => {\n return ele.concat(getAllElementsRecursively(subView));\n },\n getAllElements(view)\n );\n}\n\n/**\n * 递归获取 View 的 所有 geometries, 包括 View 的子 View\n */\nexport function getAllGeometriesRecursively(view: View): Geometry[] {\n if (get(view, ['views', 'length'], 0) <= 0) {\n return view.geometries;\n }\n\n return reduce(\n view.views,\n (ele: Geometry[], subView: View) => {\n return ele.concat(subView.geometries);\n },\n view.geometries\n );\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@antv/g2plot",
3
- "version": "2.3.39",
4
- "description": "An nteractive and responsive charting library",
3
+ "version": "2.4.2",
4
+ "description": "An interactive and responsive charting library",
5
5
  "keywords": [
6
6
  "chart",
7
7
  "plot",
@@ -21,14 +21,14 @@
21
21
  "homepage": "https://g2plot.antv.vision",
22
22
  "repository": {
23
23
  "type": "git",
24
- "url": "https://github.com/antvis/g2plot"
24
+ "url": "https://github.com/antvis/G2plot"
25
25
  },
26
26
  "scripts": {
27
27
  "start": "npm run site:clean && npm run site:develop",
28
28
  "site:develop": "cross-env PORT=8080 gatsby develop --open -H 0.0.0.0",
29
- "site:build": "npm run site:clean && gatsby build --prefix-paths",
29
+ "site:build": "NODE_OPTIONS='--max_old_space_size=8192' npm run site:clean && gatsby build --prefix-paths",
30
30
  "site:clean": "gatsby clean",
31
- "site:deploy": "yarn run build && yarn run site:build && gh-pages -d public",
31
+ "site:deploy": "npm run build && npm run site:build && gh-pages -d public",
32
32
  "fix": "eslint --ext .ts ./src ./__tests__ --fix && prettier --write ./src ./__tests__ && lint-md --fix ./examples ./docs",
33
33
  "build": "run-s clean lib dist size",
34
34
  "size": "limit-size",
@@ -66,7 +66,7 @@
66
66
  },
67
67
  "devDependencies": {
68
68
  "@antv/data-set": "^0.11.5",
69
- "@antv/gatsby-theme-antv": "^1.1.8",
69
+ "@antv/gatsby-theme-antv": "^1.1.15",
70
70
  "@babel/core": "^7.10.4",
71
71
  "@babel/plugin-transform-runtime": "^7.11.5",
72
72
  "@babel/preset-env": "^7.10.4",
@@ -100,6 +100,7 @@
100
100
  "miz": "^1.0.1",
101
101
  "npm-run-all": "^4.1.5",
102
102
  "prettier": "^2.0.1",
103
+ "rc-for-plots": "^0.0.1",
103
104
  "react": "^16.11.0",
104
105
  "react-dom": "^16.11.0",
105
106
  "react-i18next": "^11.7.0",
@@ -144,7 +145,7 @@
144
145
  "limit-size": [
145
146
  {
146
147
  "path": "dist/g2plot.min.js",
147
- "limit": "995 Kb"
148
+ "limit": "998 Kb"
148
149
  },
149
150
  {
150
151
  "path": "dist/g2plot.min.js",
@@ -90,8 +90,8 @@ function renderArrowTag(config: TagRenderConfig, elemPrev: Element, elemNext: El
90
90
  const { view, geometry, group, options, horizontal } = config;
91
91
  const { offset, size, arrow } = options;
92
92
  const coordinate = view.getCoordinate();
93
- const pointPrev = parsePoints(coordinate, elemPrev)[horizontal ? 3 : 0];
94
- const pointNext = parsePoints(coordinate, elemNext)[horizontal ? 0 : 3];
93
+ const pointPrev = parsePoints(coordinate, elemPrev)[3];
94
+ const pointNext = parsePoints(coordinate, elemNext)[0];
95
95
  const totalHeight = pointNext.y - pointPrev.y;
96
96
  const totalWidth = pointNext.x - pointPrev.x;
97
97
 
@@ -238,7 +238,7 @@ export function conversionTag<O extends OptionWithConversionTag & Options>(
238
238
  horizontal,
239
239
  options: getConversionTagOptionsWithDefaults(conversionTag, horizontal),
240
240
  };
241
- const elements = horizontal ? interval.elements : interval.elements.slice().reverse();
241
+ const elements = interval.elements;
242
242
  each(elements, (elem: Element, idx: number) => {
243
243
  if (idx > 0) {
244
244
  renderTag(config, elements[idx - 1], elem);
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export const version = '2.3.39';
1
+ export const version = '2.4.2';
2
2
 
3
3
  // G2 自定义能力透出
4
4
  import * as G2 from '@antv/g2';
@@ -176,6 +176,14 @@ export type { MixOptions } from './plots/mix';
176
176
  export { Facet } from './plots/facet';
177
177
  export type { FacetOptions } from './plots/facet';
178
178
 
179
+ /** 提供一些工具方法 */
180
+ import { findGeometry, getAllGeometriesRecursively, findViewById } from './utils';
181
+ const Util = {
182
+ findGeometry,
183
+ findViewById,
184
+ getAllGeometriesRecursively,
185
+ };
186
+ export { Util };
179
187
  /** 开发 adaptor 可能会用到的方法或一些工具方法,不强制使用 */
180
188
  export { flow, measureTextWidth } from './utils';
181
189
 
@@ -1,13 +1,14 @@
1
1
  import { Geometry } from '@antv/g2';
2
- import { each } from '@antv/util';
2
+ import { each, isNil } from '@antv/util';
3
3
  import { tooltip, slider, interaction, animation, theme, annotation, limitInPlot, pattern } from '../../adaptor/common';
4
- import { findGeometry } from '../../utils';
4
+ import { findGeometry, getAllGeometriesRecursively } from '../../utils';
5
5
  import { Params } from '../../core/adaptor';
6
6
  import { area, point, line } from '../../adaptor/geometries';
7
7
  import { flow, transformLabel, deepAssign } from '../../utils';
8
8
  import { getDataWhetherPecentage } from '../../utils/transform/percent';
9
9
  import { Datum } from '../../types';
10
10
  import { meta, legend, axis } from '../line/adaptor';
11
+ import { POINT_VIEW_ID } from './constants';
11
12
  import { AreaOptions } from './types';
12
13
 
13
14
  export { meta };
@@ -70,12 +71,21 @@ function geometry(params: Params<AreaOptions>): Params<AreaOptions> {
70
71
  const lineParams = deepAssign({ options: { line: { size: 2 } } }, primary, {
71
72
  options: { sizeField: seriesField, tooltip: false },
72
73
  });
73
- const pointParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });
74
74
 
75
75
  // area geometry 处理
76
76
  area(primary);
77
77
  line(lineParams);
78
- point(pointParams);
78
+
79
+ const pointParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });
80
+ if (pointMapping) {
81
+ const pointView = chart.createView({ id: POINT_VIEW_ID });
82
+ pointView.axis(false);
83
+ pointView.tooltip(false);
84
+ pointView.legend(false);
85
+ // [PERFORMANCE] 🚀 数据为空的 point 标注点都不渲染(不包括:数据为 0)
86
+ pointView.data(data.filter((d) => !isNil(d[yField])));
87
+ point({ ...pointParams, chart: pointView });
88
+ }
79
89
 
80
90
  return params;
81
91
  }
@@ -121,7 +131,8 @@ function adjust(params: Params<AreaOptions>): Params<AreaOptions> {
121
131
  const { chart, options } = params;
122
132
  const { isStack, isPercent, seriesField } = options;
123
133
  if ((isPercent || isStack) && seriesField) {
124
- each(chart.geometries, (g: Geometry) => {
134
+ const geometries = getAllGeometriesRecursively(chart);
135
+ each(geometries, (g: Geometry) => {
125
136
  g.adjust('stack');
126
137
  });
127
138
  }
@@ -1,6 +1,9 @@
1
1
  import { Plot } from '../../core/plot';
2
2
  import { deepAssign } from '../../utils';
3
3
 
4
+ /** point 标注点视图 */
5
+ export const POINT_VIEW_ID = 'point-view';
6
+
4
7
  /**
5
8
  * 面积图默认配置项
6
9
  */
@@ -1,9 +1,11 @@
1
+ import { isNil } from '@antv/util';
1
2
  import { Plot } from '../../core/plot';
2
3
  import { Adaptor } from '../../core/adaptor';
3
4
  import { getDataWhetherPecentage } from '../../utils/transform/percent';
5
+ import { findViewById } from '../../utils';
4
6
  import { AreaOptions } from './types';
5
7
  import { adaptor, meta } from './adaptor';
6
- import { DEFAULT_OPTIONS } from './constants';
8
+ import { DEFAULT_OPTIONS, POINT_VIEW_ID } from './constants';
7
9
 
8
10
  export type { AreaOptions };
9
11
 
@@ -32,10 +34,15 @@ export class Area extends Plot<AreaOptions> {
32
34
  */
33
35
  public changeData(data: AreaOptions['data']) {
34
36
  this.updateOption({ data });
35
- const { isPercent, xField, yField } = this.options;
36
37
  const { chart, options } = this;
38
+ const { isPercent, xField, yField } = options;
37
39
  meta({ chart, options });
38
- this.chart.changeData(getDataWhetherPecentage(data, yField, xField, yField, isPercent));
40
+ const chartdata = getDataWhetherPecentage(data, yField, xField, yField, isPercent);
41
+ this.chart.changeData(chartdata);
42
+ const pointView = findViewById(this.chart, POINT_VIEW_ID);
43
+ if (pointView) {
44
+ pointView.changeData(data.filter((d) => !isNil(d[yField])));
45
+ }
39
46
  }
40
47
 
41
48
  /**
@@ -1,31 +1,62 @@
1
1
  import { Params } from '../../core/adaptor';
2
+ import { tooltip } from '../../adaptor/common';
3
+ import { deepAssign, flow } from '../../utils';
4
+ import { Axis } from '../../types';
2
5
  import { adaptor as columnAdaptor } from '../column/adaptor';
6
+ export { meta } from '../column/adaptor';
3
7
  import { BarOptions } from './types';
4
- import { transformBarData } from './utils';
5
8
 
6
- export { meta } from '../column/adaptor';
9
+ /**
10
+ * 处理默认配置项
11
+ * 1. switch xField、 yField
12
+ * 2. switch xAxis、 yAxis and adjust axis.position configuration
13
+ */
14
+ function defaultOptions(params: Params<BarOptions>): Params<BarOptions> {
15
+ const { options } = params;
16
+ const { xField, yField, xAxis, yAxis } = options;
17
+
18
+ const position = {
19
+ left: 'bottom',
20
+ right: 'top',
21
+ top: 'left',
22
+ bottom: 'right',
23
+ };
24
+
25
+ const verticalAxis =
26
+ yAxis !== false
27
+ ? {
28
+ position: position[yAxis?.position || 'left'],
29
+ ...yAxis,
30
+ }
31
+ : false;
32
+ const horizontalAxis =
33
+ xAxis !== false
34
+ ? {
35
+ position: position[xAxis?.position || 'bottom'],
36
+ ...xAxis,
37
+ }
38
+ : false;
39
+
40
+ return {
41
+ ...params,
42
+ options: {
43
+ ...options,
44
+ xField: yField,
45
+ yField: xField,
46
+ // 条形图 xAxis,yAxis 不可以做 deepAssign
47
+ xAxis: verticalAxis as Axis,
48
+ yAxis: horizontalAxis as Axis,
49
+ },
50
+ };
51
+ }
7
52
 
8
53
  /**
9
- * 柱形图适配器
54
+ * label 适配器
10
55
  * @param params
11
56
  */
12
- export function adaptor(params: Params<BarOptions>) {
13
- const { chart, options } = params;
14
- const {
15
- xField,
16
- yField,
17
- xAxis,
18
- yAxis,
19
- barStyle,
20
- barWidthRatio,
21
- label,
22
- data,
23
- seriesField,
24
- isStack,
25
- minBarWidth,
26
- maxBarWidth,
27
- } = options;
28
-
57
+ function label(params: Params<BarOptions>): Params<BarOptions> {
58
+ const { options } = params;
59
+ const { label } = options;
29
60
  // label of bar charts default position is left, if plot has label
30
61
  if (label && !label.position) {
31
62
  label.position = 'left';
@@ -40,59 +71,75 @@ export function adaptor(params: Params<BarOptions>) {
40
71
  }
41
72
  }
42
73
 
74
+ return deepAssign({}, params, { options: { label } });
75
+ }
76
+
77
+ /**
78
+ * legend 适配器
79
+ * @param params
80
+ */
81
+ function legend(params: Params<BarOptions>): Params<BarOptions> {
82
+ const { options } = params;
83
+
43
84
  // 默认 legend 位置
85
+ const { seriesField, isStack } = options;
44
86
  let { legend } = options;
45
87
  if (seriesField) {
46
88
  if (legend !== false) {
47
89
  legend = {
48
90
  position: isStack ? 'top-left' : 'right-top',
49
- reversed: isStack ? false : true,
50
91
  ...(legend || {}),
51
92
  };
52
93
  }
53
94
  } else {
54
95
  legend = false;
55
96
  }
56
- // @ts-ignore 直接改值
57
- params.options.legend = legend;
58
97
 
59
- // 默认 tooltip 配置
60
- let { tooltip } = options;
61
- if (seriesField) {
62
- if (tooltip !== false) {
63
- tooltip = {
64
- reversed: isStack ? false : true,
65
- ...(tooltip || {}),
66
- };
67
- }
68
- }
69
- // @ts-ignore 直接改值
70
- params.options.tooltip = tooltip;
98
+ return deepAssign({}, params, { options: { legend } });
99
+ }
71
100
 
72
- // transpose column to bar
73
- chart.coordinate().transpose();
101
+ /**
102
+ * coordinate 适配器
103
+ * @param params
104
+ */
105
+ function coordinate(params: Params<BarOptions>): Params<BarOptions> {
106
+ const { chart } = params;
107
+ // transpose column to bar 对角变换 & y 方向镜像变换
108
+ chart.coordinate({ actions: [['transpose'], ['reflect', 'y']] });
109
+ return params;
110
+ }
111
+
112
+ /**
113
+ * 柱形图适配器
114
+ * @param params
115
+ */
116
+ export function geometry(params: Params<BarOptions>) {
117
+ const { chart, options } = params;
118
+
119
+ const { barStyle, barWidthRatio, minBarWidth, maxBarWidth, barBackground } = options;
74
120
 
75
121
  return columnAdaptor(
76
122
  {
77
123
  chart,
78
124
  options: {
79
125
  ...options,
80
- label,
81
- // switch xField and yField
82
- xField: yField,
83
- yField: xField,
84
- xAxis: yAxis,
85
- yAxis: xAxis,
86
126
  // rename attrs as column
87
127
  columnStyle: barStyle,
88
128
  columnWidthRatio: barWidthRatio,
89
129
  minColumnWidth: minBarWidth,
90
130
  maxColumnWidth: maxBarWidth,
91
- columnBackground: options.barBackground,
92
- // bar 调整数据顺序
93
- data: transformBarData(data),
131
+ columnBackground: barBackground,
94
132
  },
95
133
  },
96
134
  true
97
- );
135
+ ) as Params<BarOptions>;
136
+ }
137
+
138
+ /**
139
+ * @param chart
140
+ * @param options
141
+ */
142
+ export function adaptor(params: Params<BarOptions>): Params<BarOptions> {
143
+ // flow 的方式处理所有的配置到 G2 API
144
+ return flow<Params<BarOptions>>(defaultOptions, label, legend, tooltip, coordinate, geometry)(params);
98
145
  }
@@ -4,7 +4,6 @@ import { getDataWhetherPecentage } from '../../utils/transform/percent';
4
4
  import { BarOptions } from './types';
5
5
  import { adaptor, meta } from './adaptor';
6
6
  import { DEFAULT_OPTIONS } from './constants';
7
- import { transformBarData } from './utils';
8
7
 
9
8
  export type { BarOptions };
10
9
 
@@ -32,7 +31,7 @@ export class Bar extends Plot<BarOptions> {
32
31
  const { xField, yField, isPercent } = options;
33
32
  const switchedFieldOptions = { ...options, xField: yField, yField: xField };
34
33
  meta({ chart, options: switchedFieldOptions });
35
- chart.changeData(getDataWhetherPecentage(transformBarData(data), xField, yField, xField, isPercent));
34
+ chart.changeData(getDataWhetherPecentage(data, xField, yField, xField, isPercent));
36
35
  }
37
36
 
38
37
  /**
@@ -1,11 +1,11 @@
1
1
  import { Geometry } from '@antv/g2';
2
- import { each, isArray } from '@antv/util';
2
+ import { each, isArray, isNil, uniq } from '@antv/util';
3
3
  import { Params } from '../../core/adaptor';
4
4
  import { tooltip, slider, interaction, animation, theme, scale, annotation, limitInPlot } from '../../adaptor/common';
5
- import { findGeometry, transformLabel, deepAssign } from '../../utils';
5
+ import { flow, findGeometry, transformLabel, deepAssign, getAllGeometriesRecursively } from '../../utils';
6
6
  import { point, line, area } from '../../adaptor/geometries';
7
- import { flow } from '../../utils';
8
7
  import { adjustYMetaByZero } from '../../utils/data';
8
+ import { POINT_VIEW_ID } from './constants';
9
9
  import { LineOptions } from './types';
10
10
 
11
11
  /**
@@ -14,7 +14,7 @@ import { LineOptions } from './types';
14
14
  */
15
15
  function geometry(params: Params<LineOptions>): Params<LineOptions> {
16
16
  const { chart, options } = params;
17
- const { data, color, lineStyle, lineShape, point: pointMapping, area: areaMapping, seriesField } = options;
17
+ const { data, color, lineStyle, lineShape, point: pointMapping, area: areaMapping, yField, seriesField } = options;
18
18
  const pointState = pointMapping?.state;
19
19
 
20
20
  chart.data(data);
@@ -44,13 +44,23 @@ function geometry(params: Params<LineOptions>): Params<LineOptions> {
44
44
  label: undefined,
45
45
  },
46
46
  });
47
- const second = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });
47
+
48
48
  const areaParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });
49
49
 
50
50
  line(primary);
51
- point(second);
52
51
  area(areaParams);
53
52
 
53
+ const pointParams = deepAssign({}, primary, { options: { tooltip: false, state: pointState } });
54
+ if (pointMapping) {
55
+ const pointView = chart.createView({ id: POINT_VIEW_ID });
56
+ pointView.axis(false);
57
+ pointView.tooltip(false);
58
+ pointView.legend(false);
59
+ // [PERFORMANCE] 🚀 数据为空的 point 标注点都不渲染(不包括:数据为 0)
60
+ pointView.data(data.filter((d) => !isNil(d[yField])));
61
+ point({ ...pointParams, chart: pointView });
62
+ }
63
+
54
64
  return params;
55
65
  }
56
66
 
@@ -60,7 +70,21 @@ function geometry(params: Params<LineOptions>): Params<LineOptions> {
60
70
  */
61
71
  export function meta(params: Params<LineOptions>): Params<LineOptions> {
62
72
  const { options } = params;
63
- const { xAxis, yAxis, xField, yField, data } = options;
73
+ const { xAxis, yAxis, xField, yField, data, seriesField } = options;
74
+ const defaultMeta = {
75
+ [xField]: {
76
+ type: 'cat',
77
+ sync: true,
78
+ values: uniq(data.map((d) => d[xField])),
79
+ },
80
+ [yField]: {
81
+ ...adjustYMetaByZero(data, yField),
82
+ sync: true,
83
+ },
84
+ };
85
+ if (seriesField) {
86
+ defaultMeta[seriesField] = { sync: true };
87
+ }
64
88
 
65
89
  return flow(
66
90
  scale(
@@ -68,12 +92,7 @@ export function meta(params: Params<LineOptions>): Params<LineOptions> {
68
92
  [xField]: xAxis,
69
93
  [yField]: yAxis,
70
94
  },
71
- {
72
- [xField]: {
73
- type: 'cat',
74
- },
75
- [yField]: adjustYMetaByZero(data, yField),
76
- }
95
+ defaultMeta
77
96
  )
78
97
  )(params);
79
98
  }
@@ -180,8 +199,10 @@ export function adjust(params: Params<Pick<LineOptions, 'isStack'>>): Params<any
180
199
  const { chart, options } = params;
181
200
  const { isStack } = options;
182
201
 
202
+ const geometries = getAllGeometriesRecursively(chart);
203
+
183
204
  if (isStack) {
184
- each(chart.geometries, (g: Geometry) => {
205
+ each(geometries, (g: Geometry) => {
185
206
  g.adjust('stack');
186
207
  });
187
208
  }
@@ -1,10 +1,14 @@
1
1
  import { Plot } from '../../core/plot';
2
2
  import { deepAssign } from '../../utils';
3
3
 
4
+ /** point 标注点视图 */
5
+ export const POINT_VIEW_ID = 'point-view';
6
+
4
7
  /**
5
8
  * 折线图默认配置项
6
9
  */
7
10
  export const DEFAULT_OPTIONS = deepAssign({}, Plot.getDefaultOptions(), {
11
+ syncViewPadding: true,
8
12
  tooltip: {
9
13
  shared: true,
10
14
  showMarkers: true,
@@ -1,8 +1,10 @@
1
+ import { isNil } from '@antv/util';
1
2
  import { Plot } from '../../core/plot';
2
3
  import { Adaptor } from '../../core/adaptor';
4
+ import { findViewById } from '../../utils';
3
5
  import { LineOptions } from './types';
4
6
  import { adaptor, meta } from './adaptor';
5
- import { DEFAULT_OPTIONS } from './constants';
7
+ import { DEFAULT_OPTIONS, POINT_VIEW_ID } from './constants';
6
8
  import './interactions';
7
9
 
8
10
  export type { LineOptions };
@@ -26,8 +28,13 @@ export class Line extends Plot<LineOptions> {
26
28
  public changeData(data: LineOptions['data']) {
27
29
  this.updateOption({ data });
28
30
  const { chart, options } = this;
31
+ const { yField } = options;
29
32
  meta({ chart, options });
30
33
  this.chart.changeData(data);
34
+ const pointView = findViewById(this.chart, POINT_VIEW_ID);
35
+ if (pointView) {
36
+ pointView.changeData(data.filter((d) => !isNil(d[yField])));
37
+ }
31
38
  }
32
39
 
33
40
  /**
@@ -1,5 +1,6 @@
1
1
  import { each, findIndex } from '@antv/util';
2
- import { InteractionAction, View, Geometry } from '@antv/g2';
2
+ import { InteractionAction, View } from '@antv/g2';
3
+ import { findGeometry } from '../../../utils';
3
4
 
4
5
  export class MarkerActiveAction extends InteractionAction {
5
6
  public active() {
@@ -8,23 +9,19 @@ export class MarkerActiveAction extends InteractionAction {
8
9
  if (evt.data) {
9
10
  // items: 数组对象,当前 tooltip 显示的每条内容
10
11
  const { items } = evt.data;
11
- const points = view.geometries.filter((geom) => geom.type === 'point');
12
- each(points, (point: Geometry) => {
13
- each(point.elements, (element) => {
14
- const active = findIndex(items, (item) => (item as any).data === element.data) !== -1;
15
- element.setState('active', active);
16
- });
12
+ const point = findGeometry(view, 'point');
13
+ each(point.elements, (element) => {
14
+ const active = findIndex(items, (item) => (item as any).data === element.data) !== -1;
15
+ element.setState('active', active);
17
16
  });
18
17
  }
19
18
  }
20
19
 
21
20
  public reset() {
22
21
  const view = this.getView();
23
- const points = view.geometries.filter((geom) => geom.type === 'point');
24
- each(points, (point: Geometry) => {
25
- each(point.elements, (element) => {
26
- element.setState('active', false);
27
- });
22
+ const point = findGeometry(view, 'point');
23
+ each(point.elements, (element) => {
24
+ element.setState('active', false);
28
25
  });
29
26
  }
30
27