@antv/g2plot 2.3.40 → 2.4.0

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 (62) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.en-US.md +0 -1
  3. package/README.md +0 -1
  4. package/dist/g2plot.min.js +4 -4
  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 +1 -1
  9. package/esm/index.js +1 -1
  10. package/esm/index.js.map +1 -1
  11. package/esm/plots/bar/adaptor.d.ts +7 -2
  12. package/esm/plots/bar/adaptor.js +72 -25
  13. package/esm/plots/bar/adaptor.js.map +1 -1
  14. package/esm/plots/bar/index.js +1 -2
  15. package/esm/plots/bar/index.js.map +1 -1
  16. package/esm/plots/sunburst/adaptor.js +1 -11
  17. package/esm/plots/sunburst/adaptor.js.map +1 -1
  18. package/esm/plots/sunburst/constant.js +1 -0
  19. package/esm/plots/sunburst/constant.js.map +1 -1
  20. package/esm/plots/sunburst/types.d.ts +1 -1
  21. package/esm/plots/sunburst/types.js.map +1 -1
  22. package/esm/plots/venn/types.d.ts +1 -1
  23. package/esm/plots/venn/types.js.map +1 -1
  24. package/esm/utils/data.js +2 -0
  25. package/esm/utils/data.js.map +1 -1
  26. package/lib/adaptor/conversion-tag.js +3 -3
  27. package/lib/adaptor/conversion-tag.js.map +1 -1
  28. package/lib/index.d.ts +1 -1
  29. package/lib/index.js +1 -1
  30. package/lib/index.js.map +1 -1
  31. package/lib/plots/bar/adaptor.d.ts +7 -2
  32. package/lib/plots/bar/adaptor.js +74 -26
  33. package/lib/plots/bar/adaptor.js.map +1 -1
  34. package/lib/plots/bar/index.js +1 -2
  35. package/lib/plots/bar/index.js.map +1 -1
  36. package/lib/plots/sunburst/adaptor.js +1 -11
  37. package/lib/plots/sunburst/adaptor.js.map +1 -1
  38. package/lib/plots/sunburst/constant.js +1 -0
  39. package/lib/plots/sunburst/constant.js.map +1 -1
  40. package/lib/plots/sunburst/types.d.ts +1 -1
  41. package/lib/plots/sunburst/types.js.map +1 -1
  42. package/lib/plots/venn/types.d.ts +1 -1
  43. package/lib/plots/venn/types.js.map +1 -1
  44. package/lib/utils/data.js +2 -0
  45. package/lib/utils/data.js.map +1 -1
  46. package/package.json +6 -5
  47. package/src/adaptor/conversion-tag.ts +3 -3
  48. package/src/index.ts +1 -1
  49. package/src/plots/bar/adaptor.ts +90 -47
  50. package/src/plots/bar/index.ts +1 -2
  51. package/src/plots/sunburst/adaptor.ts +9 -13
  52. package/src/plots/sunburst/constant.ts +1 -0
  53. package/src/plots/sunburst/types.ts +1 -1
  54. package/src/plots/venn/types.ts +1 -1
  55. package/src/utils/data.ts +1 -0
  56. package/esm/plots/bar/utils.d.ts +0 -6
  57. package/esm/plots/bar/utils.js +0 -8
  58. package/esm/plots/bar/utils.js.map +0 -1
  59. package/lib/plots/bar/utils.d.ts +0 -6
  60. package/lib/plots/bar/utils.js +0 -12
  61. package/lib/plots/bar/utils.js.map +0 -1
  62. package/src/plots/bar/utils.ts +0 -9
@@ -36,8 +36,8 @@ function renderArrowTag(config, elemPrev, elemNext) {
36
36
  var view = config.view, geometry = config.geometry, group = config.group, options = config.options, horizontal = config.horizontal;
37
37
  var offset = options.offset, size = options.size, arrow = options.arrow;
38
38
  var coordinate = view.getCoordinate();
39
- var pointPrev = parsePoints(coordinate, elemPrev)[horizontal ? 3 : 0];
40
- var pointNext = parsePoints(coordinate, elemNext)[horizontal ? 0 : 3];
39
+ var pointPrev = parsePoints(coordinate, elemPrev)[3];
40
+ var pointNext = parsePoints(coordinate, elemNext)[0];
41
41
  var totalHeight = pointNext.y - pointPrev.y;
42
42
  var totalWidth = pointNext.x - pointPrev.x;
43
43
  if (typeof arrow === 'boolean') {
@@ -166,7 +166,7 @@ function conversionTag(field, horizontal, disabled) {
166
166
  horizontal: horizontal,
167
167
  options: getConversionTagOptionsWithDefaults(conversionTag, horizontal),
168
168
  };
169
- var elements = horizontal ? interval.elements : interval.elements.slice().reverse();
169
+ var elements = interval.elements;
170
170
  util_1.each(elements, function (elem, idx) {
171
171
  if (idx > 0) {
172
172
  renderTag(config, elements[idx - 1], elem);
@@ -1 +1 @@
1
- {"version":3,"file":"conversion-tag.js","sourceRoot":"","sources":["../../src/adaptor/conversion-tag.ts"],"names":[],"mappings":";;;;AAAA,mCAAuD;AACvD,+BAA6F;AAE7F,kCAAsC;AACtC,kDAA6D;AAqD7D,SAAS,mCAAmC,CAAC,OAA6B,EAAE,UAAmB;IAC7F,OAAO,kBAAU,CACf;QACE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;QAC1B,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;QAC5B,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3B,KAAK,EAAE,OAAO,CAAC,KAAK,KAAK,KAAK,IAAI;YAChC,QAAQ,EAAE,EAAE;YACZ,KAAK,EAAE;gBACL,IAAI,EAAE,qBAAqB;aAC5B;SACF;QACD,IAAI,EAAE,OAAO,CAAC,IAAI,KAAK,KAAK,IAAI;YAC9B,KAAK,EAAE;gBACL,QAAQ,EAAE,EAAE;gBACZ,IAAI,EAAE,qBAAqB;gBAC3B,SAAS,EAAE,QAAQ;gBACnB,YAAY,EAAE,QAAQ;aACvB;YACD,SAAS,EAAE,mCAAsB;SAClC;KACF,EACD,OAAO,CACR,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,UAAsB,EAAE,OAAgB;IAC3D,aAAa;IACb,OAAO,UAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAC,KAAK,IAAK,OAAA,UAAU,CAAC,YAAY,CAAC,KAAK,CAAC,EAA9B,CAA8B,CAAC,CAAC;AACnF,CAAC;AAED,SAA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GAAG,GAAG,CAAC,EAAE;4BACX,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;yBAC5C;oBACH,CAAC,CAAC,CAAC;gBACL,CAAC;aACF,CAAC,CAAC;SACJ;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AA5CD,sCA4CC","sourcesContent":["import { map, find, each, isObject } from '@antv/util';\nimport { Coordinate, IGroup, ShapeAttrs, Element, Geometry, View, getTheme } from '@antv/g2';\nimport { Params } from '../core/adaptor';\nimport { deepAssign } from '../utils';\nimport { conversionTagFormatter } from '../utils/conversion';\nimport { Options } from '../types';\n\n/** 转化率组件配置选项 */\nexport interface ConversionTagOptions {\n /** tag 高度 */\n size?: number;\n /** tag 对柱子间距 */\n spacing?: number;\n /** tag 距离轴线距离 */\n offset?: number;\n /** 箭头形状配置 */\n arrow?:\n | {\n /** 箭头宽度 */\n headSize?: number;\n /** 箭头样式 */\n style?: ShapeAttrs;\n }\n | false;\n /** 文本配置 */\n text?:\n | {\n /** 文字大小 */\n size?: number;\n /** 文字样式 */\n style?: ShapeAttrs;\n /** 文本格式化 */\n formatter?: (prev: number, next: number) => string;\n }\n | false;\n}\n\nexport interface OptionWithConversionTag {\n conversionTag?: ConversionTagOptions | false;\n}\n\n/** 控制转化率组件绘制的选项 */\ntype TagRenderConfig = {\n /** 所在的 View */\n view: View;\n /** 所属的 geometry */\n geometry: Geometry;\n /** 转化率组件的 group */\n group: IGroup;\n /** 转化率配置 */\n options: ConversionTagOptions;\n /** 用于转化率计算的字段 */\n field: string;\n /** 水平/垂直 */\n horizontal: boolean;\n};\n\nfunction getConversionTagOptionsWithDefaults(options: ConversionTagOptions, horizontal: boolean): ConversionTagOptions {\n return deepAssign(\n {\n size: horizontal ? 32 : 80,\n spacing: horizontal ? 8 : 12,\n offset: horizontal ? 32 : 0,\n arrow: options.arrow !== false && {\n headSize: 12,\n style: {\n fill: 'rgba(0, 0, 0, 0.05)',\n },\n },\n text: options.text !== false && {\n style: {\n fontSize: 12,\n fill: 'rgba(0, 0, 0, 0.85)',\n textAlign: 'center',\n textBaseline: 'middle',\n },\n formatter: conversionTagFormatter,\n },\n },\n options\n );\n}\n\nfunction parsePoints(coordinate: Coordinate, element: Element): { x: number; y: number }[] {\n // @ts-ignore\n return map(element.getModel().points, (point) => coordinate.convertPoint(point));\n}\n\nfunction renderArrowTag(config: TagRenderConfig, elemPrev: Element, elemNext: Element): void {\n const { view, geometry, group, options, horizontal } = config;\n const { offset, size, arrow } = options;\n const coordinate = view.getCoordinate();\n const pointPrev = parsePoints(coordinate, elemPrev)[horizontal ? 3 : 0];\n const pointNext = parsePoints(coordinate, elemNext)[horizontal ? 0 : 3];\n const totalHeight = pointNext.y - pointPrev.y;\n const totalWidth = pointNext.x - pointPrev.x;\n\n if (typeof arrow === 'boolean') {\n return;\n }\n const { headSize } = arrow;\n let spacing = options.spacing;\n let points;\n\n if (horizontal) {\n if ((totalWidth - headSize) / 2 < spacing) {\n // 当柱间距不足容纳箭头尖与间隔时,画三角并挤占间隔\n spacing = Math.max(1, (totalWidth - headSize) / 2);\n points = [\n [pointPrev.x + spacing, pointPrev.y - offset],\n [pointPrev.x + spacing, pointPrev.y - offset - size],\n [pointNext.x - spacing, pointNext.y - offset - size / 2],\n ];\n } else {\n // 当柱间距足够时,画完整图形并留出间隔。\n points = [\n [pointPrev.x + spacing, pointPrev.y - offset],\n [pointPrev.x + spacing, pointPrev.y - offset - size],\n [pointNext.x - spacing - headSize, pointNext.y - offset - size],\n [pointNext.x - spacing, pointNext.y - offset - size / 2],\n [pointNext.x - spacing - headSize, pointNext.y - offset],\n ];\n }\n } else {\n if ((totalHeight - headSize) / 2 < spacing) {\n // 当柱间距不足容纳箭头尖与间隔时,画三角并挤占间隔\n spacing = Math.max(1, (totalHeight - headSize) / 2);\n points = [\n [pointPrev.x + offset, pointPrev.y + spacing],\n [pointPrev.x + offset + size, pointPrev.y + spacing],\n [pointNext.x + offset + size / 2, pointNext.y - spacing],\n ];\n } else {\n // 当柱间距足够时,画完整图形并留出间隔。\n points = [\n [pointPrev.x + offset, pointPrev.y + spacing],\n [pointPrev.x + offset + size, pointPrev.y + spacing],\n [pointNext.x + offset + size, pointNext.y - spacing - headSize],\n [pointNext.x + offset + size / 2, pointNext.y - spacing],\n [pointNext.x + offset, pointNext.y - spacing - headSize],\n ];\n }\n }\n\n group.addShape('polygon', {\n id: `${view.id}-conversion-tag-arrow-${geometry.getElementId(elemPrev.getModel().mappingData)}`,\n name: 'conversion-tag-arrow',\n origin: {\n element: elemPrev,\n nextElement: elemNext,\n },\n attrs: {\n ...(arrow.style || {}),\n points,\n },\n });\n}\n\nfunction renderTextTag(config: TagRenderConfig, elemPrev: Element, elemNext: Element): void {\n const { view, geometry, group, options, field, horizontal } = config;\n const { offset, size } = options;\n if (typeof options.text === 'boolean') {\n return;\n }\n const coordinate = view.getCoordinate();\n const text = options.text?.formatter && options.text?.formatter(elemPrev.getData()[field], elemNext.getData()[field]);\n\n const pointPrev = parsePoints(coordinate, elemPrev)[horizontal ? 3 : 0];\n const pointNext = parsePoints(coordinate, elemNext)[horizontal ? 0 : 3];\n\n const textShape = group.addShape('text', {\n id: `${view.id}-conversion-tag-text-${geometry.getElementId(elemPrev.getModel().mappingData)}`,\n name: 'conversion-tag-text',\n origin: {\n element: elemPrev,\n nextElement: elemNext,\n },\n attrs: {\n ...(options.text?.style || {}),\n text,\n x: horizontal ? (pointPrev.x + pointNext.x) / 2 : pointPrev.x + offset + size / 2,\n y: horizontal ? pointPrev.y - offset - size / 2 : (pointPrev.y + pointNext.y) / 2,\n },\n });\n\n if (horizontal) {\n const totalWidth = pointNext.x - pointPrev.x;\n const { width: textWidth } = textShape.getBBox();\n if (textWidth > totalWidth) {\n const cWidth = textWidth / text.length;\n const cEnd = Math.max(1, Math.ceil(totalWidth / cWidth) - 1);\n const textAdjusted = `${text.slice(0, cEnd)}...`;\n textShape.attr('text', textAdjusted);\n }\n }\n}\n\nfunction renderTag(options: TagRenderConfig, elemPrev: Element, elemNext: Element): void {\n renderArrowTag(options, elemPrev, elemNext);\n renderTextTag(options, elemPrev, elemNext);\n}\n\n/**\n * 返回支持转化率组件的 adaptor,适用于柱形图/条形图\n * @param field 用户转化率计算的字段\n * @param horizontal 是否水平方向的转化率\n * @param disabled 是否禁用\n */\nexport function conversionTag<O extends OptionWithConversionTag & Options>(\n field: string,\n horizontal = true,\n disabled = false\n) {\n return function (params: Params<O>): Params<O> {\n const { options, chart } = params;\n const { conversionTag, theme } = options;\n\n if (conversionTag && !disabled) {\n // 有转化率组件时,柱子宽度占比自动为 1/3\n chart.theme(\n deepAssign({}, isObject(theme) ? theme : getTheme(theme), {\n columnWidthRatio: 1 / 3,\n })\n );\n // 使用 shape annotation 绘制转化率组件\n chart.annotation().shape({\n render: (container, view) => {\n const group = container.addGroup({\n id: `${chart.id}-conversion-tag-group`,\n name: 'conversion-tag-group',\n });\n const interval = find(chart.geometries, (geom: Geometry) => geom.type === 'interval');\n const config: TagRenderConfig = {\n view,\n geometry: interval,\n group,\n field,\n horizontal,\n options: getConversionTagOptionsWithDefaults(conversionTag, horizontal),\n };\n const elements = horizontal ? interval.elements : interval.elements.slice().reverse();\n each(elements, (elem: Element, idx: number) => {\n if (idx > 0) {\n renderTag(config, elements[idx - 1], elem);\n }\n });\n },\n });\n }\n\n return params;\n };\n}\n"]}
1
+ {"version":3,"file":"conversion-tag.js","sourceRoot":"","sources":["../../src/adaptor/conversion-tag.ts"],"names":[],"mappings":";;;;AAAA,mCAAuD;AACvD,+BAA6F;AAE7F,kCAAsC;AACtC,kDAA6D;AAqD7D,SAAS,mCAAmC,CAAC,OAA6B,EAAE,UAAmB;IAC7F,OAAO,kBAAU,CACf;QACE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;QAC1B,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,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;wBACtC,IAAI,EAAE,sBAAsB;qBAC7B,CAAC,CAAC;oBACH,IAAM,QAAQ,GAAG,WAAI,CAAC,KAAK,CAAC,UAAU,EAAE,UAAC,IAAc,IAAK,OAAA,IAAI,CAAC,IAAI,KAAK,UAAU,EAAxB,CAAwB,CAAC,CAAC;oBACtF,IAAM,MAAM,GAAoB;wBAC9B,IAAI,MAAA;wBACJ,QAAQ,EAAE,QAAQ;wBAClB,KAAK,OAAA;wBACL,KAAK,OAAA;wBACL,UAAU,YAAA;wBACV,OAAO,EAAE,mCAAmC,CAAC,aAAa,EAAE,UAAU,CAAC;qBACxE,CAAC;oBACF,IAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;oBACnC,WAAI,CAAC,QAAQ,EAAE,UAAC,IAAa,EAAE,GAAW;wBACxC,IAAI,GAAG,GAAG,CAAC,EAAE;4BACX,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;yBAC5C;oBACH,CAAC,CAAC,CAAC;gBACL,CAAC;aACF,CAAC,CAAC;SACJ;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AA5CD,sCA4CC","sourcesContent":["import { map, find, each, isObject } from '@antv/util';\nimport { Coordinate, IGroup, ShapeAttrs, Element, Geometry, View, getTheme } from '@antv/g2';\nimport { Params } from '../core/adaptor';\nimport { deepAssign } from '../utils';\nimport { conversionTagFormatter } from '../utils/conversion';\nimport { Options } from '../types';\n\n/** 转化率组件配置选项 */\nexport interface ConversionTagOptions {\n /** tag 高度 */\n size?: number;\n /** tag 对柱子间距 */\n spacing?: number;\n /** tag 距离轴线距离 */\n offset?: number;\n /** 箭头形状配置 */\n arrow?:\n | {\n /** 箭头宽度 */\n headSize?: number;\n /** 箭头样式 */\n style?: ShapeAttrs;\n }\n | false;\n /** 文本配置 */\n text?:\n | {\n /** 文字大小 */\n size?: number;\n /** 文字样式 */\n style?: ShapeAttrs;\n /** 文本格式化 */\n formatter?: (prev: number, next: number) => string;\n }\n | false;\n}\n\nexport interface OptionWithConversionTag {\n conversionTag?: ConversionTagOptions | false;\n}\n\n/** 控制转化率组件绘制的选项 */\ntype TagRenderConfig = {\n /** 所在的 View */\n view: View;\n /** 所属的 geometry */\n geometry: Geometry;\n /** 转化率组件的 group */\n group: IGroup;\n /** 转化率配置 */\n options: ConversionTagOptions;\n /** 用于转化率计算的字段 */\n field: string;\n /** 水平/垂直 */\n horizontal: boolean;\n};\n\nfunction getConversionTagOptionsWithDefaults(options: ConversionTagOptions, horizontal: boolean): ConversionTagOptions {\n return deepAssign(\n {\n size: horizontal ? 32 : 80,\n spacing: horizontal ? 8 : 12,\n offset: horizontal ? 32 : 0,\n arrow: options.arrow !== false && {\n headSize: 12,\n style: {\n fill: 'rgba(0, 0, 0, 0.05)',\n },\n },\n text: options.text !== false && {\n style: {\n fontSize: 12,\n fill: 'rgba(0, 0, 0, 0.85)',\n textAlign: 'center',\n textBaseline: 'middle',\n },\n formatter: conversionTagFormatter,\n },\n },\n options\n );\n}\n\nfunction parsePoints(coordinate: Coordinate, element: Element): { x: number; y: number }[] {\n // @ts-ignore\n return map(element.getModel().points, (point) => coordinate.convertPoint(point));\n}\n\nfunction renderArrowTag(config: TagRenderConfig, elemPrev: Element, elemNext: Element): void {\n const { view, geometry, group, options, horizontal } = config;\n const { offset, size, arrow } = options;\n const coordinate = view.getCoordinate();\n const pointPrev = parsePoints(coordinate, elemPrev)[3];\n const pointNext = parsePoints(coordinate, elemNext)[0];\n const totalHeight = pointNext.y - pointPrev.y;\n const totalWidth = pointNext.x - pointPrev.x;\n\n if (typeof arrow === 'boolean') {\n return;\n }\n const { headSize } = arrow;\n let spacing = options.spacing;\n let points;\n\n if (horizontal) {\n if ((totalWidth - headSize) / 2 < spacing) {\n // 当柱间距不足容纳箭头尖与间隔时,画三角并挤占间隔\n spacing = Math.max(1, (totalWidth - headSize) / 2);\n points = [\n [pointPrev.x + spacing, pointPrev.y - offset],\n [pointPrev.x + spacing, pointPrev.y - offset - size],\n [pointNext.x - spacing, pointNext.y - offset - size / 2],\n ];\n } else {\n // 当柱间距足够时,画完整图形并留出间隔。\n points = [\n [pointPrev.x + spacing, pointPrev.y - offset],\n [pointPrev.x + spacing, pointPrev.y - offset - size],\n [pointNext.x - spacing - headSize, pointNext.y - offset - size],\n [pointNext.x - spacing, pointNext.y - offset - size / 2],\n [pointNext.x - spacing - headSize, pointNext.y - offset],\n ];\n }\n } else {\n if ((totalHeight - headSize) / 2 < spacing) {\n // 当柱间距不足容纳箭头尖与间隔时,画三角并挤占间隔\n spacing = Math.max(1, (totalHeight - headSize) / 2);\n points = [\n [pointPrev.x + offset, pointPrev.y + spacing],\n [pointPrev.x + offset + size, pointPrev.y + spacing],\n [pointNext.x + offset + size / 2, pointNext.y - spacing],\n ];\n } else {\n // 当柱间距足够时,画完整图形并留出间隔。\n points = [\n [pointPrev.x + offset, pointPrev.y + spacing],\n [pointPrev.x + offset + size, pointPrev.y + spacing],\n [pointNext.x + offset + size, pointNext.y - spacing - headSize],\n [pointNext.x + offset + size / 2, pointNext.y - spacing],\n [pointNext.x + offset, pointNext.y - spacing - headSize],\n ];\n }\n }\n\n group.addShape('polygon', {\n id: `${view.id}-conversion-tag-arrow-${geometry.getElementId(elemPrev.getModel().mappingData)}`,\n name: 'conversion-tag-arrow',\n origin: {\n element: elemPrev,\n nextElement: elemNext,\n },\n attrs: {\n ...(arrow.style || {}),\n points,\n },\n });\n}\n\nfunction renderTextTag(config: TagRenderConfig, elemPrev: Element, elemNext: Element): void {\n const { view, geometry, group, options, field, horizontal } = config;\n const { offset, size } = options;\n if (typeof options.text === 'boolean') {\n return;\n }\n const coordinate = view.getCoordinate();\n const text = options.text?.formatter && options.text?.formatter(elemPrev.getData()[field], elemNext.getData()[field]);\n\n const pointPrev = parsePoints(coordinate, elemPrev)[horizontal ? 3 : 0];\n const pointNext = parsePoints(coordinate, elemNext)[horizontal ? 0 : 3];\n\n const textShape = group.addShape('text', {\n id: `${view.id}-conversion-tag-text-${geometry.getElementId(elemPrev.getModel().mappingData)}`,\n name: 'conversion-tag-text',\n origin: {\n element: elemPrev,\n nextElement: elemNext,\n },\n attrs: {\n ...(options.text?.style || {}),\n text,\n x: horizontal ? (pointPrev.x + pointNext.x) / 2 : pointPrev.x + offset + size / 2,\n y: horizontal ? pointPrev.y - offset - size / 2 : (pointPrev.y + pointNext.y) / 2,\n },\n });\n\n if (horizontal) {\n const totalWidth = pointNext.x - pointPrev.x;\n const { width: textWidth } = textShape.getBBox();\n if (textWidth > totalWidth) {\n const cWidth = textWidth / text.length;\n const cEnd = Math.max(1, Math.ceil(totalWidth / cWidth) - 1);\n const textAdjusted = `${text.slice(0, cEnd)}...`;\n textShape.attr('text', textAdjusted);\n }\n }\n}\n\nfunction renderTag(options: TagRenderConfig, elemPrev: Element, elemNext: Element): void {\n renderArrowTag(options, elemPrev, elemNext);\n renderTextTag(options, elemPrev, elemNext);\n}\n\n/**\n * 返回支持转化率组件的 adaptor,适用于柱形图/条形图\n * @param field 用户转化率计算的字段\n * @param horizontal 是否水平方向的转化率\n * @param disabled 是否禁用\n */\nexport function conversionTag<O extends OptionWithConversionTag & Options>(\n field: string,\n horizontal = true,\n disabled = false\n) {\n return function (params: Params<O>): Params<O> {\n const { options, chart } = params;\n const { conversionTag, theme } = options;\n\n if (conversionTag && !disabled) {\n // 有转化率组件时,柱子宽度占比自动为 1/3\n chart.theme(\n deepAssign({}, isObject(theme) ? theme : getTheme(theme), {\n columnWidthRatio: 1 / 3,\n })\n );\n // 使用 shape annotation 绘制转化率组件\n chart.annotation().shape({\n render: (container, view) => {\n const group = container.addGroup({\n id: `${chart.id}-conversion-tag-group`,\n name: 'conversion-tag-group',\n });\n const interval = find(chart.geometries, (geom: Geometry) => geom.type === 'interval');\n const config: TagRenderConfig = {\n view,\n geometry: interval,\n group,\n field,\n horizontal,\n options: getConversionTagOptionsWithDefaults(conversionTag, horizontal),\n };\n const elements = interval.elements;\n each(elements, (elem: Element, idx: number) => {\n if (idx > 0) {\n renderTag(config, elements[idx - 1], elem);\n }\n });\n },\n });\n }\n\n return params;\n };\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const version = "2.3.40";
1
+ export declare const version = "2.4.0";
2
2
  import * as G2 from '@antv/g2';
3
3
  export { G2 };
4
4
  import { registerLocale } from './core/locale';
package/lib/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.adaptors = exports.registerLocale = exports.G2 = exports.version = void 0;
4
4
  var tslib_1 = require("tslib");
5
- exports.version = '2.3.40';
5
+ exports.version = '2.4.0';
6
6
  // G2 自定义能力透出
7
7
  var G2 = tslib_1.__importStar(require("@antv/g2"));
8
8
  exports.G2 = G2;
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAa,QAAA,OAAO,GAAG,QAAQ,CAAC;AAEhC,aAAa;AACb,mDAA+B;AACtB,gBAAE;AAEX,QAAQ;AACR,wCAA+C;AAOtC,+FAPA,uBAAc,OAOA;AANvB,yCAA+C;AAC/C,yCAA+C;AAC/C,8BAA8B;AAC9B,uBAAc,CAAC,OAAO,EAAE,oBAAY,CAAC,CAAC;AACtC,uBAAc,CAAC,OAAO,EAAE,oBAAY,CAAC,CAAC;AAItC,WAAW;AACX,wCAA0C;AAAjC,mGAAA,SAAS,OAAA;AAElB,uBAAuB;AACvB,oCAAmC;AAA1B,4FAAA,IAAI,OAAA;AAKb,SAAS;AACT,kDAAwB;AAExB,2DAA2D;AAC3D,qCAAoC;AAA3B,4FAAA,IAAI,OAAA;AAGb,2DAA2D;AAC3D,qCAAoC;AAA3B,4FAAA,IAAI,OAAA;AAGb,uDAAuD;AACvD,yCAAwC;AAA/B,gGAAA,MAAM,OAAA;AAGf,yDAAyD;AACzD,mCAAkC;AAAzB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AAoD;AACpD,6BAA4B;AAAnB,0FAAA,GAAG,OAAA","sourcesContent":["export const version = '2.3.40';\n\n// G2 自定义能力透出\nimport * as G2 from '@antv/g2';\nexport { G2 };\n\n// 国际化处理\nimport { registerLocale } from './core/locale';\nimport { EN_US_LOCALE } from './locales/en_US';\nimport { ZH_CN_LOCALE } from './locales/zh_CN';\n/** default locale register */\nregisterLocale('en-US', EN_US_LOCALE);\nregisterLocale('zh-CN', ZH_CN_LOCALE);\n/** 透出 国际化 工具函数,便于使用 */\nexport { registerLocale };\n\n/** 全局变量 */\nexport { setGlobal } from './core/global';\n\n/** G2Plot 的 Plot 基类 */\nexport { Plot } from './core/plot';\n\n/** Adaptor 及其参数的类型定义 */\nexport type { Adaptor, Params } from './core/adaptor';\n\n// 类型定义导出\nexport * from './types';\n\n// 折线图及类型定义 | author by [hustcc](https://github.com/hustcc)\nexport { Line } from './plots/line';\nexport type { LineOptions } from './plots/line';\n\n// 面积图及类型定义 | author by [hustcc](https://github.com/hustcc)\nexport { Area } from './plots/area';\nexport type { AreaOptions } from './plots/area';\n\n// 柱形图及类型定义 | author by [zqlu](https://github.com/zqlu)\nexport { Column } from './plots/column';\nexport type { ColumnOptions } from './plots/column';\n\n// 条形图及类型定义 | author by [BBSQQ](https://github.com/BBSQQ)\nexport { Bar } from './plots/bar';\nexport type { BarOptions } from './plots/bar';\n\n// 饼图及类型定义 | author by [visiky](https://github.com/visiky)\nexport { Pie } from './plots/pie';\nexport type { PieOptions } from './plots/pie';\n\n// 玫瑰图及类型定义 | author by [zhangzhonghe](https://github.com/zhangzhonghe)\nexport { Rose } from './plots/rose';\nexport type { RoseOptions } from './plots/rose';\n\n// 词云图及类型定义 | author by [zhangzhonghe](https://github.com/zhangzhonghe)\nexport { WordCloud } from './plots/word-cloud';\nexport type { WordCloudOptions } from './plots/word-cloud';\n\n// 散点图及类型定义 | author by [lxfu1](https://github.com/lxfu1)\nexport { Scatter } from './plots/scatter';\nexport type { ScatterOptions } from './plots/scatter';\n\n// 雷达图及类型定义 | author by [visiky](https://github.com/visiky)\nexport { Radar } from './plots/radar';\nexport type { RadarOptions } from './plots/radar';\n\n// 混合图形 | author by [liuzhenying](https://github.com/liuzhenying)\nexport { DualAxes } from './plots/dual-axes';\nexport type { DualAxesOptions } from './plots/dual-axes';\n\n// 迷你折线图及类型定义 | author by [connono](https://github.com/connono)\nexport { TinyLine } from './plots/tiny-line';\nexport type { TinyLineOptions } from './plots/tiny-line';\n\n// 迷你柱形图及类型定义 | author by [connono](https://github.com/connono)\nexport { TinyColumn } from './plots/tiny-column';\nexport type { TinyColumnOptions } from './plots/tiny-column';\n\n// 迷你面积图及类型定义 | author by [connono](https://github.com/connono)\nexport { TinyArea } from './plots/tiny-area';\nexport type { TinyAreaOptions } from './plots/tiny-area';\n\n// 直方图及类型定义 | author by [arcsin1](https://github.com/arcsin1), [visiky](https://github.com/visiky)\nexport { Histogram } from './plots/histogram';\nexport type { HistogramOptions } from './plots/histogram';\n\n// 进度图及类型定义 | author by [connono](https://github.com/connono)\nexport { Progress } from './plots/progress';\nexport type { ProgressOptions } from './plots/progress';\n\n// 环形进度图及类型定义 | author by [connono](https://github.com/connono)\nexport { RingProgress } from './plots/ring-progress';\nexport type { RingProgressOptions } from './plots/ring-progress';\n\n// 热力图及类型定义 | author by [jiazhewang](https://github.com/jiazhewang)\nexport { Heatmap } from './plots/heatmap';\nexport type { HeatmapOptions } from './plots/heatmap';\n\n// 箱线图及类型定义 | author by [BBSQQ](https://github.com/BBSQQ), [visiky](https://github.com/visiky)\nexport { Box } from './plots/box';\nexport type { BoxOptions } from './plots/box';\n\n// 小提琴图及类型定义 | author by [YiSiWang](https://github.com/YiSiWang), [visiky](https://github.com/visiky)\nexport { Violin } from './plots/violin';\nexport type { ViolinOptions } from './plots/violin';\n\n// 韦恩图及类型定义 | author by [visiky](https://github.com/visiky)\nexport { Venn } from './plots/venn';\nexport type { VennOptions } from './plots/venn';\n\n// K线图及类型定义 | author by [jhwong](https://github.com/jinhuiWong), [visiky](https://github.com/visiky)\nexport { Stock } from './plots/stock';\nexport type { StockOptions } from './plots/stock';\n\n// 漏斗图及类型定义\nexport { Funnel, FUNNEL_CONVERSATION_FIELD } from './plots/funnel';\nexport type { FunnelOptions } from './plots/funnel';\n\n// 水波图及类型定义 | author by [CarisL](https://github.com/CarisL), [hustcc](https://github.com/hustcc), [pearmini](https://github.com/pearmini)\nexport { Liquid } from './plots/liquid';\nexport type { LiquidOptions } from './plots/liquid';\n\n// 子弹图及类型定义 | author by [arcsin1](https://github.com/arcsin1)\nexport { Bullet } from './plots/bullet';\nexport type { BulletOptions } from './plots/bullet';\n\n// 旭日图及类型定义 | author by [lxfu1](https://github.com/lxfu1), [visiky](https://github.com/visiky)\nexport { Sunburst } from './plots/sunburst';\nexport type { SunburstOptions } from './plots/sunburst';\n\n// 仪表盘及类型定义 | author by [hustcc](https://github.com/hustcc)\nexport { Gauge } from './plots/gauge';\nexport type { GaugeOptions } from './plots/gauge';\n\n// 瀑布图 | author by [visiky](https://github.com/visiky)\nexport { Waterfall } from './plots/waterfall';\nexport type { WaterfallOptions } from './plots/waterfall';\n\n// 玉珏图 | author by [yujs](https://github.com/yujs) | updated by [visiky](https://github.com/visiky)\nexport { RadialBar } from './plots/radial-bar';\nexport type { RadialBarOptions } from './plots/radial-bar';\n\n// 对称条形图及类型定义 | author by [arcsin1](https://github.com/arcsin1)\nexport { BidirectionalBar } from './plots/bidirectional-bar';\nexport type { BidirectionalBarOptions } from './plots/bidirectional-bar';\n\n// 矩形树图\nexport { Treemap } from './plots/treemap';\nexport type { TreemapOptions } from './plots/treemap';\n\n// 桑基图及类型定义 | author by [hustcc](https://github.com/hustcc)\nexport { Sankey } from './plots/sankey';\nexport type { SankeyOptions } from './plots/sankey';\n\n// 弦图及类型定义 | author by [MrSmallLiu](https://github.com/MrSmallLiu), [visiky](https://github.com/visiky)\nexport { Chord } from './plots/chord';\nexport type { ChordOptions } from './plots/chord';\n\n// circle-packing 及类型定义 | author by [visiky](https://github.com/visiky), [Angeli](https://github.com/Angelii)\nexport { CirclePacking } from './plots/circle-packing';\nexport type { CirclePackingOptions } from './plots/circle-packing';\n\n// 以下开放自定义图表开发的能力(目前仅仅是孵化中)\n/** 所有开放图表都使用 G2Plot.P 作为入口开发,理论上官方的所有图表都可以走 G2Plot.P 的入口(暂时不处理) */\nexport { P } from './plugin';\n\n/** 开放 getCanvasPatterng 方法 */\nexport { getCanvasPattern } from './utils/pattern';\n\n// 已经废弃,更名为 Mix\nexport { Mix as MultiView } from './plots/mix';\nexport type { MixOptions as MultiViewOptions } from './plots/mix';\n/** 开放多图层图表 (mix) */\nexport { Mix as Mix } from './plots/mix';\nexport type { MixOptions } from './plots/mix';\n\n// 分面图及类型定义 | author by [visiky](https://github.com/visiky)\nexport { Facet } from './plots/facet';\nexport type { FacetOptions } from './plots/facet';\n\n/** 开发 adaptor 可能会用到的方法或一些工具方法,不强制使用 */\nexport { flow, measureTextWidth } from './utils';\n\n/** 各个 geometry 的 adaptor,可以让开发者更快的构造图形 */\nexport { line, interval, area, point, polygon, schema } from './adaptor/geometries';\nexport type {\n LineGeometryOptions,\n IntervalGeometryOptions,\n AreaGeometryOptions,\n PointGeometryOptions,\n PolygonGeometryOptions,\n SchemaGeometryOptions,\n} from './adaptor/geometries';\n/** 开放一些通用的 adaptor 通道方法,实验阶段:不保证稳定性 */\nimport { scale, legend, tooltip, annotation, interaction, theme, animation } from './adaptor/common';\nexport const adaptors = { scale, legend, tooltip, annotation, interaction, theme, animation };\n\n/** 对于没有开发完成的图表,可以暂时先放到 Lab 下面,先做体验,稳定后放到根 export */\nexport { Lab } from './lab';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAa,QAAA,OAAO,GAAG,OAAO,CAAC;AAE/B,aAAa;AACb,mDAA+B;AACtB,gBAAE;AAEX,QAAQ;AACR,wCAA+C;AAOtC,+FAPA,uBAAc,OAOA;AANvB,yCAA+C;AAC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;AACvC,iCAAiD;AAAxC,6FAAA,IAAI,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAE/B,0CAA0C;AAC1C,mDAAoF;AAA3E,kGAAA,IAAI,OAAA;AAAE,sGAAA,QAAQ,OAAA;AAAE,kGAAA,IAAI,OAAA;AAAE,mGAAA,KAAK,OAAA;AAAE,qGAAA,OAAO,OAAA;AAAE,oGAAA,MAAM,OAAA;AASrD,uCAAuC;AACvC,2CAAqG;AACxF,QAAA,QAAQ,GAAG,EAAE,KAAK,gBAAA,EAAE,MAAM,iBAAA,EAAE,OAAO,kBAAA,EAAE,UAAU,qBAAA,EAAE,WAAW,sBAAA,EAAE,KAAK,gBAAA,EAAE,SAAS,oBAAA,EAAE,CAAC;AAE9F,oDAAoD;AACpD,6BAA4B;AAAnB,0FAAA,GAAG,OAAA","sourcesContent":["export const version = '2.4.0';\n\n// G2 自定义能力透出\nimport * as G2 from '@antv/g2';\nexport { G2 };\n\n// 国际化处理\nimport { registerLocale } from './core/locale';\nimport { EN_US_LOCALE } from './locales/en_US';\nimport { ZH_CN_LOCALE } from './locales/zh_CN';\n/** default locale register */\nregisterLocale('en-US', EN_US_LOCALE);\nregisterLocale('zh-CN', ZH_CN_LOCALE);\n/** 透出 国际化 工具函数,便于使用 */\nexport { registerLocale };\n\n/** 全局变量 */\nexport { setGlobal } from './core/global';\n\n/** G2Plot 的 Plot 基类 */\nexport { Plot } from './core/plot';\n\n/** Adaptor 及其参数的类型定义 */\nexport type { Adaptor, Params } from './core/adaptor';\n\n// 类型定义导出\nexport * from './types';\n\n// 折线图及类型定义 | author by [hustcc](https://github.com/hustcc)\nexport { Line } from './plots/line';\nexport type { LineOptions } from './plots/line';\n\n// 面积图及类型定义 | author by [hustcc](https://github.com/hustcc)\nexport { Area } from './plots/area';\nexport type { AreaOptions } from './plots/area';\n\n// 柱形图及类型定义 | author by [zqlu](https://github.com/zqlu)\nexport { Column } from './plots/column';\nexport type { ColumnOptions } from './plots/column';\n\n// 条形图及类型定义 | author by [BBSQQ](https://github.com/BBSQQ)\nexport { Bar } from './plots/bar';\nexport type { BarOptions } from './plots/bar';\n\n// 饼图及类型定义 | author by [visiky](https://github.com/visiky)\nexport { Pie } from './plots/pie';\nexport type { PieOptions } from './plots/pie';\n\n// 玫瑰图及类型定义 | author by [zhangzhonghe](https://github.com/zhangzhonghe)\nexport { Rose } from './plots/rose';\nexport type { RoseOptions } from './plots/rose';\n\n// 词云图及类型定义 | author by [zhangzhonghe](https://github.com/zhangzhonghe)\nexport { WordCloud } from './plots/word-cloud';\nexport type { WordCloudOptions } from './plots/word-cloud';\n\n// 散点图及类型定义 | author by [lxfu1](https://github.com/lxfu1)\nexport { Scatter } from './plots/scatter';\nexport type { ScatterOptions } from './plots/scatter';\n\n// 雷达图及类型定义 | author by [visiky](https://github.com/visiky)\nexport { Radar } from './plots/radar';\nexport type { RadarOptions } from './plots/radar';\n\n// 混合图形 | author by [liuzhenying](https://github.com/liuzhenying)\nexport { DualAxes } from './plots/dual-axes';\nexport type { DualAxesOptions } from './plots/dual-axes';\n\n// 迷你折线图及类型定义 | author by [connono](https://github.com/connono)\nexport { TinyLine } from './plots/tiny-line';\nexport type { TinyLineOptions } from './plots/tiny-line';\n\n// 迷你柱形图及类型定义 | author by [connono](https://github.com/connono)\nexport { TinyColumn } from './plots/tiny-column';\nexport type { TinyColumnOptions } from './plots/tiny-column';\n\n// 迷你面积图及类型定义 | author by [connono](https://github.com/connono)\nexport { TinyArea } from './plots/tiny-area';\nexport type { TinyAreaOptions } from './plots/tiny-area';\n\n// 直方图及类型定义 | author by [arcsin1](https://github.com/arcsin1), [visiky](https://github.com/visiky)\nexport { Histogram } from './plots/histogram';\nexport type { HistogramOptions } from './plots/histogram';\n\n// 进度图及类型定义 | author by [connono](https://github.com/connono)\nexport { Progress } from './plots/progress';\nexport type { ProgressOptions } from './plots/progress';\n\n// 环形进度图及类型定义 | author by [connono](https://github.com/connono)\nexport { RingProgress } from './plots/ring-progress';\nexport type { RingProgressOptions } from './plots/ring-progress';\n\n// 热力图及类型定义 | author by [jiazhewang](https://github.com/jiazhewang)\nexport { Heatmap } from './plots/heatmap';\nexport type { HeatmapOptions } from './plots/heatmap';\n\n// 箱线图及类型定义 | author by [BBSQQ](https://github.com/BBSQQ), [visiky](https://github.com/visiky)\nexport { Box } from './plots/box';\nexport type { BoxOptions } from './plots/box';\n\n// 小提琴图及类型定义 | author by [YiSiWang](https://github.com/YiSiWang), [visiky](https://github.com/visiky)\nexport { Violin } from './plots/violin';\nexport type { ViolinOptions } from './plots/violin';\n\n// 韦恩图及类型定义 | author by [visiky](https://github.com/visiky)\nexport { Venn } from './plots/venn';\nexport type { VennOptions } from './plots/venn';\n\n// K线图及类型定义 | author by [jhwong](https://github.com/jinhuiWong), [visiky](https://github.com/visiky)\nexport { Stock } from './plots/stock';\nexport type { StockOptions } from './plots/stock';\n\n// 漏斗图及类型定义\nexport { Funnel, FUNNEL_CONVERSATION_FIELD } from './plots/funnel';\nexport type { FunnelOptions } from './plots/funnel';\n\n// 水波图及类型定义 | author by [CarisL](https://github.com/CarisL), [hustcc](https://github.com/hustcc), [pearmini](https://github.com/pearmini)\nexport { Liquid } from './plots/liquid';\nexport type { LiquidOptions } from './plots/liquid';\n\n// 子弹图及类型定义 | author by [arcsin1](https://github.com/arcsin1)\nexport { Bullet } from './plots/bullet';\nexport type { BulletOptions } from './plots/bullet';\n\n// 旭日图及类型定义 | author by [lxfu1](https://github.com/lxfu1), [visiky](https://github.com/visiky)\nexport { Sunburst } from './plots/sunburst';\nexport type { SunburstOptions } from './plots/sunburst';\n\n// 仪表盘及类型定义 | author by [hustcc](https://github.com/hustcc)\nexport { Gauge } from './plots/gauge';\nexport type { GaugeOptions } from './plots/gauge';\n\n// 瀑布图 | author by [visiky](https://github.com/visiky)\nexport { Waterfall } from './plots/waterfall';\nexport type { WaterfallOptions } from './plots/waterfall';\n\n// 玉珏图 | author by [yujs](https://github.com/yujs) | updated by [visiky](https://github.com/visiky)\nexport { RadialBar } from './plots/radial-bar';\nexport type { RadialBarOptions } from './plots/radial-bar';\n\n// 对称条形图及类型定义 | author by [arcsin1](https://github.com/arcsin1)\nexport { BidirectionalBar } from './plots/bidirectional-bar';\nexport type { BidirectionalBarOptions } from './plots/bidirectional-bar';\n\n// 矩形树图\nexport { Treemap } from './plots/treemap';\nexport type { TreemapOptions } from './plots/treemap';\n\n// 桑基图及类型定义 | author by [hustcc](https://github.com/hustcc)\nexport { Sankey } from './plots/sankey';\nexport type { SankeyOptions } from './plots/sankey';\n\n// 弦图及类型定义 | author by [MrSmallLiu](https://github.com/MrSmallLiu), [visiky](https://github.com/visiky)\nexport { Chord } from './plots/chord';\nexport type { ChordOptions } from './plots/chord';\n\n// circle-packing 及类型定义 | author by [visiky](https://github.com/visiky), [Angeli](https://github.com/Angelii)\nexport { CirclePacking } from './plots/circle-packing';\nexport type { CirclePackingOptions } from './plots/circle-packing';\n\n// 以下开放自定义图表开发的能力(目前仅仅是孵化中)\n/** 所有开放图表都使用 G2Plot.P 作为入口开发,理论上官方的所有图表都可以走 G2Plot.P 的入口(暂时不处理) */\nexport { P } from './plugin';\n\n/** 开放 getCanvasPatterng 方法 */\nexport { getCanvasPattern } from './utils/pattern';\n\n// 已经废弃,更名为 Mix\nexport { Mix as MultiView } from './plots/mix';\nexport type { MixOptions as MultiViewOptions } from './plots/mix';\n/** 开放多图层图表 (mix) */\nexport { Mix as Mix } from './plots/mix';\nexport type { MixOptions } from './plots/mix';\n\n// 分面图及类型定义 | author by [visiky](https://github.com/visiky)\nexport { Facet } from './plots/facet';\nexport type { FacetOptions } from './plots/facet';\n\n/** 开发 adaptor 可能会用到的方法或一些工具方法,不强制使用 */\nexport { flow, measureTextWidth } from './utils';\n\n/** 各个 geometry 的 adaptor,可以让开发者更快的构造图形 */\nexport { line, interval, area, point, polygon, schema } from './adaptor/geometries';\nexport type {\n LineGeometryOptions,\n IntervalGeometryOptions,\n AreaGeometryOptions,\n PointGeometryOptions,\n PolygonGeometryOptions,\n SchemaGeometryOptions,\n} from './adaptor/geometries';\n/** 开放一些通用的 adaptor 通道方法,实验阶段:不保证稳定性 */\nimport { scale, legend, tooltip, annotation, interaction, theme, animation } from './adaptor/common';\nexport const adaptors = { scale, legend, tooltip, annotation, interaction, theme, animation };\n\n/** 对于没有开发完成的图表,可以暂时先放到 Lab 下面,先做体验,稳定后放到根 export */\nexport { Lab } from './lab';\n"]}
@@ -1,8 +1,13 @@
1
1
  import { Params } from '../../core/adaptor';
2
- import { BarOptions } from './types';
3
2
  export { meta } from '../column/adaptor';
3
+ import { BarOptions } from './types';
4
4
  /**
5
5
  * 柱形图适配器
6
6
  * @param params
7
7
  */
8
- export declare function adaptor(params: Params<BarOptions>): Params<import("../..").Options>;
8
+ export declare function geometry(params: Params<BarOptions>): Params<BarOptions>;
9
+ /**
10
+ * @param chart
11
+ * @param options
12
+ */
13
+ export declare function adaptor(params: Params<BarOptions>): Params<BarOptions>;
@@ -1,18 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.adaptor = void 0;
3
+ exports.adaptor = exports.geometry = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ var common_1 = require("../../adaptor/common");
6
+ var utils_1 = require("../../utils");
5
7
  var adaptor_1 = require("../column/adaptor");
6
- var utils_1 = require("./utils");
7
8
  var adaptor_2 = require("../column/adaptor");
8
9
  Object.defineProperty(exports, "meta", { enumerable: true, get: function () { return adaptor_2.meta; } });
9
10
  /**
10
- * 柱形图适配器
11
+ * 处理默认配置项
12
+ * 1. switch xField、 yField
13
+ * 2. switch xAxis、 yAxis and adjust axis.position configuration
14
+ */
15
+ function defaultOptions(params) {
16
+ var options = params.options;
17
+ var xField = options.xField, yField = options.yField, xAxis = options.xAxis, yAxis = options.yAxis;
18
+ var position = {
19
+ left: 'bottom',
20
+ right: 'top',
21
+ top: 'left',
22
+ bottom: 'right',
23
+ };
24
+ var verticalAxis = yAxis !== false
25
+ ? tslib_1.__assign({ position: position[(yAxis === null || yAxis === void 0 ? void 0 : yAxis.position) || 'left'] }, yAxis) : false;
26
+ var horizontalAxis = xAxis !== false
27
+ ? tslib_1.__assign({ position: position[(xAxis === null || xAxis === void 0 ? void 0 : xAxis.position) || 'bottom'] }, xAxis) : false;
28
+ return utils_1.deepAssign({}, params, {
29
+ options: {
30
+ xField: yField,
31
+ yField: xField,
32
+ xAxis: verticalAxis,
33
+ yAxis: horizontalAxis,
34
+ },
35
+ });
36
+ }
37
+ /**
38
+ * label 适配器
11
39
  * @param params
12
40
  */
13
- function adaptor(params) {
14
- var chart = params.chart, options = params.options;
15
- var xField = options.xField, yField = options.yField, xAxis = options.xAxis, yAxis = options.yAxis, barStyle = options.barStyle, barWidthRatio = options.barWidthRatio, label = options.label, data = options.data, seriesField = options.seriesField, isStack = options.isStack, minBarWidth = options.minBarWidth, maxBarWidth = options.maxBarWidth;
41
+ function label(params) {
42
+ var options = params.options;
43
+ var label = options.label;
16
44
  // label of bar charts default position is left, if plot has label
17
45
  if (label && !label.position) {
18
46
  label.position = 'left';
@@ -26,39 +54,59 @@ function adaptor(params) {
26
54
  ];
27
55
  }
28
56
  }
57
+ return utils_1.deepAssign({}, params, { options: { label: label } });
58
+ }
59
+ /**
60
+ * legend 适配器
61
+ * @param params
62
+ */
63
+ function legend(params) {
64
+ var options = params.options;
29
65
  // 默认 legend 位置
66
+ var seriesField = options.seriesField, isStack = options.isStack;
30
67
  var legend = options.legend;
31
68
  if (seriesField) {
32
69
  if (legend !== false) {
33
- legend = tslib_1.__assign({ position: isStack ? 'top-left' : 'right-top', reversed: isStack ? false : true }, (legend || {}));
70
+ legend = tslib_1.__assign({ position: isStack ? 'top-left' : 'right-top' }, (legend || {}));
34
71
  }
35
72
  }
36
73
  else {
37
74
  legend = false;
38
75
  }
39
- // @ts-ignore 直接改值
40
- params.options.legend = legend;
41
- // 默认 tooltip 配置
42
- var tooltip = options.tooltip;
43
- if (seriesField) {
44
- if (tooltip !== false) {
45
- tooltip = tslib_1.__assign({ reversed: isStack ? false : true }, (tooltip || {}));
46
- }
47
- }
48
- // @ts-ignore 直接改值
49
- params.options.tooltip = tooltip;
50
- // transpose column to bar
51
- chart.coordinate().transpose();
76
+ return utils_1.deepAssign({}, params, { options: { legend: legend } });
77
+ }
78
+ /**
79
+ * coordinate 适配器
80
+ * @param params
81
+ */
82
+ function coordinate(params) {
83
+ var chart = params.chart;
84
+ // transpose column to bar 对角变换 & y 方向镜像变换
85
+ chart.coordinate({ actions: [['transpose'], ['reflect', 'y']] });
86
+ return params;
87
+ }
88
+ /**
89
+ * 柱形图适配器
90
+ * @param params
91
+ */
92
+ function geometry(params) {
93
+ var chart = params.chart, options = params.options;
94
+ var barStyle = options.barStyle, barWidthRatio = options.barWidthRatio, minBarWidth = options.minBarWidth, maxBarWidth = options.maxBarWidth, barBackground = options.barBackground;
52
95
  return adaptor_1.adaptor({
53
96
  chart: chart,
54
- options: tslib_1.__assign(tslib_1.__assign({}, options), { label: label,
55
- // switch xField and yField
56
- xField: yField, yField: xField, xAxis: yAxis, yAxis: xAxis,
97
+ options: tslib_1.__assign(tslib_1.__assign({}, options), {
57
98
  // rename attrs as column
58
- columnStyle: barStyle, columnWidthRatio: barWidthRatio, minColumnWidth: minBarWidth, maxColumnWidth: maxBarWidth, columnBackground: options.barBackground,
59
- // bar 调整数据顺序
60
- data: utils_1.transformBarData(data) }),
99
+ columnStyle: barStyle, columnWidthRatio: barWidthRatio, minColumnWidth: minBarWidth, maxColumnWidth: maxBarWidth, columnBackground: barBackground }),
61
100
  }, true);
62
101
  }
102
+ exports.geometry = geometry;
103
+ /**
104
+ * @param chart
105
+ * @param options
106
+ */
107
+ function adaptor(params) {
108
+ // flow 的方式处理所有的配置到 G2 API
109
+ return utils_1.flow(defaultOptions, label, legend, common_1.tooltip, coordinate, geometry)(params);
110
+ }
63
111
  exports.adaptor = adaptor;
64
112
  //# sourceMappingURL=adaptor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"adaptor.js","sourceRoot":"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,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAC7B,CAAC,MAAM,IAAI,EAAE,CAAC,CAClB,CAAC;SACH;KACF;SAAM;QACL,MAAM,GAAG,KAAK,CAAC;KAChB;IACD,kBAAkB;IAClB,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;IAE/B,gBAAgB;IACV,IAAA,OAAO,GAAK,OAAO,QAAZ,CAAa;IAC1B,IAAI,WAAW,EAAE;QACf,IAAI,OAAO,KAAK,KAAK,EAAE;YACrB,OAAO,sBACL,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAC7B,CAAC,OAAO,IAAI,EAAE,CAAC,CACnB,CAAC;SACH;KACF;IACD,kBAAkB;IAClB,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;IAEjC,0BAA0B;IAC1B,KAAK,CAAC,UAAU,EAAE,CAAC,SAAS,EAAE,CAAC;IAE/B,OAAO,iBAAa,CAClB;QACE,KAAK,OAAA;QACL,OAAO,wCACF,OAAO,KACV,KAAK,OAAA;YACL,2BAA2B;YAC3B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,KAAK;YACZ,yBAAyB;YACzB,WAAW,EAAE,QAAQ,EACrB,gBAAgB,EAAE,aAAa,EAC/B,cAAc,EAAE,WAAW,EAC3B,cAAc,EAAE,WAAW,EAC3B,gBAAgB,EAAE,OAAO,CAAC,aAAa;YACvC,aAAa;YACb,IAAI,EAAE,wBAAgB,CAAC,IAAI,CAAC,GAC7B;KACF,EACD,IAAI,CACL,CAAC;AACJ,CAAC;AAtFD,0BAsFC","sourcesContent":["import { Params } from '../../core/adaptor';\nimport { adaptor as columnAdaptor } from '../column/adaptor';\nimport { BarOptions } from './types';\nimport { transformBarData } from './utils';\n\nexport { meta } from '../column/adaptor';\n\n/**\n * 柱形图适配器\n * @param params\n */\nexport function adaptor(params: Params<BarOptions>) {\n const { chart, options } = params;\n const {\n xField,\n yField,\n xAxis,\n yAxis,\n barStyle,\n barWidthRatio,\n label,\n data,\n seriesField,\n isStack,\n minBarWidth,\n maxBarWidth,\n } = options;\n\n // label of bar charts default position is left, if plot has label\n if (label && !label.position) {\n label.position = 'left';\n // 配置默认的 label layout: 如果用户没有指定 layout 和 position, 则自动配置 layout\n if (!label.layout) {\n label.layout = [\n { type: 'interval-adjust-position' },\n { type: 'interval-hide-overlap' },\n { type: 'adjust-color' },\n { type: 'limit-in-plot', cfg: { action: 'hide' } },\n ];\n }\n }\n\n // 默认 legend 位置\n let { legend } = options;\n if (seriesField) {\n if (legend !== false) {\n legend = {\n position: isStack ? 'top-left' : 'right-top',\n reversed: isStack ? false : true,\n ...(legend || {}),\n };\n }\n } else {\n legend = false;\n }\n // @ts-ignore 直接改值\n params.options.legend = legend;\n\n // 默认 tooltip 配置\n let { tooltip } = options;\n if (seriesField) {\n if (tooltip !== false) {\n tooltip = {\n reversed: isStack ? false : true,\n ...(tooltip || {}),\n };\n }\n }\n // @ts-ignore 直接改值\n params.options.tooltip = tooltip;\n\n // transpose column to bar\n chart.coordinate().transpose();\n\n return columnAdaptor(\n {\n chart,\n options: {\n ...options,\n label,\n // switch xField and yField\n xField: yField,\n yField: xField,\n xAxis: yAxis,\n yAxis: xAxis,\n // rename attrs as column\n columnStyle: barStyle,\n columnWidthRatio: barWidthRatio,\n minColumnWidth: minBarWidth,\n maxColumnWidth: maxBarWidth,\n columnBackground: options.barBackground,\n // bar 调整数据顺序\n data: transformBarData(data),\n },\n },\n true\n );\n}\n"]}
1
+ {"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../src/plots/bar/adaptor.ts"],"names":[],"mappings":";;;;AACA,+CAA+C;AAC/C,qCAA+C;AAC/C,6CAA6D;AAC7D,6CAAyC;AAAhC,+FAAA,IAAI,OAAA;AAGb;;;;GAIG;AACH,SAAS,cAAc,CA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AgB,QAAQ,CAAC,MAA0B;IACzC,IAAA,KAAK,GAAc,MAAM,MAApB,EAAE,OAAO,GAAK,MAAM,QAAX,CAAY;IAE1B,IAAA,QAAQ,GAA6D,OAAO,SAApE,EAAE,aAAa,GAA8C,OAAO,cAArD,EAAE,WAAW,GAAiC,OAAO,YAAxC,EAAE,WAAW,GAAoB,OAAO,YAA3B,EAAE,aAAa,GAAK,OAAO,cAAZ,CAAa;IAErF,OAAO,iBAAa,CAClB;QACE,KAAK,OAAA;QACL,OAAO,wCACF,OAAO;YACV,yBAAyB;YACzB,WAAW,EAAE,QAAQ,EACrB,gBAAgB,EAAE,aAAa,EAC/B,cAAc,EAAE,WAAW,EAC3B,cAAc,EAAE,WAAW,EAC3B,gBAAgB,EAAE,aAAa,GAChC;KACF,EACD,IAAI,CACiB,CAAC;AAC1B,CAAC;AApBD,4BAoBC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,MAA0B;IAChD,0BAA0B;IAC1B,OAAO,YAAI,CAAqB,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAO,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AACxG,CAAC;AAHD,0BAGC","sourcesContent":["import { Params } from '../../core/adaptor';\nimport { tooltip } from '../../adaptor/common';\nimport { deepAssign, flow } from '../../utils';\nimport { adaptor as columnAdaptor } from '../column/adaptor';\nexport { meta } from '../column/adaptor';\nimport { BarOptions } from './types';\n\n/**\n * 处理默认配置项\n * 1. switch xField、 yField\n * 2. switch xAxis、 yAxis and adjust axis.position configuration\n */\nfunction defaultOptions(params: Params<BarOptions>): Params<BarOptions> {\n const { options } = params;\n const { xField, yField, xAxis, yAxis } = options;\n\n const position = {\n left: 'bottom',\n right: 'top',\n top: 'left',\n bottom: 'right',\n };\n\n const verticalAxis =\n yAxis !== false\n ? {\n position: position[yAxis?.position || 'left'],\n ...yAxis,\n }\n : false;\n const horizontalAxis =\n xAxis !== false\n ? {\n position: position[xAxis?.position || 'bottom'],\n ...xAxis,\n }\n : false;\n\n return deepAssign({}, params, {\n options: {\n xField: yField,\n yField: xField,\n xAxis: verticalAxis,\n yAxis: horizontalAxis,\n },\n });\n}\n\n/**\n * label 适配器\n * @param params\n */\nfunction label(params: Params<BarOptions>): Params<BarOptions> {\n const { options } = params;\n const { label } = options;\n // label of bar charts default position is left, if plot has label\n if (label && !label.position) {\n label.position = 'left';\n // 配置默认的 label layout: 如果用户没有指定 layout 和 position, 则自动配置 layout\n if (!label.layout) {\n label.layout = [\n { type: 'interval-adjust-position' },\n { type: 'interval-hide-overlap' },\n { type: 'adjust-color' },\n { type: 'limit-in-plot', cfg: { action: 'hide' } },\n ];\n }\n }\n\n return deepAssign({}, params, { options: { label } });\n}\n\n/**\n * legend 适配器\n * @param params\n */\nfunction legend(params: Params<BarOptions>): Params<BarOptions> {\n const { options } = params;\n\n // 默认 legend 位置\n const { seriesField, isStack } = options;\n let { legend } = options;\n if (seriesField) {\n if (legend !== false) {\n legend = {\n position: isStack ? 'top-left' : 'right-top',\n ...(legend || {}),\n };\n }\n } else {\n legend = false;\n }\n\n return deepAssign({}, params, { options: { legend } });\n}\n\n/**\n * coordinate 适配器\n * @param params\n */\nfunction coordinate(params: Params<BarOptions>): Params<BarOptions> {\n const { chart } = params;\n // transpose column to bar 对角变换 & y 方向镜像变换\n chart.coordinate({ actions: [['transpose'], ['reflect', 'y']] });\n return params;\n}\n\n/**\n * 柱形图适配器\n * @param params\n */\nexport function geometry(params: Params<BarOptions>) {\n const { chart, options } = params;\n\n const { barStyle, barWidthRatio, minBarWidth, maxBarWidth, barBackground } = options;\n\n return columnAdaptor(\n {\n chart,\n options: {\n ...options,\n // rename attrs as column\n columnStyle: barStyle,\n columnWidthRatio: barWidthRatio,\n minColumnWidth: minBarWidth,\n maxColumnWidth: maxBarWidth,\n columnBackground: barBackground,\n },\n },\n true\n ) as Params<BarOptions>;\n}\n\n/**\n * @param chart\n * @param options\n */\nexport function adaptor(params: Params<BarOptions>): Params<BarOptions> {\n // flow 的方式处理所有的配置到 G2 API\n return flow<Params<BarOptions>>(defaultOptions, label, legend, tooltip, coordinate, geometry)(params);\n}\n"]}
@@ -6,7 +6,6 @@ var plot_1 = require("../../core/plot");
6
6
  var percent_1 = require("../../utils/transform/percent");
7
7
  var adaptor_1 = require("./adaptor");
8
8
  var constants_1 = require("./constants");
9
- var utils_1 = require("./utils");
10
9
  /**
11
10
  * 条形图
12
11
  */
@@ -34,7 +33,7 @@ var Bar = /** @class */ (function (_super) {
34
33
  var xField = options.xField, yField = options.yField, isPercent = options.isPercent;
35
34
  var switchedFieldOptions = tslib_1.__assign(tslib_1.__assign({}, options), { xField: yField, yField: xField });
36
35
  adaptor_1.meta({ chart: chart, options: switchedFieldOptions });
37
- chart.changeData(percent_1.getDataWhetherPecentage(utils_1.transformBarData(data), xField, yField, xField, isPercent));
36
+ chart.changeData(percent_1.getDataWhetherPecentage(data, xField, yField, xField, isPercent));
38
37
  };
39
38
  /**
40
39
  * 获取 条形图 默认配置
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plots/bar/index.ts"],"names":[],"mappings":";;;;AAAA,wCAAuC;AAEvC,yDAAwE;AAExE,qCAA0C;AAC1C,yCAA8C;AAC9C,iCAA2C;AAI3C;;GAEG;AACH;IAAyB,+BAAgB;IAAzC;QAAA,qEAqCC;QA5BC,WAAW;QACK,UAAI,GAAW,KAAK,CAAC;;IA2BvC,CAAC;IApCC;;;OAGG;IACI,qBAAiB,GAAxB;QACE,OAAO,2BAAe,CAAC;IACzB,CAAC;IAKD;;OAEG;IACI,wBAAU,GAAjB,UAAkB,IAAwB;QACxC,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,MAAA,EAAE,CAAC,CAAC;QACtB,IAAA,KAAqB,IAAI,EAAvB,KAAK,WAAA,EAAE,OAAO,aAAS,CAAC;QACxB,IAAA,MAAM,GAAwB,OAAO,OAA/B,EAAE,MAAM,GAAgB,OAAO,OAAvB,EAAE,SAAS,GAAK,OAAO,UAAZ,CAAa;QAC9C,IAAM,oBAAoB,yCAAQ,OAAO,KAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,CAAC;QAC5E,cAAI,CAAC,EAAE,KAAK,OAAA,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC,CAAC;QAC/C,KAAK,CAAC,UAAU,CAAC,iCAAuB,CAAC,wBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IACvG,CAAC;IAED;;OAEG;IACO,+BAAiB,GAA3B;QACE,OAAO,GAAG,CAAC,iBAAiB,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACO,8BAAgB,GAA1B;QACE,OAAO,iBAAO,CAAC;IACjB,CAAC;IACH,UAAC;AAAD,CAAC,AArCD,CAAyB,WAAI,GAqC5B;AArCY,kBAAG","sourcesContent":["import { Plot } from '../../core/plot';\nimport { Adaptor } from '../../core/adaptor';\nimport { getDataWhetherPecentage } from '../../utils/transform/percent';\nimport { BarOptions } from './types';\nimport { adaptor, meta } from './adaptor';\nimport { DEFAULT_OPTIONS } from './constants';\nimport { transformBarData } from './utils';\n\nexport type { BarOptions };\n\n/**\n * 条形图\n */\nexport class Bar extends Plot<BarOptions> {\n /**\n * 获取 条形图 默认配置项\n * 供外部使用\n */\n static getDefaultOptions(): Partial<BarOptions> {\n return DEFAULT_OPTIONS;\n }\n\n /** 图表类型 */\n public readonly type: string = 'bar';\n\n /**\n * @override\n */\n public changeData(data: BarOptions['data']) {\n this.updateOption({ data });\n const { chart, options } = this;\n const { xField, yField, isPercent } = options;\n const switchedFieldOptions = { ...options, xField: yField, yField: xField };\n meta({ chart, options: switchedFieldOptions });\n chart.changeData(getDataWhetherPecentage(transformBarData(data), xField, yField, xField, isPercent));\n }\n\n /**\n * 获取 条形图 默认配置\n */\n protected getDefaultOptions() {\n return Bar.getDefaultOptions();\n }\n\n /**\n * 获取 条形图 的适配器\n */\n protected getSchemaAdaptor(): Adaptor<BarOptions> {\n return adaptor;\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plots/bar/index.ts"],"names":[],"mappings":";;;;AAAA,wCAAuC;AAEvC,yDAAwE;AAExE,qCAA0C;AAC1C,yCAA8C;AAI9C;;GAEG;AACH;IAAyB,+BAAgB;IAAzC;QAAA,qEAqCC;QA5BC,WAAW;QACK,UAAI,GAAW,KAAK,CAAC;;IA2BvC,CAAC;IApCC;;;OAGG;IACI,qBAAiB,GAAxB;QACE,OAAO,2BAAe,CAAC;IACzB,CAAC;IAKD;;OAEG;IACI,wBAAU,GAAjB,UAAkB,IAAwB;QACxC,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,MAAA,EAAE,CAAC,CAAC;QACtB,IAAA,KAAqB,IAAI,EAAvB,KAAK,WAAA,EAAE,OAAO,aAAS,CAAC;QACxB,IAAA,MAAM,GAAwB,OAAO,OAA/B,EAAE,MAAM,GAAgB,OAAO,OAAvB,EAAE,SAAS,GAAK,OAAO,UAAZ,CAAa;QAC9C,IAAM,oBAAoB,yCAAQ,OAAO,KAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,CAAC;QAC5E,cAAI,CAAC,EAAE,KAAK,OAAA,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC,CAAC;QAC/C,KAAK,CAAC,UAAU,CAAC,iCAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IACrF,CAAC;IAED;;OAEG;IACO,+BAAiB,GAA3B;QACE,OAAO,GAAG,CAAC,iBAAiB,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACO,8BAAgB,GAA1B;QACE,OAAO,iBAAO,CAAC;IACjB,CAAC;IACH,UAAC;AAAD,CAAC,AArCD,CAAyB,WAAI,GAqC5B;AArCY,kBAAG","sourcesContent":["import { Plot } from '../../core/plot';\nimport { Adaptor } from '../../core/adaptor';\nimport { getDataWhetherPecentage } from '../../utils/transform/percent';\nimport { BarOptions } from './types';\nimport { adaptor, meta } from './adaptor';\nimport { DEFAULT_OPTIONS } from './constants';\n\nexport type { BarOptions };\n\n/**\n * 条形图\n */\nexport class Bar extends Plot<BarOptions> {\n /**\n * 获取 条形图 默认配置项\n * 供外部使用\n */\n static getDefaultOptions(): Partial<BarOptions> {\n return DEFAULT_OPTIONS;\n }\n\n /** 图表类型 */\n public readonly type: string = 'bar';\n\n /**\n * @override\n */\n public changeData(data: BarOptions['data']) {\n this.updateOption({ data });\n const { chart, options } = this;\n const { xField, yField, isPercent } = options;\n const switchedFieldOptions = { ...options, xField: yField, yField: xField };\n meta({ chart, options: switchedFieldOptions });\n chart.changeData(getDataWhetherPecentage(data, xField, yField, xField, isPercent));\n }\n\n /**\n * 获取 条形图 默认配置\n */\n protected getDefaultOptions() {\n return Bar.getDefaultOptions();\n }\n\n /**\n * 获取 条形图 的适配器\n */\n protected getSchemaAdaptor(): Adaptor<BarOptions> {\n return adaptor;\n }\n}\n"]}
@@ -52,16 +52,6 @@ function axis(params) {
52
52
  return params;
53
53
  }
54
54
  exports.axis = axis;
55
- /**
56
- * legend 配置(旭日图暂时不支持图例,后续需要支持的话,得自定义数据筛选)
57
- * @param params
58
- * @returns
59
- */
60
- function legend(params) {
61
- var chart = params.chart;
62
- chart.legend(false);
63
- return params;
64
- }
65
55
  /**
66
56
  * 数据标签
67
57
  * @param params
@@ -186,7 +176,7 @@ function interaction(params) {
186
176
  */
187
177
  function adaptor(params) {
188
178
  // flow 的方式处理所有的配置到 G2 API
189
- return utils_1.flow(common_1.theme, common_1.pattern('sunburstStyle'), geometry, axis, meta, legend, coordinate, tooltip, label, interaction, common_1.animation, common_1.annotation())(params);
179
+ return utils_1.flow(common_1.theme, common_1.pattern('sunburstStyle'), geometry, axis, meta, common_1.legend, coordinate, tooltip, label, interaction, common_1.animation, common_1.annotation())(params);
190
180
  }
191
181
  exports.adaptor = adaptor;
192
182
  //# sourceMappingURL=adaptor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../src/plots/sunburst/adaptor.ts"],"names":[],"mappings":";;;;AAAA,mCAAmD;AAGnD,uDAAqE;AACrE,+CAAoH;AACpH,qCAA6E;AAC7E,+CAA6D;AAE7D,uCAAwG;AACxG,iCAAwC;AAGxC;;;GAGG;AACH,SAAS,QAAQ,CAAC,MAA+B;IACvC,IAAA,KAAK,GAAc,MAAM,MAApB,EAAE,OAAO,GAAK,MAAM,QAAX,CAAY;IAC1B,IAAA,KAAK,GAA0E,OAAO,MAAjF,EAAE,KAAwE,OAAO,WAA3C,EAApC,UAAU,mBAAG,kCAAuB,KAAA,EAAE,aAAa,GAAqB,OAAO,cAA5B,EAAE,KAAmB,OAAO,UAAZ,EAAd,SAAS,mBAAG,EAAE,KAAA,CAAa;IAC/F,IAAM,IAAI,GAAG,qBAAa,CAAC,OAAO,CAAC,CAAC;IACpC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEjB,+CAA+C;IAC/C,IAAI,KAAK,CAAC;IACV,IAAI,aAAa,EAAE;QACjB,KAAK,GAAG,UAAC,KAAY;YACnB,OAAO,kBAAU,CACf,EAAE,EACF;gBACE,WAAW,EAAE,SAAA,IAAI,EAAI,KAAK,CAAC,KAAK,CAAA;aACjC,EACD,iBAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CACjE,CAAC;QACJ,CAAC,CAAC;KACH;IAED,WAAW;IACX,oBAAc,CACZ,kBAAU,CAAC,EAAE,EAAE,MAAM,EAAE;QACrB,OAAO,EAAE;YACP,MAAM,EAAE,GAAG;YACX,MAAM,EAAE,GAAG;YACX,WAAW,EAAE,UAAU;YACvB,SAAS,EAAE,WAAI,wBAAK,qBAAU,EAAK,SAAS,EAAE;YAC9C,O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A,KAAK,GAAc,MAAM,MAApB,EAAE,OAAO,GAAK,MAAM,QAAX,CAAY;IAE1B,IAAA,SAAS,GAAK,OAAO,UAAZ,CAAa;IAE9B,oBAAe,CAAC;QACd,KAAK,OAAA;QACL,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC;KACrC,CAAC,CAAC;IAEH,YAAY;IACZ,IAAI,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,EAAE;QACtB,kBAAkB;QAClB,KAAK,CAAC,aAAa,GAAG,gCAAsB,CAAC,KAAK,CAAC,aAAa,EAAE,UAAG,CAAC,SAAS,EAAE,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;KAC/G;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CAAC,MAA+B;IACrD,0BAA0B;IAC1B,OAAO,YAAI,CACT,cAAK,EACL,gBAAO,CAAC,eAAe,CAAC,EACxB,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,UAAU,EACV,OAAO,EACP,KAAK,EACL,WAAW,EACX,kBAAS,EACT,mBAAU,EAAE,CACb,CAAC,MAAM,CAAC,CAAC;AACZ,CAAC;AAhBD,0BAgBC","sourcesContent":["import { isFunction, get, uniq } from '@antv/util';\nimport { Types } from '@antv/g2';\nimport { Params } from '../../core/adaptor';\nimport { polygon as polygonAdaptor } from '../../adaptor/geometries';\nimport { interaction as baseInteraction, animation, theme, annotation, scale, pattern } from '../../adaptor/common';\nimport { flow, findGeometry, transformLabel, deepAssign } from '../../utils';\nimport { getAdjustAppendPadding } from '../../utils/padding';\nimport { Datum } from '../../types';\nimport { RAW_FIELDS, SUNBURST_ANCESTOR_FIELD, SUNBURST_PATH_FIELD, SUNBURST_Y_FIELD } from './constant';\nimport { transformData } from './utils';\nimport { SunburstOptions } from './types';\n\n/**\n * geometry 配置处理\n * @param params\n */\nfunction geometry(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { chart, options } = params;\n const { color, colorField = SUNBURST_ANCESTOR_FIELD, sunburstStyle, rawFields = [] } = options;\n const data = transformData(options);\n chart.data(data);\n\n // 特殊处理下样式,如果没有设置 fillOpacity 的时候,默认根据层级进行填充透明度\n let style;\n if (sunburstStyle) {\n style = (datum: Datum) => {\n return deepAssign(\n {},\n {\n fillOpacity: 0.85 ** datum.depth,\n },\n isFunction(sunburstStyle) ? sunburstStyle(datum) : sunburstStyle\n );\n };\n }\n\n // geometry\n polygonAdaptor(\n deepAssign({}, params, {\n options: {\n xField: 'x',\n yField: 'y',\n seriesField: colorField,\n rawFields: uniq([...RAW_FIELDS, ...rawFields]),\n polygon: {\n color,\n style,\n },\n },\n })\n );\n\n return params;\n}\n\n/**\n * axis 配置\n * @param params\n */\nexport function axis(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { chart } = params;\n chart.axis(false);\n return params;\n}\n\n/**\n * legend 配置(旭日图暂时不支持图例,后续需要支持的话,得自定义数据筛选)\n * @param params\n * @returns\n */\nfunction legend(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { chart } = params;\n\n chart.legend(false);\n return params;\n}\n\n/**\n * 数据标签\n * @param params\n */\nfunction label(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { chart, options } = params;\n const { label } = options;\n\n const geometry = findGeometry(chart, 'polygon');\n\n // 默认不展示,undefined 也不展示\n if (!label) {\n geometry.label(false);\n } else {\n const { fields = ['name'], callback, ...cfg } = label;\n geometry.label({\n fields,\n callback,\n cfg: transformLabel(cfg),\n });\n }\n\n return params;\n}\n\n/**\n * coord 配置\n * @param params\n */\nfunction coordinate(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { chart, options } = params;\n const { innerRadius, radius, reflect } = options;\n\n const coord = chart.coordinate({\n type: 'polar',\n cfg: {\n innerRadius,\n radius,\n },\n });\n if (reflect) {\n coord.reflect(reflect);\n }\n\n return params;\n}\n/**\n * meta 配置\n * @param params\n */\nexport function meta(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { options } = params;\n const { hierarchyConfig, meta } = options;\n\n return flow(\n scale(\n {},\n {\n [SUNBURST_Y_FIELD]: get(meta, get(hierarchyConfig, ['field'], 'value')),\n }\n )\n )(params);\n}\n\n/**\n * tooltip 配置\n * @param params\n */\nexport function tooltip(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { chart, options } = params;\n const { tooltip } = options;\n\n if (tooltip === false) {\n chart.tooltip(false);\n } else {\n let tooltipOptions = tooltip;\n // 设置了 fields,就不进行 customItems 了; 设置 formatter 时,需要搭配 fields\n if (!get(tooltip, 'fields')) {\n tooltipOptions = deepAssign(\n {},\n {\n customItems: (items: Types.TooltipItem[]) =>\n items.map((item) => {\n const scales = get(chart.getOptions(), 'scales');\n const pathFormatter = get(scales, [SUNBURST_PATH_FIELD, 'formatter'], (v) => v);\n const valueFormatter = get(scales, [SUNBURST_Y_FIELD, 'formatter'], (v) => v);\n return {\n ...item,\n name: pathFormatter(item.data[SUNBURST_PATH_FIELD]),\n value: valueFormatter(item.data.value),\n };\n }),\n },\n tooltipOptions\n );\n }\n chart.tooltip(tooltipOptions);\n }\n\n return params;\n}\n\nfunction adaptorInteraction(options: SunburstOptions): SunburstOptions {\n const { drilldown, interactions = [] } = options;\n\n if (drilldown?.enabled) {\n return deepAssign({}, options, {\n interactions: [\n ...interactions,\n {\n type: 'drill-down',\n cfg: { drillDownConfig: drilldown, transformData },\n },\n ],\n });\n }\n return options;\n}\n\n/**\n * 交互配置\n * @param params\n * @returns\n */\nfunction interaction(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { chart, options } = params;\n\n const { drilldown } = options;\n\n baseInteraction({\n chart,\n options: adaptorInteraction(options),\n });\n\n // 适应下钻交互面包屑\n if (drilldown?.enabled) {\n // 为面包屑留出 25px 的空间\n chart.appendPadding = getAdjustAppendPadding(chart.appendPadding, get(drilldown, ['breadCrumb', 'position']));\n }\n\n return params;\n}\n\n/**\n * 旭日图适配器\n * @param chart\n * @param options\n */\nexport function adaptor(params: Params<SunburstOptions>) {\n // flow 的方式处理所有的配置到 G2 API\n return flow(\n theme,\n pattern('sunburstStyle'),\n geometry,\n axis,\n meta,\n legend,\n coordinate,\n tooltip,\n label,\n interaction,\n animation,\n annotation()\n )(params);\n}\n"]}
1
+ {"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../src/plots/sunburst/adaptor.ts"],"names":[],"mappings":";;;;AAAA,mCAAmD;AAGnD,uDAAqE;AACrE,+CAQ8B;AAC9B,qCAA6E;AAC7E,+CAA6D;AAE7D,uCAAwG;AACxG,iCAAwC;AAGxC;;;GAGG;AACH,SAAS,QAAQ,CAAC,MAA+B;IACvC,IAAA,KAAK,GAAc,MAAM,MAApB,EAAE,OAAO,GAAK,MAAM,QAAX,CAAY;IAC1B,IAAA,KAAK,GAA0E,OAAO,MAAjF,EAAE,KAAwE,OAAO,WAA3C,EAApC,UAAU,mBAAG,kCAAuB,KAAA,EAAE,aAAa,GAAqB,OAAO,cAA5B,EAAE,KAAmB,OAAO,UAAZ,EAAd,SAAS,mBAAG,EAAE,KAAA,CAAa;IAC/F,IAAM,IAAI,GAAG,qBAAa,CAAC,OAAO,CAAC,CAAC;IACpC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEjB,+CAA+C;IAC/C,IAAI,KAAK,CAAC;IACV,IAAI,aAAa,EAAE;QACjB,KAAK,GAAG,UAAC,KAAY;YACnB,OAAO,kBAAU,CACf,EAAE,EACF;gBACE,WAAW,EAAE,SAAA,IAAI,EAAI,KAAK,CAAC,KAAK,CAAA;aACjC,EACD,iBAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CACjE,CAAC;QACJ,CAAC,CAAC;KACH;IAED,WAAW;IACX,oBAAc,CACZ,kBAAU,CAAC,EAAE,EAAE,MAAM,EAAE;QACrB,OAAO,EAAE;YACP,MAAM,EAAE,GAAG;YACX,MAAM,EA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,SAAS,GAAK,OAAO,UAAZ,CAAa;IAE9B,oBAAe,CAAC;QACd,KAAK,OAAA;QACL,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC;KACrC,CAAC,CAAC;IAEH,YAAY;IACZ,IAAI,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,EAAE;QACtB,kBAAkB;QAClB,KAAK,CAAC,aAAa,GAAG,gCAAsB,CAAC,KAAK,CAAC,aAAa,EAAE,UAAG,CAAC,SAAS,EAAE,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;KAC/G;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CAAC,MAA+B;IACrD,0BAA0B;IAC1B,OAAO,YAAI,CACT,cAAK,EACL,gBAAO,CAAC,eAAe,CAAC,EACxB,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,eAAM,EACN,UAAU,EACV,OAAO,EACP,KAAK,EACL,WAAW,EACX,kBAAS,EACT,mBAAU,EAAE,CACb,CAAC,MAAM,CAAC,CAAC;AACZ,CAAC;AAhBD,0BAgBC","sourcesContent":["import { isFunction, get, uniq } from '@antv/util';\nimport { Types } from '@antv/g2';\nimport { Params } from '../../core/adaptor';\nimport { polygon as polygonAdaptor } from '../../adaptor/geometries';\nimport {\n interaction as baseInteraction,\n animation,\n theme,\n annotation,\n scale,\n pattern,\n legend,\n} from '../../adaptor/common';\nimport { flow, findGeometry, transformLabel, deepAssign } from '../../utils';\nimport { getAdjustAppendPadding } from '../../utils/padding';\nimport { Datum } from '../../types';\nimport { RAW_FIELDS, SUNBURST_ANCESTOR_FIELD, SUNBURST_PATH_FIELD, SUNBURST_Y_FIELD } from './constant';\nimport { transformData } from './utils';\nimport { SunburstOptions } from './types';\n\n/**\n * geometry 配置处理\n * @param params\n */\nfunction geometry(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { chart, options } = params;\n const { color, colorField = SUNBURST_ANCESTOR_FIELD, sunburstStyle, rawFields = [] } = options;\n const data = transformData(options);\n chart.data(data);\n\n // 特殊处理下样式,如果没有设置 fillOpacity 的时候,默认根据层级进行填充透明度\n let style;\n if (sunburstStyle) {\n style = (datum: Datum) => {\n return deepAssign(\n {},\n {\n fillOpacity: 0.85 ** datum.depth,\n },\n isFunction(sunburstStyle) ? sunburstStyle(datum) : sunburstStyle\n );\n };\n }\n\n // geometry\n polygonAdaptor(\n deepAssign({}, params, {\n options: {\n xField: 'x',\n yField: 'y',\n seriesField: colorField,\n rawFields: uniq([...RAW_FIELDS, ...rawFields]),\n polygon: {\n color,\n style,\n },\n },\n })\n );\n\n return params;\n}\n\n/**\n * axis 配置\n * @param params\n */\nexport function axis(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { chart } = params;\n chart.axis(false);\n return params;\n}\n\n/**\n * 数据标签\n * @param params\n */\nfunction label(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { chart, options } = params;\n const { label } = options;\n\n const geometry = findGeometry(chart, 'polygon');\n\n // 默认不展示,undefined 也不展示\n if (!label) {\n geometry.label(false);\n } else {\n const { fields = ['name'], callback, ...cfg } = label;\n geometry.label({\n fields,\n callback,\n cfg: transformLabel(cfg),\n });\n }\n\n return params;\n}\n\n/**\n * coord 配置\n * @param params\n */\nfunction coordinate(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { chart, options } = params;\n const { innerRadius, radius, reflect } = options;\n\n const coord = chart.coordinate({\n type: 'polar',\n cfg: {\n innerRadius,\n radius,\n },\n });\n if (reflect) {\n coord.reflect(reflect);\n }\n\n return params;\n}\n/**\n * meta 配置\n * @param params\n */\nexport function meta(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { options } = params;\n const { hierarchyConfig, meta } = options;\n\n return flow(\n scale(\n {},\n {\n [SUNBURST_Y_FIELD]: get(meta, get(hierarchyConfig, ['field'], 'value')),\n }\n )\n )(params);\n}\n\n/**\n * tooltip 配置\n * @param params\n */\nexport function tooltip(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { chart, options } = params;\n const { tooltip } = options;\n\n if (tooltip === false) {\n chart.tooltip(false);\n } else {\n let tooltipOptions = tooltip;\n // 设置了 fields,就不进行 customItems 了; 设置 formatter 时,需要搭配 fields\n if (!get(tooltip, 'fields')) {\n tooltipOptions = deepAssign(\n {},\n {\n customItems: (items: Types.TooltipItem[]) =>\n items.map((item) => {\n const scales = get(chart.getOptions(), 'scales');\n const pathFormatter = get(scales, [SUNBURST_PATH_FIELD, 'formatter'], (v) => v);\n const valueFormatter = get(scales, [SUNBURST_Y_FIELD, 'formatter'], (v) => v);\n return {\n ...item,\n name: pathFormatter(item.data[SUNBURST_PATH_FIELD]),\n value: valueFormatter(item.data.value),\n };\n }),\n },\n tooltipOptions\n );\n }\n chart.tooltip(tooltipOptions);\n }\n\n return params;\n}\n\nfunction adaptorInteraction(options: SunburstOptions): SunburstOptions {\n const { drilldown, interactions = [] } = options;\n\n if (drilldown?.enabled) {\n return deepAssign({}, options, {\n interactions: [\n ...interactions,\n {\n type: 'drill-down',\n cfg: { drillDownConfig: drilldown, transformData },\n },\n ],\n });\n }\n return options;\n}\n\n/**\n * 交互配置\n * @param params\n * @returns\n */\nfunction interaction(params: Params<SunburstOptions>): Params<SunburstOptions> {\n const { chart, options } = params;\n\n const { drilldown } = options;\n\n baseInteraction({\n chart,\n options: adaptorInteraction(options),\n });\n\n // 适应下钻交互面包屑\n if (drilldown?.enabled) {\n // 为面包屑留出 25px 的空间\n chart.appendPadding = getAdjustAppendPadding(chart.appendPadding, get(drilldown, ['breadCrumb', 'position']));\n }\n\n return params;\n}\n\n/**\n * 旭日图适配器\n * @param chart\n * @param options\n */\nexport function adaptor(params: Params<SunburstOptions>) {\n // flow 的方式处理所有的配置到 G2 API\n return flow(\n theme,\n pattern('sunburstStyle'),\n geometry,\n axis,\n meta,\n legend,\n coordinate,\n tooltip,\n label,\n interaction,\n animation,\n annotation()\n )(params);\n}\n"]}
@@ -38,6 +38,7 @@ exports.DEFAULT_OPTIONS = utils_1.deepAssign({}, plot_1.Plot.getDefaultOptions()
38
38
  offset: 20,
39
39
  showTitle: false,
40
40
  },
41
+ legend: false,
41
42
  // 样式设置
42
43
  sunburstStyle: {
43
44
  lineWidth: 0.5,
@@ -1 +1 @@
1
- {"version":3,"file":"constant.js","sourceRoot":"","sources":["../../../src/plots/sunburst/constant.ts"],"names":[],"mappings":";;;AAAA,wCAAuC;AACvC,qCAAyC;AACzC,mDAAsG;AAGtG;;GAEG;AACU,QAAA,uBAAuB,GAAG,eAAe,CAAC;AAC1C,QAAA,gBAAgB,GAAG,OAAO,CAAC;AAC3B,QAAA,mBAAmB,GAAG,MAAM,CAAC;AAE1C,aAAa;AACA,QAAA,UAAU,GAAG;IACxB,2BAAmB;IACnB,uBAAgB;IAChB,2BAAoB;IACpB,uBAAgB;IAChB,MAAM;IACN,OAAO;IACP,QAAQ;CACT,CAAC;AAEF;;GAEG;AACU,QAAA,eAAe,GAA6B,kBAAU,CAAC,EAAE,EAAE,WAAI,CAAC,iBAAiB,EAAE,EAAE;IAChG,WAAW,EAAE,CAAC;IACd,MAAM,EAAE,IAAI;IAEZ,OAAO;IACP,eAAe,EAAE;QACf,sBAAsB;QACtB,KAAK,EAAE,OAAO;KACf;IAED,KAAK;IACL,OAAO,EAAE;QACP,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,KAAK;QAClB,MAAM,EAAE,EAAE;QACV,SAAS,EAAE,KAAK;KACjB;IAED,OAAO;IACP,aAAa,EAAE;QACb,SAAS,EAAE,GAAG;QACd,MAAM,EAAE,MAAM;KACf;IAED,SAAS;IACT,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;CAC7B,CAAC,CAAC","sourcesContent":["import { Plot } from '../../core/plot';\nimport { deepAssign } from '../../utils';\nimport { CHILD_NODE_COUNT, NODE_ANCESTORS_FIELD, NODE_INDEX_FIELD } from '../../utils/hierarchy/util';\nimport { SunburstOptions } from './types';\n\n/**\n * 祖先节点,非 root 根节点\n */\nexport const SUNBURST_ANCESTOR_FIELD = 'ancestor-node';\nexport const SUNBURST_Y_FIELD = 'value';\nexport const SUNBURST_PATH_FIELD = 'path';\n\n/** 默认的源字段 */\nexport const RAW_FIELDS = [\n SUNBURST_PATH_FIELD,\n NODE_INDEX_FIELD,\n NODE_ANCESTORS_FIELD,\n CHILD_NODE_COUNT,\n 'name',\n 'depth',\n 'height',\n];\n\n/**\n * 旭日图 默认配置项\n */\nexport const DEFAULT_OPTIONS: Partial<SunburstOptions> = deepAssign({}, Plot.getDefaultOptions(), {\n innerRadius: 0,\n radius: 0.85,\n\n // 分层配置\n hierarchyConfig: {\n // 数值字段,默认是 value(可配置)\n field: 'value',\n },\n\n // 组件\n tooltip: {\n shared: true,\n showMarkers: false,\n offset: 20,\n showTitle: false,\n },\n\n // 样式设置\n sunburstStyle: {\n lineWidth: 0.5,\n stroke: '#FFF',\n },\n\n // 默认开启交互\n drilldown: { enabled: true },\n});\n"]}
1
+ {"version":3,"file":"constant.js","sourceRoot":"","sources":["../../../src/plots/sunburst/constant.ts"],"names":[],"mappings":";;;AAAA,wCAAuC;AACvC,qCAAyC;AACzC,mDAAsG;AAGtG;;GAEG;AACU,QAAA,uBAAuB,GAAG,eAAe,CAAC;AAC1C,QAAA,gBAAgB,GAAG,OAAO,CAAC;AAC3B,QAAA,mBAAmB,GAAG,MAAM,CAAC;AAE1C,aAAa;AACA,QAAA,UAAU,GAAG;IACxB,2BAAmB;IACnB,uBAAgB;IAChB,2BAAoB;IACpB,uBAAgB;IAChB,MAAM;IACN,OAAO;IACP,QAAQ;CACT,CAAC;AAEF;;GAEG;AACU,QAAA,eAAe,GAA6B,kBAAU,CAAC,EAAE,EAAE,WAAI,CAAC,iBAAiB,EAAE,EAAE;IAChG,WAAW,EAAE,CAAC;IACd,MAAM,EAAE,IAAI;IAEZ,OAAO;IACP,eAAe,EAAE;QACf,sBAAsB;QACtB,KAAK,EAAE,OAAO;KACf;IAED,KAAK;IACL,OAAO,EAAE;QACP,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,KAAK;QAClB,MAAM,EAAE,EAAE;QACV,SAAS,EAAE,KAAK;KACjB;IACD,MAAM,EAAE,KAAK;IAEb,OAAO;IACP,aAAa,EAAE;QACb,SAAS,EAAE,GAAG;QACd,MAAM,EAAE,MAAM;KACf;IAED,SAAS;IACT,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;CAC7B,CAAC,CAAC","sourcesContent":["import { Plot } from '../../core/plot';\nimport { deepAssign } from '../../utils';\nimport { CHILD_NODE_COUNT, NODE_ANCESTORS_FIELD, NODE_INDEX_FIELD } from '../../utils/hierarchy/util';\nimport { SunburstOptions } from './types';\n\n/**\n * 祖先节点,非 root 根节点\n */\nexport const SUNBURST_ANCESTOR_FIELD = 'ancestor-node';\nexport const SUNBURST_Y_FIELD = 'value';\nexport const SUNBURST_PATH_FIELD = 'path';\n\n/** 默认的源字段 */\nexport const RAW_FIELDS = [\n SUNBURST_PATH_FIELD,\n NODE_INDEX_FIELD,\n NODE_ANCESTORS_FIELD,\n CHILD_NODE_COUNT,\n 'name',\n 'depth',\n 'height',\n];\n\n/**\n * 旭日图 默认配置项\n */\nexport const DEFAULT_OPTIONS: Partial<SunburstOptions> = deepAssign({}, Plot.getDefaultOptions(), {\n innerRadius: 0,\n radius: 0.85,\n\n // 分层配置\n hierarchyConfig: {\n // 数值字段,默认是 value(可配置)\n field: 'value',\n },\n\n // 组件\n tooltip: {\n shared: true,\n showMarkers: false,\n offset: 20,\n showTitle: false,\n },\n legend: false,\n\n // 样式设置\n sunburstStyle: {\n lineWidth: 0.5,\n stroke: '#FFF',\n },\n\n // 默认开启交互\n drilldown: { enabled: true },\n});\n"]}
@@ -1,7 +1,7 @@
1
1
  import { ColorAttr, Options, StyleAttr } from '../../types';
2
2
  import { DrillDownCfg } from '../../types/drill-down';
3
3
  import { HierarchyOption } from '../../utils/hierarchy/types';
4
- export interface SunburstOptions extends Omit<Options, 'data' | 'legend' | 'slider' | 'scrollbar' | 'xAxis' | 'yAxis'> {
4
+ export interface SunburstOptions extends Omit<Options, 'data' | 'slider' | 'scrollbar' | 'xAxis' | 'yAxis'> {
5
5
  /** 旭日图数据 */
6
6
  readonly data: any;
7
7
  /** 径向类型 */
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plots/sunburst/types.ts"],"names":[],"mappings":"","sourcesContent":["import { ColorAttr, Options, StyleAttr } from '../../types';\nimport { DrillDownCfg } from '../../types/drill-down';\nimport { HierarchyOption } from '../../utils/hierarchy/types';\n\nexport interface SunburstOptions extends Omit<Options, 'data' | 'legend' | 'slider' | 'scrollbar' | 'xAxis' | 'yAxis'> {\n /** 旭日图数据 */\n readonly data: any;\n /** 径向类型 */\n readonly reflect?: 'x' | 'y';\n\n // 样式\n /** 内径 */\n readonly innerRadius?: number;\n /** 半经 */\n readonly radius?: number;\n /** 颜色映射 */\n readonly colorField?: string;\n /** 颜色*/\n readonly color?: ColorAttr;\n /** 旭日图形样式 */\n readonly sunburstStyle?: StyleAttr;\n\n /** 层级布局配置 */\n readonly hierarchyConfig?: Omit<HierarchyOption, 'as' | 'type'> & {\n /** default: 'value', required data to be like: { name: 'xx', [field]: 12, children: [] } */\n readonly field?: string;\n /** 是否忽略父节点的权重, 默认: false, 其父节点的权重不由子节点权重总和决定 */\n readonly ignoreParentValue?: boolean;\n /** 默认展示的层级深度. 默认空, 代表全部展示. 取值 > 0 */\n readonly activeDepth?: number;\n };\n\n // 其他\n /** 额外的原始字段 */\n readonly rawFields?: string[];\n /** 下钻交互 */\n readonly drilldown?: DrillDownCfg;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plots/sunburst/types.ts"],"names":[],"mappings":"","sourcesContent":["import { ColorAttr, Options, StyleAttr } from '../../types';\nimport { DrillDownCfg } from '../../types/drill-down';\nimport { HierarchyOption } from '../../utils/hierarchy/types';\n\nexport interface SunburstOptions extends Omit<Options, 'data' | 'slider' | 'scrollbar' | 'xAxis' | 'yAxis'> {\n /** 旭日图数据 */\n readonly data: any;\n /** 径向类型 */\n readonly reflect?: 'x' | 'y';\n\n // 样式\n /** 内径 */\n readonly innerRadius?: number;\n /** 半经 */\n readonly radius?: number;\n /** 颜色映射 */\n readonly colorField?: string;\n /** 颜色*/\n readonly color?: ColorAttr;\n /** 旭日图形样式 */\n readonly sunburstStyle?: StyleAttr;\n\n /** 层级布局配置 */\n readonly hierarchyConfig?: Omit<HierarchyOption, 'as' | 'type'> & {\n /** default: 'value', required data to be like: { name: 'xx', [field]: 12, children: [] } */\n readonly field?: string;\n /** 是否忽略父节点的权重, 默认: false, 其父节点的权重不由子节点权重总和决定 */\n readonly ignoreParentValue?: boolean;\n /** 默认展示的层级深度. 默认空, 代表全部展示. 取值 > 0 */\n readonly activeDepth?: number;\n };\n\n // 其他\n /** 额外的原始字段 */\n readonly rawFields?: string[];\n /** 下钻交互 */\n readonly drilldown?: DrillDownCfg;\n}\n"]}
@@ -15,7 +15,7 @@ export interface VennOptions extends Options {
15
15
  /** 大小字段 */
16
16
  readonly sizeField: string;
17
17
  /** color */
18
- readonly color?: string | string[] | ((datum: Datum, defaultColor: string) => string);
18
+ readonly color?: string | string[] | ((datum: Datum, defaultColor?: string) => string);
19
19
  /** 并集合的颜色混合方式, 可选项: 参考 https://gka.github.io/chroma.js/#chroma-blend, 默认: multiply */
20
20
  readonly blendMode?: string;
21
21
  /** point 样式 */
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plots/venn/types.ts"],"names":[],"mappings":";;AAEA,uCAAkD","sourcesContent":["import { Types } from '@antv/g2';\nimport { Datum, Options, StyleAttr } from '../../types';\nimport { ID_FIELD, PATH_FIELD } from './constant';\n\nexport type VennData = (Types.Datum & { sets: string[]; [PATH_FIELD]: string; [ID_FIELD]: string })[];\n\n/** 配置类型定义 */\nexport interface VennOptions extends Options {\n /** 韦恩图 数据 */\n readonly data: Types.Datum[];\n /** 集合字段 */\n readonly setsField: string;\n /** 大小字段 */\n readonly sizeField: string;\n\n // 韦恩图 样式\n /** color */\n readonly color?: string | string[] | ((datum: Datum, defaultColor: string) => string);\n /** 并集合的颜色混合方式, 可选项: 参考 https://gka.github.io/chroma.js/#chroma-blend, 默认: multiply */\n readonly blendMode?: string;\n /** point 样式 */\n readonly pointStyle?: StyleAttr;\n}\n\nexport type CustomInfo = { offsetY: number; offsetX: number } & Pick<VennOptions, 'label'>;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plots/venn/types.ts"],"names":[],"mappings":";;AAEA,uCAAkD","sourcesContent":["import { Types } from '@antv/g2';\nimport { Datum, Options, StyleAttr } from '../../types';\nimport { ID_FIELD, PATH_FIELD } from './constant';\n\nexport type VennData = (Types.Datum & { sets: string[]; [PATH_FIELD]: string; [ID_FIELD]: string })[];\n\n/** 配置类型定义 */\nexport interface VennOptions extends Options {\n /** 韦恩图 数据 */\n readonly data: Types.Datum[];\n /** 集合字段 */\n readonly setsField: string;\n /** 大小字段 */\n readonly sizeField: string;\n\n // 韦恩图 样式\n /** color */\n readonly color?: string | string[] | ((datum: Datum, defaultColor?: string) => string);\n /** 并集合的颜色混合方式, 可选项: 参考 https://gka.github.io/chroma.js/#chroma-blend, 默认: multiply */\n readonly blendMode?: string;\n /** point 样式 */\n readonly pointStyle?: StyleAttr;\n}\n\nexport type CustomInfo = { offsetY: number; offsetX: number } & Pick<VennOptions, 'label'>;\n"]}
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;AACz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AAG,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,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,IA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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"]}