@visactor/vgrammar-plot 0.6.7-alpha.1 → 0.7.0-alpha.1

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 (109) hide show
  1. package/cjs/area.js +3 -3
  2. package/cjs/area.js.map +1 -1
  3. package/cjs/cell.js +3 -3
  4. package/cjs/cell.js.map +1 -1
  5. package/cjs/circle-packing.js +5 -6
  6. package/cjs/circle-packing.js.map +1 -1
  7. package/cjs/image.js +3 -3
  8. package/cjs/image.js.map +1 -1
  9. package/cjs/interval.js +3 -3
  10. package/cjs/interval.js.map +1 -1
  11. package/cjs/line.js +3 -3
  12. package/cjs/line.js.map +1 -1
  13. package/cjs/path.js +4 -1
  14. package/cjs/path.js.map +1 -1
  15. package/cjs/plot.d.ts +6 -4
  16. package/cjs/plot.js +24 -16
  17. package/cjs/plot.js.map +1 -1
  18. package/cjs/polygon.js +3 -3
  19. package/cjs/polygon.js.map +1 -1
  20. package/cjs/rect-x.js +3 -3
  21. package/cjs/rect-x.js.map +1 -1
  22. package/cjs/rect-y.js +3 -3
  23. package/cjs/rect-y.js.map +1 -1
  24. package/cjs/rect.js +3 -3
  25. package/cjs/rect.js.map +1 -1
  26. package/cjs/rule-x.js +3 -3
  27. package/cjs/rule-x.js.map +1 -1
  28. package/cjs/rule-y.d.ts +1 -1
  29. package/cjs/rule-y.js +14 -8
  30. package/cjs/rule-y.js.map +1 -1
  31. package/cjs/rule.js +3 -3
  32. package/cjs/rule.js.map +1 -1
  33. package/cjs/sankey.js +8 -10
  34. package/cjs/sankey.js.map +1 -1
  35. package/cjs/semantic-mark.d.ts +9 -4
  36. package/cjs/semantic-mark.js +113 -77
  37. package/cjs/semantic-mark.js.map +1 -1
  38. package/cjs/sunburst.js +5 -6
  39. package/cjs/sunburst.js.map +1 -1
  40. package/cjs/symbol.d.ts +3 -1
  41. package/cjs/symbol.js +25 -3
  42. package/cjs/symbol.js.map +1 -1
  43. package/cjs/text.js +5 -3
  44. package/cjs/text.js.map +1 -1
  45. package/cjs/tree.js +6 -7
  46. package/cjs/tree.js.map +1 -1
  47. package/cjs/treemap.js +5 -6
  48. package/cjs/treemap.js.map +1 -1
  49. package/cjs/wordcloud-shape.d.ts +1 -0
  50. package/cjs/wordcloud-shape.js +13 -8
  51. package/cjs/wordcloud-shape.js.map +1 -1
  52. package/cjs/wordcloud.js +5 -6
  53. package/cjs/wordcloud.js.map +1 -1
  54. package/dist/index.js +283 -126
  55. package/dist/index.min.js +1 -1
  56. package/es/area.js +3 -3
  57. package/es/area.js.map +1 -1
  58. package/es/cell.js +3 -3
  59. package/es/cell.js.map +1 -1
  60. package/es/circle-packing.js +6 -6
  61. package/es/circle-packing.js.map +1 -1
  62. package/es/image.js +3 -3
  63. package/es/image.js.map +1 -1
  64. package/es/interval.js +4 -4
  65. package/es/interval.js.map +1 -1
  66. package/es/line.js +3 -3
  67. package/es/line.js.map +1 -1
  68. package/es/path.js +4 -1
  69. package/es/path.js.map +1 -1
  70. package/es/plot.d.ts +6 -4
  71. package/es/plot.js +25 -17
  72. package/es/plot.js.map +1 -1
  73. package/es/polygon.js +3 -3
  74. package/es/polygon.js.map +1 -1
  75. package/es/rect-x.js +3 -3
  76. package/es/rect-x.js.map +1 -1
  77. package/es/rect-y.js +3 -3
  78. package/es/rect-y.js.map +1 -1
  79. package/es/rect.js +3 -3
  80. package/es/rect.js.map +1 -1
  81. package/es/rule-x.js +3 -3
  82. package/es/rule-x.js.map +1 -1
  83. package/es/rule-y.d.ts +1 -1
  84. package/es/rule-y.js +15 -7
  85. package/es/rule-y.js.map +1 -1
  86. package/es/rule.js +3 -3
  87. package/es/rule.js.map +1 -1
  88. package/es/sankey.js +9 -9
  89. package/es/sankey.js.map +1 -1
  90. package/es/semantic-mark.d.ts +9 -4
  91. package/es/semantic-mark.js +111 -77
  92. package/es/semantic-mark.js.map +1 -1
  93. package/es/sunburst.js +6 -6
  94. package/es/sunburst.js.map +1 -1
  95. package/es/symbol.d.ts +3 -1
  96. package/es/symbol.js +25 -3
  97. package/es/symbol.js.map +1 -1
  98. package/es/text.js +5 -3
  99. package/es/text.js.map +1 -1
  100. package/es/tree.js +7 -7
  101. package/es/tree.js.map +1 -1
  102. package/es/treemap.js +6 -6
  103. package/es/treemap.js.map +1 -1
  104. package/es/wordcloud-shape.d.ts +1 -0
  105. package/es/wordcloud-shape.js +15 -7
  106. package/es/wordcloud-shape.js.map +1 -1
  107. package/es/wordcloud.js +6 -6
  108. package/es/wordcloud.js.map +1 -1
  109. package/package.json +10 -10
package/es/rect.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/rect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAapE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,OAAO,gBAAiB,SAAQ,YAAqD;IAEzF,YAAY,EAAoB;QAC9B,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED,WAAW;QACT,OAAO,eAAe,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED,kBAAkB,CAChB,OAA2B,EAC3B,MAA+F;QAE/F,OAAO,IAAI,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAED,mBAAmB;QACjB,OAAO;YACL,CAAC,EAAE,EAAE,cAAc,EAAE,MAAM,EAAE;SAC9B,CAAC;IACJ,CAAC;IAED,iBAAiB;;QACf,MAAM,OAAO,GAAG,MAAA,IAAI,CAAC,IAAI,CAAC,MAAM,0CAAE,CAAC,CAAC;QACpC,OAAO;YACL,OAAO,EAAE,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AAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBAEpD,OAAO,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YAChC,CAAC,CAAC;SACH;QAED,IAAI,WAAW,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,EAAE;YAC1C,GAAG,CAAC,IAAI,GAAG,MAAA,WAAW,CAAC,KAAK,mCAAI,WAAW,CAAC,KAAK,CAAC;SACnD;aAAM;YACL,GAAG,CAAC,IAAI,GAAG,MAAA,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,IAAI,mCAAI,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;SACrD;QAED,OAAO,GAAG,CAAC;IACb,CAAC;;AA5Ge,qBAAI,GAAG,WAAW,CAAC,IAAI,CAAC","file":"rect.js","sourcesContent":["import { field as getFieldAccessor } from '@visactor/vgrammar-util';\nimport type {\n RectEncodeChannels,\n PlotRectEncoderSpec,\n SemanticTooltipOption,\n WithDefaultEncode,\n GenerateBaseEncodeSpec,\n CrosshairSpec,\n Nil,\n ScaleSpec,\n ValueOf,\n IElement\n} from '@visactor/vgrammar';\nimport { SemanticMark } from './semantic-mark';\nimport { getPalette, GrammarMarkType } from '@visactor/vgrammar';\nimport { isArray } from '@visactor/vutils';\nimport { PlotMakType } from './enums';\n\nexport class RectSemanticMark extends SemanticMark<PlotRectEncoderSpec, RectEncodeChannels> {\n static readonly type = PlotMakType.rect;\n constructor(id?: string | number) {\n super(PlotMakType.rect, id);\n }\n\n setMarkType() {\n return GrammarMarkType.rect;\n }\n\n parseScaleByEncode(\n channel: RectEncodeChannels,\n option: ValueOf<WithDefaultEncode<PlotRectEncoderSpec, RectEncodeChannels>, RectEncodeChannels>\n ): ScaleSpec | Nil {\n return this.parseScaleOfCommonEncode(channel, option);\n }\n\n setDefaultCrosshair(): Record<string, Pick<CrosshairSpec, 'crosshairShape' | 'crosshairType'>> {\n return {\n x: { crosshairShape: 'rect' }\n };\n }\n\n setDefaultTooltip(): SemanticTooltipOption | Nil {\n const encodeY = this.spec.encode?.y;\n return {\n content: isArray(encodeY)\n ? encodeY.map(entry => {\n return {\n value: entry\n };\n })\n : [\n {\n value: encodeY\n }\n ]\n };\n }\n\n convertMarkEncode(\n encode: WithDefaultEncode<PlotRectEncoderSpec, RectEncodeChannels>\n ): GenerateBaseEncodeSpec<PlotRectEncoderSpec> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n const scaleXId = this.getScaleId('x');\n const scaleYId = this.getScaleId('y');\n const res: GenerateBaseEncodeSpec<PlotRectEncoderSpec> = {};\n\n if (isArray(markEncoder.x?.field)) {\n res.x = { field: markEncoder.x.field[0], scale: markEncoder.x.scale };\n res.x1 = { field: markEncoder.x.field[1], scale: markEncoder.x.scale };\n } else {\n const xAccessor = getFieldAccessor(markEncoder.x.field);\n res.x = (datum: any, el: IElement, params: any) => {\n const xVals = xAccessor(datum);\n const scale = params[scaleXId];\n\n return isArray(xVals) ? scale.scale(xVals[0]) : scale.scale(xVals);\n };\n res.x1 = (datum: any, el: IElement, params: any) => {\n const scale = params[scaleXId];\n const xVals = xAccessor(datum);\n\n if (isArray(xVals) && xVals.length > 1) {\n return scale.scale(xVals[1]);\n }\n const domain = scale.domain();\n const min = Math.min.apply(null, domain);\n const max = Math.max.apply(null, domain);\n const baseValue = min > 0 ? min : max < 0 ? max : 0;\n\n return scale.scale(baseValue);\n };\n }\n\n if (isArray(markEncoder.y?.field)) {\n res.y = { field: markEncoder.y.field[0], scale: markEncoder.y.scale };\n res.y1 = { field: markEncoder.y.field[1], scale: markEncoder.y.scale };\n } else {\n const yAccessor = getFieldAccessor(markEncoder.y.field);\n res.y = (datum: any, el: IElement, params: any) => {\n const yVals = yAccessor(datum);\n const scale = params[scaleYId];\n\n return isArray(yVals) ? scale.scale(yVals[0]) : scale.scale(yVals);\n };\n res.y1 = (datum: any, el: IElement, params: any) => {\n const scale = params[scaleYId];\n const yVals = yAccessor(datum);\n\n if (isArray(yVals) && yVals.length > 1) {\n return scale.scale(yVals[1]);\n }\n const domain = scale.domain();\n const min = Math.min.apply(null, domain);\n const max = Math.max.apply(null, domain);\n const baseValue = min > 0 ? min : max < 0 ? max : 0;\n\n return scale.scale(baseValue);\n };\n }\n\n if (markEncoder.color || markEncoder.group) {\n res.fill = markEncoder.color ?? markEncoder.group;\n } else {\n res.fill = this.spec.style?.fill ?? getPalette()[0];\n }\n\n return res;\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/rect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAapE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,OAAO,gBAAiB,SAAQ,YAAqD;IAEzF,YAAY,EAAoB;QAC9B,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED,WAAW;QACT,OAAO,eAAe,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED,kBAAkB,CAChB,OAA2B,EAC3B,MAA+F;QAE/F,OAAO,IAAI,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAED,mBAAmB;QACjB,OAAO;YACL,CAAC,EAAE,EAAE,cAAc,EAAE,MAAM,EAAE;SAC9B,CAAC;IACJ,CAAC;IAED,iBAAiB;;QACf,MAAM,OAAO,GAAG,MAAA,IAAI,CAAC,IAAI,CAAC,MAAM,0CAAE,CAAC,CAAC;QACpC,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;gBACvB,CAAC,CAAC,OAAO,CAAC,G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C,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBAEpD,OAAO,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YAChC,CAAC,CAAC;SACH;QAED,IAAI,WAAW,CAAC,MAAM,EAAE;YACtB,GAAG,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;SACjC;QAED,IAAI,WAAW,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,EAAE;YAC1C,GAAG,CAAC,IAAI,GAAG,MAAA,WAAW,CAAC,KAAK,mCAAI,WAAW,CAAC,KAAK,CAAC;SACnD;aAAM;YACL,GAAG,CAAC,IAAI,GAAG,MAAA,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,IAAI,mCAAI,MAAA,IAAI,CAAC,UAAU,EAAE,0CAAG,CAAC,CAAC,CAAC;SAC5D;QAED,OAAO,GAAG,CAAC;IACb,CAAC;;AAhHe,qBAAI,GAAG,WAAW,CAAC,IAAI,CAAC","file":"rect.js","sourcesContent":["import { field as getFieldAccessor } from '@visactor/vgrammar-util';\nimport type {\n RectEncodeChannels,\n PlotRectEncoderSpec,\n SemanticTooltipOption,\n WithDefaultEncode,\n GenerateBaseEncodeSpec,\n CrosshairSpec,\n Nil,\n ScaleSpec,\n ValueOf,\n IElement\n} from '@visactor/vgrammar';\nimport { SemanticMark } from './semantic-mark';\n// eslint-disable-next-line no-duplicate-imports\nimport { GrammarMarkType } from '@visactor/vgrammar';\nimport { isArray } from '@visactor/vutils';\nimport { PlotMakType } from './enums';\n\nexport class RectSemanticMark extends SemanticMark<PlotRectEncoderSpec, RectEncodeChannels> {\n static readonly type = PlotMakType.rect;\n constructor(id?: string | number) {\n super(PlotMakType.rect, id);\n }\n\n setMarkType() {\n return GrammarMarkType.rect;\n }\n\n parseScaleByEncode(\n channel: RectEncodeChannels,\n option: ValueOf<WithDefaultEncode<PlotRectEncoderSpec, RectEncodeChannels>, RectEncodeChannels>\n ): ScaleSpec | Nil {\n return this.parseScaleOfCommonEncode(channel, option);\n }\n\n setDefaultCrosshair(): Record<string, Pick<CrosshairSpec, 'crosshairShape' | 'crosshairType'>> {\n return {\n x: { crosshairShape: 'rect' }\n };\n }\n\n setDefaultTooltip(): SemanticTooltipOption | Nil {\n const encodeY = this.spec.encode?.y;\n return {\n content: isArray(encodeY)\n ? encodeY.map(entry => {\n return {\n value: entry\n };\n })\n : [\n {\n value: encodeY\n }\n ]\n };\n }\n\n convertMarkEncode(\n encode: WithDefaultEncode<PlotRectEncoderSpec, RectEncodeChannels>\n ): GenerateBaseEncodeSpec<PlotRectEncoderSpec> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n const scaleXId = this.getScaleId('x');\n const scaleYId = this.getScaleId('y');\n const res: GenerateBaseEncodeSpec<PlotRectEncoderSpec> = {};\n\n if (isArray(markEncoder.x?.field)) {\n res.x = { field: markEncoder.x.field[0], scale: markEncoder.x.scale };\n res.x1 = { field: markEncoder.x.field[1], scale: markEncoder.x.scale };\n } else {\n const xAccessor = getFieldAccessor(markEncoder.x.field);\n res.x = (datum: any, el: IElement, params: any) => {\n const xVals = xAccessor(datum);\n const scale = params[scaleXId];\n\n return isArray(xVals) ? scale.scale(xVals[0]) : scale.scale(xVals);\n };\n res.x1 = (datum: any, el: IElement, params: any) => {\n const scale = params[scaleXId];\n const xVals = xAccessor(datum);\n\n if (isArray(xVals) && xVals.length > 1) {\n return scale.scale(xVals[1]);\n }\n const domain = scale.domain();\n const min = Math.min.apply(null, domain);\n const max = Math.max.apply(null, domain);\n const baseValue = min > 0 ? min : max < 0 ? max : 0;\n\n return scale.scale(baseValue);\n };\n }\n\n if (isArray(markEncoder.y?.field)) {\n res.y = { field: markEncoder.y.field[0], scale: markEncoder.y.scale };\n res.y1 = { field: markEncoder.y.field[1], scale: markEncoder.y.scale };\n } else {\n const yAccessor = getFieldAccessor(markEncoder.y.field);\n res.y = (datum: any, el: IElement, params: any) => {\n const yVals = yAccessor(datum);\n const scale = params[scaleYId];\n\n return isArray(yVals) ? scale.scale(yVals[0]) : scale.scale(yVals);\n };\n res.y1 = (datum: any, el: IElement, params: any) => {\n const scale = params[scaleYId];\n const yVals = yAccessor(datum);\n\n if (isArray(yVals) && yVals.length > 1) {\n return scale.scale(yVals[1]);\n }\n const domain = scale.domain();\n const min = Math.min.apply(null, domain);\n const max = Math.max.apply(null, domain);\n const baseValue = min > 0 ? min : max < 0 ? max : 0;\n\n return scale.scale(baseValue);\n };\n }\n\n if (markEncoder.stroke) {\n res.stroke = markEncoder.stroke;\n }\n\n if (markEncoder.color || markEncoder.group) {\n res.fill = markEncoder.color ?? markEncoder.group;\n } else {\n res.fill = this.spec.style?.fill ?? this.getPalette()?.[0];\n }\n\n return res;\n }\n}\n"]}
package/es/rule-x.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SemanticMark } from "./semantic-mark";
2
2
 
3
- import { getPalette, GrammarMarkType } from "@visactor/vgrammar";
3
+ import { GrammarMarkType } from "@visactor/vgrammar";
4
4
 
5
5
  import { PlotMakType } from "./enums";
6
6
 
@@ -19,14 +19,14 @@ export class RuleX extends SemanticMark {
19
19
  return this.parseScaleOfCommonEncode(channel, option);
20
20
  }
21
21
  convertMarkEncode(encode) {
22
- var _a, _b, _c;
22
+ var _a, _b, _c, _d;
23
23
  const markEncoder = this.convertSimpleMarkEncode(encode), res = {
24
24
  x: markEncoder.x,
25
25
  x1: markEncoder.x,
26
26
  y: (datum, el, params) => 0,
27
27
  y1: (datum, el, params) => params.viewBox.height()
28
28
  };
29
- return markEncoder.color || markEncoder.group ? res.stroke = null !== (_a = markEncoder.color) && void 0 !== _a ? _a : markEncoder.group : res.stroke = null !== (_c = null === (_b = this.spec.style) || void 0 === _b ? void 0 : _b.stroke) && void 0 !== _c ? _c : getPalette()[0],
29
+ return markEncoder.color || markEncoder.group ? res.stroke = null !== (_a = markEncoder.color) && void 0 !== _a ? _a : markEncoder.group : res.stroke = null !== (_c = null === (_b = this.spec.style) || void 0 === _b ? void 0 : _b.stroke) && void 0 !== _c ? _c : null === (_d = this.getPalette()) || void 0 === _d ? void 0 : _d[0],
30
30
  res;
31
31
  }
32
32
  }
package/es/rule-x.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/rule-x.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,OAAO,KAAM,SAAQ,YAA8D;IAEvF,YAAY,EAAoB;QAC9B,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC/B,CAAC;IAED,WAAW;QACT,OAAO,eAAe,CAAC,IAAI,CAAC;IAC9B,CAAC;IAES,mBAAmB,CAC3B,MAAyG;QAEzG,MAAM,GAAG,GAAG,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAE9C,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC;QACnB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,kBAAkB,CAChB,OAA4B,EAC5B,MAAyG;QAEzG,OAAO,IAAI,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAED,iBAAiB,CACf,MAA2E;;QAE3E,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAEzD,MAAM,GAAG,GAAG;YACV,CAAC,EAAE,WAAW,CAAC,CAAC;YAChB,EAAE,EAAE,WAAW,CAAC,CAAC;YACjB,CAAC,EAAE,CAAC,KAAU,EAAE,EAAY,EAAE,MAAW,EAAE,EAAE;gBAC3C,OAAO,CAAC,CAAC;YACX,CAAC;YACD,EAAE,EAAE,CAAC,KAAU,EAAE,EAAY,EAAE,MAAW,EAAE,EAAE;gBAC5C,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACjC,CAAC;SACkD,CAAC;QAEtD,IAAI,WAAW,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,EAAE;YAC1C,GAAG,CAAC,MAAM,GAAG,MAAA,WAAW,CAAC,KAAK,mCAAI,WAAW,CAAC,KAAK,CAAC;SACrD;aAAM;YACL,GAAG,CAAC,MAAM,GAAG,MAAA,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,MAAM,mCAAI,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;SACzD;QAED,OAAO,GAAG,CAAC;IACb,CAAC;;AAhDe,UAAI,GAAG,WAAW,CAAC,KAAK,CAAC","file":"rule-x.js","sourcesContent":["import type {\n RuleXEncodeChannels,\n WithDefaultEncode,\n BasicEncoderSpecMap,\n GenerateBaseEncodeSpec,\n GenerateEncoderSpec,\n IElement,\n Nil,\n ScaleSpec,\n ValueOf\n} from '@visactor/vgrammar';\nimport { SemanticMark } from './semantic-mark';\nimport { getPalette, GrammarMarkType } from '@visactor/vgrammar';\nimport { PlotMakType } from './enums';\n\nexport class RuleX extends SemanticMark<BasicEncoderSpecMap['rule'], RuleXEncodeChannels> {\n static readonly type = PlotMakType.ruleX;\n constructor(id?: string | number) {\n super(PlotMakType.ruleX, id);\n }\n\n setMarkType() {\n return GrammarMarkType.rule;\n }\n\n protected parseScaleOfEncodeX(\n option: ValueOf<WithDefaultEncode<BasicEncoderSpecMap['rule'], RuleXEncodeChannels>, RuleXEncodeChannels>\n ): ScaleSpec | Nil {\n const res = super.parseScaleOfEncodeX(option);\n\n res.type = 'point';\n return res;\n }\n\n parseScaleByEncode(\n channel: RuleXEncodeChannels,\n option: ValueOf<WithDefaultEncode<BasicEncoderSpecMap['rule'], RuleXEncodeChannels>, RuleXEncodeChannels>\n ): ScaleSpec | Nil {\n return this.parseScaleOfCommonEncode(channel, option);\n }\n\n convertMarkEncode(\n encode: WithDefaultEncode<BasicEncoderSpecMap['rule'], RuleXEncodeChannels>\n ): GenerateBaseEncodeSpec<BasicEncoderSpecMap['rule']> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n\n const res = {\n x: markEncoder.x,\n x1: markEncoder.x,\n y: (datum: any, el: IElement, params: any) => {\n return 0;\n },\n y1: (datum: any, el: IElement, params: any) => {\n return params.viewBox.height();\n }\n } as GenerateEncoderSpec<BasicEncoderSpecMap['rule']>;\n\n if (markEncoder.color || markEncoder.group) {\n res.stroke = markEncoder.color ?? markEncoder.group;\n } else {\n res.stroke = this.spec.style?.stroke ?? getPalette()[0];\n }\n\n return res;\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/rule-x.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,OAAO,KAAM,SAAQ,YAA8D;IAEvF,YAAY,EAAoB;QAC9B,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC/B,CAAC;IAED,WAAW;QACT,OAAO,eAAe,CAAC,IAAI,CAAC;IAC9B,CAAC;IAES,mBAAmB,CAC3B,MAAyG;QAEzG,MAAM,GAAG,GAAG,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAE9C,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC;QACnB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,kBAAkB,CAChB,OAA4B,EAC5B,MAAyG;QAEzG,OAAO,IAAI,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAED,iBAAiB,CACf,MAA2E;;QAE3E,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAEzD,MAAM,GAAG,GAAG;YACV,CAAC,EAAE,WAAW,CAAC,CAAC;YAChB,EAAE,EAAE,WAAW,CAAC,CAAC;YACjB,CAAC,EAAE,CAAC,KAAU,EAAE,EAAY,EAAE,MAAW,EAAE,EAAE;gBAC3C,OAAO,CAAC,CAAC;YACX,CAAC;YACD,EAAE,EAAE,CAAC,KAAU,EAAE,EAAY,EAAE,MAAW,EAAE,EAAE;gBAC5C,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACjC,CAAC;SACkD,CAAC;QAEtD,IAAI,WAAW,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,EAAE;YAC1C,GAAG,CAAC,MAAM,GAAG,MAAA,WAAW,CAAC,KAAK,mCAAI,WAAW,CAAC,KAAK,CAAC;SACrD;aAAM;YACL,GAAG,CAAC,MAAM,GAAG,MAAA,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,MAAM,mCAAI,MAAA,IAAI,CAAC,UAAU,EAAE,0CAAG,CAAC,CAAC,CAAC;SAChE;QAED,OAAO,GAAG,CAAC;IACb,CAAC;;AAhDe,UAAI,GAAG,WAAW,CAAC,KAAK,CAAC","file":"rule-x.js","sourcesContent":["import type {\n RuleXEncodeChannels,\n WithDefaultEncode,\n BasicEncoderSpecMap,\n GenerateBaseEncodeSpec,\n GenerateEncoderSpec,\n IElement,\n Nil,\n ScaleSpec,\n ValueOf\n} from '@visactor/vgrammar';\nimport { SemanticMark } from './semantic-mark';\n// eslint-disable-next-line no-duplicate-imports\nimport { GrammarMarkType } from '@visactor/vgrammar';\nimport { PlotMakType } from './enums';\n\nexport class RuleX extends SemanticMark<BasicEncoderSpecMap['rule'], RuleXEncodeChannels> {\n static readonly type = PlotMakType.ruleX;\n constructor(id?: string | number) {\n super(PlotMakType.ruleX, id);\n }\n\n setMarkType() {\n return GrammarMarkType.rule;\n }\n\n protected parseScaleOfEncodeX(\n option: ValueOf<WithDefaultEncode<BasicEncoderSpecMap['rule'], RuleXEncodeChannels>, RuleXEncodeChannels>\n ): ScaleSpec | Nil {\n const res = super.parseScaleOfEncodeX(option);\n\n res.type = 'point';\n return res;\n }\n\n parseScaleByEncode(\n channel: RuleXEncodeChannels,\n option: ValueOf<WithDefaultEncode<BasicEncoderSpecMap['rule'], RuleXEncodeChannels>, RuleXEncodeChannels>\n ): ScaleSpec | Nil {\n return this.parseScaleOfCommonEncode(channel, option);\n }\n\n convertMarkEncode(\n encode: WithDefaultEncode<BasicEncoderSpecMap['rule'], RuleXEncodeChannels>\n ): GenerateBaseEncodeSpec<BasicEncoderSpecMap['rule']> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n\n const res = {\n x: markEncoder.x,\n x1: markEncoder.x,\n y: (datum: any, el: IElement, params: any) => {\n return 0;\n },\n y1: (datum: any, el: IElement, params: any) => {\n return params.viewBox.height();\n }\n } as GenerateEncoderSpec<BasicEncoderSpecMap['rule']>;\n\n if (markEncoder.color || markEncoder.group) {\n res.stroke = markEncoder.color ?? markEncoder.group;\n } else {\n res.stroke = this.spec.style?.stroke ?? this.getPalette()?.[0];\n }\n\n return res;\n }\n}\n"]}
package/es/rule-y.d.ts CHANGED
@@ -3,7 +3,7 @@ import { SemanticMark } from './semantic-mark';
3
3
  import { GrammarMarkType } from '@visactor/vgrammar';
4
4
  import { PlotMakType } from './enums';
5
5
  export declare class RuleY extends SemanticMark<BasicEncoderSpecMap['rule'], RuleYEncodeChannels> {
6
- static readonly type = PlotMakType.ruleX;
6
+ static readonly type = PlotMakType.ruleY;
7
7
  constructor(id?: string | number);
8
8
  setMarkType(): GrammarMarkType;
9
9
  protected parseScaleOfEncodeX(option: ValueOf<WithDefaultEncode<BasicEncoderSpecMap['rule'], RuleYEncodeChannels>, RuleYEncodeChannels>): ScaleSpec | Nil;
package/es/rule-y.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import { SemanticMark } from "./semantic-mark";
2
2
 
3
- import { getPalette, GrammarMarkType } from "@visactor/vgrammar";
3
+ import { GrammarMarkType } from "@visactor/vgrammar";
4
4
 
5
5
  import { PlotMakType } from "./enums";
6
6
 
7
+ import { isArray } from "@visactor/vutils";
8
+
7
9
  export class RuleY extends SemanticMark {
8
10
  constructor(id) {
9
- super(PlotMakType.ruleX, id);
11
+ super(PlotMakType.ruleY, id);
10
12
  }
11
13
  setMarkType() {
12
14
  return GrammarMarkType.rule;
@@ -19,16 +21,22 @@ export class RuleY extends SemanticMark {
19
21
  return this.parseScaleOfCommonEncode(channel, option);
20
22
  }
21
23
  convertMarkEncode(encode) {
22
- var _a, _b, _c;
24
+ var _a, _b, _c, _d, _e, _f;
23
25
  const markEncoder = this.convertSimpleMarkEncode(encode), res = {
24
26
  y: markEncoder.y,
25
27
  y1: markEncoder.y,
26
- x: (datum, el, params) => 0,
27
- x1: (datum, el, params) => params.viewBox.width()
28
+ x: isArray(null === (_a = markEncoder.x) || void 0 === _a ? void 0 : _a.field) ? {
29
+ field: markEncoder.x.field[0],
30
+ scale: markEncoder.x.scale
31
+ } : (datum, el, params) => 0,
32
+ x1: isArray(null === (_b = markEncoder.x) || void 0 === _b ? void 0 : _b.field) ? {
33
+ field: markEncoder.x.field[1],
34
+ scale: markEncoder.x.scale
35
+ } : (datum, el, params) => params.viewBox.width()
28
36
  };
29
- return markEncoder.color || markEncoder.group ? res.stroke = null !== (_a = markEncoder.color) && void 0 !== _a ? _a : markEncoder.group : res.stroke = null !== (_c = null === (_b = this.spec.style) || void 0 === _b ? void 0 : _b.stroke) && void 0 !== _c ? _c : getPalette()[0],
37
+ return markEncoder.color || markEncoder.group ? res.stroke = null !== (_c = markEncoder.color) && void 0 !== _c ? _c : markEncoder.group : res.stroke = null !== (_e = null === (_d = this.spec.style) || void 0 === _d ? void 0 : _d.stroke) && void 0 !== _e ? _e : null === (_f = this.getPalette()) || void 0 === _f ? void 0 : _f[0],
30
38
  res;
31
39
  }
32
40
  }
33
41
 
34
- RuleY.type = PlotMakType.ruleX;
42
+ RuleY.type = PlotMakType.ruleY;
package/es/rule-y.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/rule-y.ts"],"names":[],"mappings":"AAWA,OAAO,EAA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D;aAAM;YACL,GAAG,CAAC,MAAM,GAAG,MAAA,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,MAAM,mCAAI,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;SACzD;QAED,OAAO,GAAG,CAAC;IACb,CAAC;;AAhDe,UAAI,GAAG,WAAW,CAAC,KAAK,CAAC","file":"rule-y.js","sourcesContent":["import type {\n RuleYEncodeChannels,\n WithDefaultEncode,\n BasicEncoderSpecMap,\n GenerateBaseEncodeSpec,\n GenerateEncoderSpec,\n IElement,\n Nil,\n ScaleSpec,\n ValueOf\n} from '@visactor/vgrammar';\nimport { SemanticMark } from './semantic-mark';\nimport { getPalette, GrammarMarkType } from '@visactor/vgrammar';\nimport { PlotMakType } from './enums';\n\nexport class RuleY extends SemanticMark<BasicEncoderSpecMap['rule'], RuleYEncodeChannels> {\n static readonly type = PlotMakType.ruleX;\n constructor(id?: string | number) {\n super(PlotMakType.ruleX, id);\n }\n\n setMarkType() {\n return GrammarMarkType.rule;\n }\n\n protected parseScaleOfEncodeX(\n option: ValueOf<WithDefaultEncode<BasicEncoderSpecMap['rule'], RuleYEncodeChannels>, RuleYEncodeChannels>\n ): ScaleSpec | Nil {\n const res = super.parseScaleOfEncodeX(option);\n\n res.type = 'point';\n return res;\n }\n\n parseScaleByEncode(\n channel: RuleYEncodeChannels,\n option: ValueOf<WithDefaultEncode<BasicEncoderSpecMap['rule'], RuleYEncodeChannels>, RuleYEncodeChannels>\n ): ScaleSpec | Nil {\n return this.parseScaleOfCommonEncode(channel, option);\n }\n\n convertMarkEncode(\n encode: WithDefaultEncode<BasicEncoderSpecMap['rule'], RuleYEncodeChannels>\n ): GenerateBaseEncodeSpec<BasicEncoderSpecMap['rule']> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n\n const res = {\n y: markEncoder.y,\n y1: markEncoder.y,\n x: (datum: any, el: IElement, params: any) => {\n return 0;\n },\n x1: (datum: any, el: IElement, params: any) => {\n return params.viewBox.width();\n }\n } as GenerateEncoderSpec<BasicEncoderSpecMap['rule']>;\n\n if (markEncoder.color || markEncoder.group) {\n res.stroke = markEncoder.color ?? markEncoder.group;\n } else {\n res.stroke = this.spec.style?.stroke ?? getPalette()[0];\n }\n\n return res;\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/rule-y.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,MAAM,OAAO,KAAM,SAAQ,YAA8D;IAEvF,YAAY,EAAoB;QAC9B,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC/B,CAAC;IAED,WAAW;QACT,OAAO,eAAe,CAAC,IAAI,CAAC;IAC9B,CAAC;IAES,mBAAmB,CAC3B,MAAyG;QAEzG,MAAM,GAAG,GAAG,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAE9C,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC;QACnB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,kBAAkB,CAChB,OAA4B,EAC5B,MAAyG;QAEzG,OAAO,IAAI,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAED,iBAAiB,CACf,MAA2E;;QAE3E,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;QAEzD,MAAM,GAAG,GAAG;YACV,CAAC,EAAE,WAAW,CAAC,CAAC;YAChB,EAAE,EAAE,WAAW,CAAC,CAAC;YACjB,CAAC,EAAE,OAAO,CAAC,MAAA,WAAW,CAAC,CAAC,0CAAE,KAAK,CAAC;gBAC9B,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE;gBAC/D,CAAC,CAAC,CAAC,KAAU,EAAE,EAAY,EAAE,MAAW,EAAE,EAAE;oBACxC,OAAO,CAAC,CAAC;gBACX,CAAC;YACL,EAAE,EAAE,OAAO,CAAC,MAAA,WAAW,CAAC,CAAC,0CAAE,KAAK,CAAC;gBAC/B,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE;gBAC/D,CAAC,CAAC,CAAC,KAAU,EAAE,EAAY,EAAE,MAAW,EAAE,EAAE;oBACxC,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;gBAChC,CAAC;SAC8C,CAAC;QAEtD,IAAI,WAAW,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,EAAE;YAC1C,GAAG,CAAC,MAAM,GAAG,MAAA,WAAW,CAAC,KAAK,mCAAI,WAAW,CAAC,KAAK,CAAC;SACrD;aAAM;YACL,GAAG,CAAC,MAAM,GAAG,MAAA,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,MAAM,mCAAI,MAAA,IAAI,CAAC,UAAU,EAAE,0CAAG,CAAC,CAAC,CAAC;SAChE;QAED,OAAO,GAAG,CAAC;IACb,CAAC;;AApDe,UAAI,GAAG,WAAW,CAAC,KAAK,CAAC","file":"rule-y.js","sourcesContent":["import type {\n RuleYEncodeChannels,\n WithDefaultEncode,\n BasicEncoderSpecMap,\n GenerateBaseEncodeSpec,\n GenerateEncoderSpec,\n IElement,\n Nil,\n ScaleSpec,\n ValueOf\n} from '@visactor/vgrammar';\nimport { SemanticMark } from './semantic-mark';\n// eslint-disable-next-line no-duplicate-imports\nimport { GrammarMarkType } from '@visactor/vgrammar';\nimport { PlotMakType } from './enums';\nimport { isArray } from '@visactor/vutils';\n\nexport class RuleY extends SemanticMark<BasicEncoderSpecMap['rule'], RuleYEncodeChannels> {\n static readonly type = PlotMakType.ruleY;\n constructor(id?: string | number) {\n super(PlotMakType.ruleY, id);\n }\n\n setMarkType() {\n return GrammarMarkType.rule;\n }\n\n protected parseScaleOfEncodeX(\n option: ValueOf<WithDefaultEncode<BasicEncoderSpecMap['rule'], RuleYEncodeChannels>, RuleYEncodeChannels>\n ): ScaleSpec | Nil {\n const res = super.parseScaleOfEncodeX(option);\n\n res.type = 'point';\n return res;\n }\n\n parseScaleByEncode(\n channel: RuleYEncodeChannels,\n option: ValueOf<WithDefaultEncode<BasicEncoderSpecMap['rule'], RuleYEncodeChannels>, RuleYEncodeChannels>\n ): ScaleSpec | Nil {\n return this.parseScaleOfCommonEncode(channel, option);\n }\n\n convertMarkEncode(\n encode: WithDefaultEncode<BasicEncoderSpecMap['rule'], RuleYEncodeChannels>\n ): GenerateBaseEncodeSpec<BasicEncoderSpecMap['rule']> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n\n const res = {\n y: markEncoder.y,\n y1: markEncoder.y,\n x: isArray(markEncoder.x?.field)\n ? { field: markEncoder.x.field[0], scale: markEncoder.x.scale }\n : (datum: any, el: IElement, params: any) => {\n return 0;\n },\n x1: isArray(markEncoder.x?.field)\n ? { field: markEncoder.x.field[1], scale: markEncoder.x.scale }\n : (datum: any, el: IElement, params: any) => {\n return params.viewBox.width();\n }\n } as GenerateEncoderSpec<BasicEncoderSpecMap['rule']>;\n\n if (markEncoder.color || markEncoder.group) {\n res.stroke = markEncoder.color ?? markEncoder.group;\n } else {\n res.stroke = this.spec.style?.stroke ?? this.getPalette()?.[0];\n }\n\n return res;\n }\n}\n"]}
package/es/rule.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SemanticMark } from "./semantic-mark";
2
2
 
3
- import { getPalette, GrammarMarkType } from "@visactor/vgrammar";
3
+ import { GrammarMarkType } from "@visactor/vgrammar";
4
4
 
5
5
  import { isArray } from "@visactor/vutils";
6
6
 
@@ -21,7 +21,7 @@ export class Rule extends SemanticMark {
21
21
  return this.parseScaleOfCommonEncode(channel, option);
22
22
  }
23
23
  convertMarkEncode(encode) {
24
- var _a, _b, _c, _d, _e;
24
+ var _a, _b, _c, _d, _e, _f;
25
25
  const markEncoder = this.convertSimpleMarkEncode(encode);
26
26
  let res;
27
27
  return isArray(null === (_a = markEncoder.x) || void 0 === _a ? void 0 : _a.field) ? (res.x = {
@@ -36,7 +36,7 @@ export class Rule extends SemanticMark {
36
36
  }, res.y1 = {
37
37
  field: markEncoder.y.field[1],
38
38
  scale: markEncoder.y.scale
39
- }) : res.y = res.y1 = markEncoder.y, markEncoder.color || markEncoder.group ? res.stroke = null !== (_c = markEncoder.color) && void 0 !== _c ? _c : markEncoder.group : res.stroke = null !== (_e = null === (_d = this.spec.style) || void 0 === _d ? void 0 : _d.stroke) && void 0 !== _e ? _e : getPalette()[0],
39
+ }) : res.y = res.y1 = markEncoder.y, markEncoder.color || markEncoder.group ? res.stroke = null !== (_c = markEncoder.color) && void 0 !== _c ? _c : markEncoder.group : res.stroke = null !== (_e = null === (_d = this.spec.style) || void 0 === _d ? void 0 : _d.stroke) && void 0 !== _e ? _e : null === (_f = this.getPalette()) || void 0 === _f ? void 0 : _f[0],
40
40
  res;
41
41
  }
42
42
  }
package/es/rule.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/rule.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,OAAO,IAAK,SAAQ,YAAqD;IAE7E,YAAY,EAAoB;QAC9B,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IA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AE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;SACxE;aAAM;YACL,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC;SAChC;QAED,IAAI,WAAW,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,EAAE;YAC1C,GAAG,CAAC,MAAM,GAAG,MAAA,WAAW,CAAC,KAAK,mCAAI,WAAW,CAAC,KAAK,CAAC;SACrD;aAAM;YACL,GAAG,CAAC,MAAM,GAAG,MAAA,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,MAAM,mCAAI,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;SACzD;QAED,OAAO,GAAG,CAAC;IACb,CAAC;;AArDe,SAAI,GAAG,WAAW,CAAC,IAAI,CAAC","file":"rule.js","sourcesContent":["import type {\n RuleEncodeChannels,\n WithDefaultEncode,\n PlotRuleEncoderSpec,\n GenerateBaseEncodeSpec,\n GenerateEncoderSpec,\n Nil,\n ScaleSpec,\n ValueOf\n} from '@visactor/vgrammar';\nimport { SemanticMark } from './semantic-mark';\nimport { getPalette, GrammarMarkType } from '@visactor/vgrammar';\nimport { isArray } from '@visactor/vutils';\nimport { PlotMakType } from './enums';\n\nexport class Rule extends SemanticMark<PlotRuleEncoderSpec, RuleEncodeChannels> {\n static readonly type = PlotMakType.rule;\n constructor(id?: string | number) {\n super(PlotMakType.rule, id);\n }\n\n setMarkType() {\n return GrammarMarkType.rule;\n }\n\n protected parseScaleOfEncodeX(\n option: ValueOf<WithDefaultEncode<PlotRuleEncoderSpec, RuleEncodeChannels>, RuleEncodeChannels>\n ): ScaleSpec | Nil {\n const res = super.parseScaleOfEncodeX(option);\n\n res.type = 'point';\n return res;\n }\n\n parseScaleByEncode(\n channel: RuleEncodeChannels,\n option: ValueOf<WithDefaultEncode<PlotRuleEncoderSpec, RuleEncodeChannels>, RuleEncodeChannels>\n ): ScaleSpec | Nil {\n return this.parseScaleOfCommonEncode(channel, option);\n }\n\n convertMarkEncode(\n encode: WithDefaultEncode<PlotRuleEncoderSpec, RuleEncodeChannels>\n ): GenerateBaseEncodeSpec<PlotRuleEncoderSpec> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n\n let res: GenerateEncoderSpec<PlotRuleEncoderSpec>;\n\n if (isArray(markEncoder.x?.field)) {\n res.x = { field: markEncoder.x.field[0], scale: markEncoder.x.scale };\n res.x1 = { field: markEncoder.x.field[1], scale: markEncoder.x.scale };\n } else {\n res.x = res.x1 = markEncoder.x;\n }\n\n if (isArray(markEncoder.y?.field)) {\n res.y = { field: markEncoder.y.field[0], scale: markEncoder.y.scale };\n res.y1 = { field: markEncoder.y.field[1], scale: markEncoder.y.scale };\n } else {\n res.y = res.y1 = markEncoder.y;\n }\n\n if (markEncoder.color || markEncoder.group) {\n res.stroke = markEncoder.color ?? markEncoder.group;\n } else {\n res.stroke = this.spec.style?.stroke ?? getPalette()[0];\n }\n\n return res;\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/rule.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,OAAO,IAAK,SAAQ,YAAqD;IAE7E,YAAY,EAAoB;QAC9B,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED,WAAW;QACT,OAAO,eAAe,CAAC,IAAI,CAAC;IAC9B,CAAC;IAES,mBAAmB,CAC3B,MAA+F;QAE/F,MAAM,GAAG,GAAG,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAE9C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AC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC;SAChC;QAED,IAAI,WAAW,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,EAAE;YAC1C,GAAG,CAAC,MAAM,GAAG,MAAA,WAAW,CAAC,KAAK,mCAAI,WAAW,CAAC,KAAK,CAAC;SACrD;aAAM;YACL,GAAG,CAAC,MAAM,GAAG,MAAA,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,MAAM,mCAAI,MAAA,IAAI,CAAC,UAAU,EAAE,0CAAG,CAAC,CAAC,CAAC;SAChE;QAED,OAAO,GAAG,CAAC;IACb,CAAC;;AArDe,SAAI,GAAG,WAAW,CAAC,IAAI,CAAC","file":"rule.js","sourcesContent":["import type {\n RuleEncodeChannels,\n WithDefaultEncode,\n PlotRuleEncoderSpec,\n GenerateBaseEncodeSpec,\n GenerateEncoderSpec,\n Nil,\n ScaleSpec,\n ValueOf\n} from '@visactor/vgrammar';\nimport { SemanticMark } from './semantic-mark';\n// eslint-disable-next-line no-duplicate-imports\nimport { GrammarMarkType } from '@visactor/vgrammar';\nimport { isArray } from '@visactor/vutils';\nimport { PlotMakType } from './enums';\n\nexport class Rule extends SemanticMark<PlotRuleEncoderSpec, RuleEncodeChannels> {\n static readonly type = PlotMakType.rule;\n constructor(id?: string | number) {\n super(PlotMakType.rule, id);\n }\n\n setMarkType() {\n return GrammarMarkType.rule;\n }\n\n protected parseScaleOfEncodeX(\n option: ValueOf<WithDefaultEncode<PlotRuleEncoderSpec, RuleEncodeChannels>, RuleEncodeChannels>\n ): ScaleSpec | Nil {\n const res = super.parseScaleOfEncodeX(option);\n\n res.type = 'point';\n return res;\n }\n\n parseScaleByEncode(\n channel: RuleEncodeChannels,\n option: ValueOf<WithDefaultEncode<PlotRuleEncoderSpec, RuleEncodeChannels>, RuleEncodeChannels>\n ): ScaleSpec | Nil {\n return this.parseScaleOfCommonEncode(channel, option);\n }\n\n convertMarkEncode(\n encode: WithDefaultEncode<PlotRuleEncoderSpec, RuleEncodeChannels>\n ): GenerateBaseEncodeSpec<PlotRuleEncoderSpec> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n\n let res: GenerateEncoderSpec<PlotRuleEncoderSpec>;\n\n if (isArray(markEncoder.x?.field)) {\n res.x = { field: markEncoder.x.field[0], scale: markEncoder.x.scale };\n res.x1 = { field: markEncoder.x.field[1], scale: markEncoder.x.scale };\n } else {\n res.x = res.x1 = markEncoder.x;\n }\n\n if (isArray(markEncoder.y?.field)) {\n res.y = { field: markEncoder.y.field[0], scale: markEncoder.y.scale };\n res.y1 = { field: markEncoder.y.field[1], scale: markEncoder.y.scale };\n } else {\n res.y = res.y1 = markEncoder.y;\n }\n\n if (markEncoder.color || markEncoder.group) {\n res.stroke = markEncoder.color ?? markEncoder.group;\n } else {\n res.stroke = this.spec.style?.stroke ?? this.getPalette()?.[0];\n }\n\n return res;\n }\n}\n"]}
package/es/sankey.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SemanticMark } from "./semantic-mark";
2
2
 
3
- import { getPalette, GrammarMarkType, SIGNAL_VIEW_BOX, getTransform, getGlyph } from "@visactor/vgrammar";
3
+ import { GrammarMarkType, SIGNAL_VIEW_BOX, Factory } from "@visactor/vgrammar";
4
4
 
5
5
  import { PlotMakType } from "./enums";
6
6
 
@@ -8,8 +8,8 @@ import { field as getFieldAccessor } from "@visactor/vgrammar-util";
8
8
 
9
9
  export class SankeySemanticMark extends SemanticMark {
10
10
  constructor(id) {
11
- super(PlotMakType.sankey, id), getTransform(PlotMakType.sankey) || this._logger.error("Please add this line of code: import { registerSankeyTransforms } from '@visactor/vgrammar-sankey'; \n and run registerSankeyTransforms() before use sankey"),
12
- getGlyph("linkPath") || this._logger.error("\n Please add this line of code: import { registerLinkPathGlyph } from '@visactor/vgrammar';\n add run registerLinkPathGlyph() before use sankey\n ");
11
+ super(PlotMakType.sankey, id), Factory.getTransform(PlotMakType.sankey) || this._logger.error("Please add this line of code: import { registerSankeyTransforms } from '@visactor/vgrammar-sankey'; \n and run registerSankeyTransforms() before use sankey"),
12
+ Factory.getGlyph("linkPath") || this._logger.error("\n Please add this line of code: import { registerLinkPathGlyph } from '@visactor/vgrammar';\n add run registerLinkPathGlyph() before use sankey\n ");
13
13
  }
14
14
  setMarkType() {
15
15
  return GrammarMarkType.rect;
@@ -57,11 +57,11 @@ export class SankeySemanticMark extends SemanticMark {
57
57
  data: this.getDataIdOfFiltered(),
58
58
  field: option
59
59
  },
60
- range: getPalette()
60
+ range: this.getPalette()
61
61
  } : null;
62
62
  }
63
63
  convertMarkEncode(encode) {
64
- var _a, _b, _c;
64
+ var _a, _b, _c, _d;
65
65
  const markEncoder = this.convertSimpleMarkEncode(encode), res = {
66
66
  x: {
67
67
  field: "x0"
@@ -76,10 +76,10 @@ export class SankeySemanticMark extends SemanticMark {
76
76
  field: "y1"
77
77
  }
78
78
  };
79
- if (markEncoder.color) {
79
+ if (markEncoder.stroke && (res.stroke = markEncoder.stroke), markEncoder.color) {
80
80
  const scaleColorId = this.getScaleId("color"), colorAccessor = getFieldAccessor(markEncoder.color.field);
81
81
  res.fill = (datum, el, params) => params[scaleColorId].scale(colorAccessor(null == datum ? void 0 : datum.datum));
82
- } else res.fill = null !== (_c = null === (_b = null === (_a = this.spec.style) || void 0 === _a ? void 0 : _a.nodeStyle) || void 0 === _b ? void 0 : _b.fill) && void 0 !== _c ? _c : getPalette()[0];
82
+ } else res.fill = null !== (_c = null === (_b = null === (_a = this.spec.style) || void 0 === _a ? void 0 : _a.nodeStyle) || void 0 === _b ? void 0 : _b.fill) && void 0 !== _c ? _c : null === (_d = this.getPalette()) || void 0 === _d ? void 0 : _d[0];
83
83
  return res;
84
84
  }
85
85
  setMainMarkSpec() {
@@ -117,7 +117,7 @@ export class SankeySemanticMark extends SemanticMark {
117
117
  round: !0
118
118
  }, null === (_a = this.spec.style) || void 0 === _a ? void 0 : _a.linkStyle),
119
119
  update: (datum, el, params) => {
120
- var _a, _b, _c;
120
+ var _a, _b, _c, _d;
121
121
  return {
122
122
  direction: datum.vertical ? "vertical" : "horizontal",
123
123
  x0: datum.x0,
@@ -125,7 +125,7 @@ export class SankeySemanticMark extends SemanticMark {
125
125
  y0: datum.y0,
126
126
  y1: datum.y1,
127
127
  thickness: datum.thickness,
128
- fill: null !== (_c = null === (_b = null === (_a = this.spec.style) || void 0 === _a ? void 0 : _a.linkStyle) || void 0 === _b ? void 0 : _b.fill) && void 0 !== _c ? _c : getPalette()[0]
128
+ fill: null !== (_c = null === (_b = null === (_a = this.spec.style) || void 0 === _a ? void 0 : _a.linkStyle) || void 0 === _b ? void 0 : _b.fill) && void 0 !== _c ? _c : null === (_d = this.getPalette()) || void 0 === _d ? void 0 : _d[0]
129
129
  };
130
130
  }
131
131
  })
package/es/sankey.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sankey.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1G,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,KAAK,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGpE,MAAM,OAAO,kBAAmB,SAAQ,YAAyD;IAE/F,YAAY,EAAoB;QAC9B,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAE9B,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;YACrC,IAAI,CAAC,OAAO,CAAC,KAAK,CAChB;6DACqD,CACtD,CAAC;SACH;QAED,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;YACzB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;;;OAGlB,CAAC,CAAC;SACJ;IACH,CAAC;IAED,WAAW;QACT,OAAO,eAAe,CAAC,IAAI,CA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,CAAC,EAAE;4BACZ,EAAE,EAAE,KAAK,CAAC,EAAE;4BACZ,EAAE,EAAE,KAAK,CAAC,EAAE;4BACZ,SAAS,EAAE,KAAK,CAAC,SAAS;4BAC1B,IAAI,EAAE,MAAA,MAAA,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,SAAS,0CAAE,IAAI,mCAAI,UAAU,EAAE,CAAC,CAAC,CAAC;yBAC1D,CAAC;oBACJ,CAAC;iBACF,CAAC;aACH;SACF,CAAC;IACJ,CAAC;;AAzKe,uBAAI,GAAG,WAAW,CAAC,MAAM,CAAC","file":"sankey.js","sourcesContent":["import type {\n SankeyEncodeChannels,\n WithDefaultEncode,\n PlotSankeyEncoderSpec,\n SemanticLabelOption,\n ChannelEncodeType,\n DataSpec,\n GenerateBaseEncodeSpec,\n GenerateEncoderSpec,\n Nil,\n ScaleSpec,\n ValueOf,\n TransformSpec,\n IElement\n} from '@visactor/vgrammar';\nimport { SemanticMark } from './semantic-mark';\nimport { getPalette, GrammarMarkType, SIGNAL_VIEW_BOX, getTransform, getGlyph } from '@visactor/vgrammar';\nimport { PlotMakType } from './enums';\nimport { field as getFieldAccessor } from '@visactor/vgrammar-util';\nimport type { ITextAttribute } from '@visactor/vrender';\n\nexport class SankeySemanticMark extends SemanticMark<PlotSankeyEncoderSpec, SankeyEncodeChannels> {\n static readonly type = PlotMakType.sankey;\n constructor(id?: string | number) {\n super(PlotMakType.sankey, id);\n\n if (!getTransform(PlotMakType.sankey)) {\n this._logger.error(\n `Please add this line of code: import { registerSankeyTransforms } from '@visactor/vgrammar-sankey'; \n and run registerSankeyTransforms() before use sankey`\n );\n }\n\n if (!getGlyph('linkPath')) {\n this._logger.error(`\n Please add this line of code: import { registerLinkPathGlyph } from '@visactor/vgrammar';\n add run registerLinkPathGlyph() before use sankey\n `);\n }\n }\n\n setMarkType() {\n return GrammarMarkType.rect;\n }\n\n setDefaultDataTransform(): TransformSpec[] {\n return [\n {\n type: 'sankey',\n width: { signal: 'viewWidth' },\n height: { signal: 'viewHeight' },\n nodeKey: this.spec.encode?.node\n }\n ];\n }\n\n getDataIdOfLink() {\n return `${this.spec.data?.id ?? this.spec.id}-data-link`;\n }\n\n setMultipleData(): DataSpec[] {\n return [\n {\n id: this.getDataIdOfFiltered(),\n transform: [\n {\n type: 'map',\n all: true,\n callback: (datum: any) => {\n return datum[0].nodes;\n }\n }\n ]\n },\n {\n source: this.getDataIdOfMain(),\n id: this.getDataIdOfLink(),\n transform: [\n {\n type: 'map',\n all: true,\n callback: (datum: any) => {\n // return formatLinkPath(datum[0].links);\n return datum[0].links;\n }\n }\n ]\n }\n ];\n }\n\n parseScaleByEncode(\n channel: SankeyEncodeChannels,\n option: ValueOf<WithDefaultEncode<PlotSankeyEncoderSpec, SankeyEncodeChannels>, SankeyEncodeChannels>\n ): ScaleSpec | Nil {\n if (channel === 'color') {\n return {\n type: 'ordinal',\n id: this.getScaleId('color'),\n domain: {\n data: this.getDataIdOfFiltered(),\n field: option as string\n },\n range: getPalette()\n };\n }\n\n return null;\n }\n\n convertMarkEncode(\n encode: WithDefaultEncode<PlotSankeyEncoderSpec, SankeyEncodeChannels>\n ): GenerateBaseEncodeSpec<PlotSankeyEncoderSpec> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n\n const res: GenerateEncoderSpec<PlotSankeyEncoderSpec> = {\n x: { field: 'x0' },\n x1: { field: 'x1' },\n y: { field: 'y0' },\n y1: { field: 'y1' }\n };\n\n if (markEncoder.color) {\n const scaleColorId = this.getScaleId('color');\n const colorAccessor = getFieldAccessor(markEncoder.color.field);\n\n res.fill = (datum: any, el: IElement, params: any) => {\n const scale = params[scaleColorId];\n return scale.scale(colorAccessor(datum?.datum));\n };\n } else {\n res.fill = this.spec.style?.nodeStyle?.fill ?? getPalette()[0];\n }\n\n return res;\n }\n\n setMainMarkSpec() {\n return { key: 'key' };\n }\n\n protected setLabelTextGetter(\n channel: string,\n option: SemanticLabelOption | boolean\n ): ChannelEncodeType<ITextAttribute['text']> {\n const textGetter = getFieldAccessor(channel);\n return (datum: any, el: IElement, params: any) => {\n return textGetter(datum.datum);\n };\n }\n\n setMultiMarksSpec() {\n // TODO: optimize the default style\n return [\n {\n id: `${this.getMarkId()}-link`,\n type: 'glyph',\n glyphType: 'linkPath',\n from: {\n data: this.getDataIdOfLink()\n },\n layout: {\n position: 'content',\n skipBeforeLayouted: true\n },\n key: 'index',\n dependency: this.viewSpec.scales.map(scale => scale.id).concat(SIGNAL_VIEW_BOX),\n animation: this.convertMarkAnimation(),\n encode: Object.assign({}, this.spec.state, {\n enter: Object.assign(\n {\n backgroundStyle: { fillColor: '#ccc', fillOpacity: 0.2 },\n fillOpacity: 0.8,\n round: true\n },\n this.spec.style?.linkStyle\n ),\n update: (datum: any, el: IElement, params: any) => {\n return {\n direction: datum.vertical ? 'vertical' : 'horizontal',\n x0: datum.x0,\n x1: datum.x1,\n y0: datum.y0,\n y1: datum.y1,\n thickness: datum.thickness,\n fill: this.spec.style?.linkStyle?.fill ?? getPalette()[0]\n };\n }\n })\n }\n ];\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/sankey.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,KAAK,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGpE,MAAM,OAAO,kBAAmB,SAAQ,YAAyD;IAE/F,YAAY,EAAoB;QAC9B,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAE9B,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;YAC7C,IAAI,CAAC,OAAO,CAAC,KAAK,CAChB;6DACqD,CACtD,CAAC;SACH;QAED,IAAI,CA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qBACZ,EACD,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,SAAS,CAC3B;oBACD,MAAM,EAAE,CAAC,KAAU,EAAE,EAAY,EAAE,MAAW,EAAE,EAAE;;wBAChD,OAAO;4BACL,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY;4BACrD,EAAE,EAAE,KAAK,CAAC,EAAE;4BACZ,EAAE,EAAE,KAAK,CAAC,EAAE;4BACZ,EAAE,EAAE,KAAK,CAAC,EAAE;4BACZ,EAAE,EAAE,KAAK,CAAC,EAAE;4BACZ,SAAS,EAAE,KAAK,CAAC,SAAS;4BAC1B,IAAI,EAAE,MAAA,MAAA,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,SAAS,0CAAE,IAAI,mCAAI,MAAA,IAAI,CAAC,UAAU,EAAE,0CAAG,CAAC,CAAC;yBACjE,CAAC;oBACJ,CAAC;iBACF,CAAC;aACH;SACF,CAAC;IACJ,CAAC;;AA7Ke,uBAAI,GAAG,WAAW,CAAC,MAAM,CAAC","file":"sankey.js","sourcesContent":["import type {\n SankeyEncodeChannels,\n WithDefaultEncode,\n PlotSankeyEncoderSpec,\n SemanticLabelOption,\n ChannelEncodeType,\n DataSpec,\n GenerateBaseEncodeSpec,\n GenerateEncoderSpec,\n Nil,\n ScaleSpec,\n ValueOf,\n TransformSpec,\n IElement\n} from '@visactor/vgrammar';\nimport { SemanticMark } from './semantic-mark';\n// eslint-disable-next-line no-duplicate-imports\nimport { GrammarMarkType, SIGNAL_VIEW_BOX, Factory } from '@visactor/vgrammar';\nimport { PlotMakType } from './enums';\nimport { field as getFieldAccessor } from '@visactor/vgrammar-util';\nimport type { ITextAttribute } from '@visactor/vrender';\n\nexport class SankeySemanticMark extends SemanticMark<PlotSankeyEncoderSpec, SankeyEncodeChannels> {\n static readonly type = PlotMakType.sankey;\n constructor(id?: string | number) {\n super(PlotMakType.sankey, id);\n\n if (!Factory.getTransform(PlotMakType.sankey)) {\n this._logger.error(\n `Please add this line of code: import { registerSankeyTransforms } from '@visactor/vgrammar-sankey'; \n and run registerSankeyTransforms() before use sankey`\n );\n }\n\n if (!Factory.getGlyph('linkPath')) {\n this._logger.error(`\n Please add this line of code: import { registerLinkPathGlyph } from '@visactor/vgrammar';\n add run registerLinkPathGlyph() before use sankey\n `);\n }\n }\n\n setMarkType() {\n return GrammarMarkType.rect;\n }\n\n setDefaultDataTransform(): TransformSpec[] {\n return [\n {\n type: 'sankey',\n width: { signal: 'viewWidth' },\n height: { signal: 'viewHeight' },\n nodeKey: this.spec.encode?.node\n }\n ];\n }\n\n getDataIdOfLink() {\n return `${this.spec.data?.id ?? this.spec.id}-data-link`;\n }\n\n setMultipleData(): DataSpec[] {\n return [\n {\n id: this.getDataIdOfFiltered(),\n transform: [\n {\n type: 'map',\n all: true,\n callback: (datum: any) => {\n return datum[0].nodes;\n }\n }\n ]\n },\n {\n source: this.getDataIdOfMain(),\n id: this.getDataIdOfLink(),\n transform: [\n {\n type: 'map',\n all: true,\n callback: (datum: any) => {\n // return formatLinkPath(datum[0].links);\n return datum[0].links;\n }\n }\n ]\n }\n ];\n }\n\n parseScaleByEncode(\n channel: SankeyEncodeChannels,\n option: ValueOf<WithDefaultEncode<PlotSankeyEncoderSpec, SankeyEncodeChannels>, SankeyEncodeChannels>\n ): ScaleSpec | Nil {\n if (channel === 'color') {\n return {\n type: 'ordinal',\n id: this.getScaleId('color'),\n domain: {\n data: this.getDataIdOfFiltered(),\n field: option as string\n },\n range: this.getPalette()\n };\n }\n\n return null;\n }\n\n convertMarkEncode(\n encode: WithDefaultEncode<PlotSankeyEncoderSpec, SankeyEncodeChannels>\n ): GenerateBaseEncodeSpec<PlotSankeyEncoderSpec> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n\n const res: GenerateEncoderSpec<PlotSankeyEncoderSpec> = {\n x: { field: 'x0' },\n x1: { field: 'x1' },\n y: { field: 'y0' },\n y1: { field: 'y1' }\n };\n\n if (markEncoder.stroke) {\n res.stroke = markEncoder.stroke;\n }\n\n if (markEncoder.color) {\n const scaleColorId = this.getScaleId('color');\n const colorAccessor = getFieldAccessor(markEncoder.color.field);\n\n res.fill = (datum: any, el: IElement, params: any) => {\n const scale = params[scaleColorId];\n return scale.scale(colorAccessor(datum?.datum));\n };\n } else {\n res.fill = this.spec.style?.nodeStyle?.fill ?? this.getPalette()?.[0];\n }\n\n return res;\n }\n\n setMainMarkSpec() {\n return { key: 'key' };\n }\n\n protected setLabelTextGetter(\n channel: string,\n option: SemanticLabelOption | boolean\n ): ChannelEncodeType<ITextAttribute['text']> {\n const textGetter = getFieldAccessor(channel);\n return (datum: any, el: IElement, params: any) => {\n return textGetter(datum.datum);\n };\n }\n\n setMultiMarksSpec() {\n // TODO: optimize the default style\n return [\n {\n id: `${this.getMarkId()}-link`,\n type: 'glyph',\n glyphType: 'linkPath',\n from: {\n data: this.getDataIdOfLink()\n },\n layout: {\n position: 'content',\n skipBeforeLayouted: true\n },\n key: 'index',\n dependency: this.viewSpec.scales.map(scale => scale.id).concat(SIGNAL_VIEW_BOX),\n animation: this.convertMarkAnimation(),\n encode: Object.assign({}, this.spec.state, {\n enter: Object.assign(\n {\n backgroundStyle: { fillColor: '#ccc', fillOpacity: 0.2 },\n fillOpacity: 0.8,\n round: true\n },\n this.spec.style?.linkStyle\n ),\n update: (datum: any, el: IElement, params: any) => {\n return {\n direction: datum.vertical ? 'vertical' : 'horizontal',\n x0: datum.x0,\n x1: datum.x1,\n y0: datum.y0,\n y1: datum.y1,\n thickness: datum.thickness,\n fill: this.spec.style?.linkStyle?.fill ?? this.getPalette()?.[0]\n };\n }\n })\n }\n ];\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { ILogger } from '@visactor/vutils';
2
- import type { ISemanticMark, ISemanticMarkSpec, ParsedSimpleEncode, WithDefaultEncode, SemanticTooltipOption, SemanticAxisOption, SemanticPlayerOption, SemanticLabelOption, SemanticDataZoomOption, SemanticSliderOption, SemanticLegendOption, SemanticCrosshairOption, CoordinateOption, AxisSpec, CrosshairSpec, DatazoomSpec, DimensionTooltipSpec, LabelSpec, LegendSpec, PlayerSpec, SliderSpec, TooltipSpec, CoordinateSpec, DataSpec, ChannelEncodeType, ScaleSpec, TransformSpec, MarkAnimationSpec, ViewSpec, MarkType, Nil, ValueOf, GenerateBaseEncodeSpec, IAnimationConfig, MarkSpec, MarkRelativeItemSpec } from '@visactor/vgrammar';
2
+ import type { ISemanticMark, ISemanticMarkSpec, ParsedSimpleEncode, WithDefaultEncode, SemanticTooltipOption, SemanticAxisOption, SemanticPlayerOption, SemanticLabelOption, SemanticDataZoomOption, SemanticSliderOption, SemanticLegendOption, SemanticCrosshairOption, CoordinateOption, AxisSpec, CrosshairSpec, DatazoomSpec, DimensionTooltipSpec, LabelSpec, LegendSpec, PlayerSpec, SliderSpec, TooltipSpec, CoordinateSpec, DataSpec, ChannelEncodeType, ScaleSpec, TransformSpec, MarkAnimationSpec, ViewSpec, MarkType, Nil, ValueOf, GenerateBaseEncodeSpec, IAnimationConfig, MarkSpec, MarkRelativeItemSpec, IPlot } from '@visactor/vgrammar';
3
3
  import type { ITextAttribute } from '@visactor/vrender';
4
4
  export declare abstract class SemanticMark<EncodeSpec, K extends string> implements ISemanticMark<EncodeSpec, K> {
5
5
  spec: ISemanticMarkSpec<EncodeSpec, K>;
@@ -8,7 +8,8 @@ export declare abstract class SemanticMark<EncodeSpec, K extends string> impleme
8
8
  protected _logger: ILogger;
9
9
  protected _coordinate: CoordinateOption;
10
10
  readonly type: string;
11
- constructor(type: string, id?: string | number);
11
+ readonly plot: IPlot;
12
+ constructor(type: string, id?: string | number, plot?: IPlot);
12
13
  parseSpec(spec: Partial<ISemanticMarkSpec<EncodeSpec, K>>): this;
13
14
  coordinate(option: CoordinateOption): this;
14
15
  data(values: any, transform?: TransformSpec[], id?: string): this;
@@ -26,13 +27,14 @@ export declare abstract class SemanticMark<EncodeSpec, K extends string> impleme
26
27
  datazoom(channel: string, option?: SemanticDataZoomOption | boolean, layout?: MarkRelativeItemSpec): this;
27
28
  label(channel: string, option?: SemanticLabelOption | boolean): this;
28
29
  player(data?: any[], option?: SemanticPlayerOption | boolean, layout?: MarkRelativeItemSpec): this;
30
+ protected getPalette(): import("@visactor/vrender").IColor[];
29
31
  abstract setMarkType(): MarkType;
30
32
  abstract parseScaleByEncode(channel: K, option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): ScaleSpec | Nil;
31
33
  abstract convertMarkEncode(encode: WithDefaultEncode<EncodeSpec, K>): GenerateBaseEncodeSpec<EncodeSpec>;
32
34
  protected setDefaultDataTransform(): TransformSpec[];
33
35
  protected setMultipleData(): DataSpec[];
34
36
  protected setDefaultMarkTransform(): TransformSpec[];
35
- protected convertMarkTransform(userTransform: TransformSpec[], defaultTransform?: TransformSpec[]): TransformSpec[];
37
+ protected convertMarkTransform(userTransform: TransformSpec[], defaultTransform?: TransformSpec[]): any[];
36
38
  protected convertMarkAnimation(): MarkAnimationSpec;
37
39
  protected convertSimpleMarkEncode(encode: WithDefaultEncode<EncodeSpec, K>): ParsedSimpleEncode<EncodeSpec, K>;
38
40
  protected getDataIdOfFiltered(): string;
@@ -48,6 +50,7 @@ export declare abstract class SemanticMark<EncodeSpec, K extends string> impleme
48
50
  protected parseScaleOfEncodeX(option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): ScaleSpec | Nil;
49
51
  protected parseScaleOfEncodeY(option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): ScaleSpec | Nil;
50
52
  protected parseScaleOfEncodeColor(option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): ScaleSpec | Nil;
53
+ protected parseScaleOfEncodeStroke(option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): ScaleSpec | Nil;
51
54
  protected parseScaleOfEncodeGroup(option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): ScaleSpec | Nil;
52
55
  protected parseScaleOfCommonEncode(channel: K, option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): ScaleSpec | Nil;
53
56
  protected setDefaultAxis(): Record<string, Partial<AxisSpec>>;
@@ -78,7 +81,9 @@ export declare abstract class SemanticMark<EncodeSpec, K extends string> impleme
78
81
  protected setDefaultPlayer(): Record<string, Partial<PlayerSpec>>;
79
82
  protected parsePlayerSpec(): PlayerSpec[];
80
83
  protected parseDataSpec(): DataSpec[];
81
- protected parseScaleSpec(): ScaleSpec[];
84
+ protected parseScaleSpec(): (ScaleSpec & {
85
+ userScale?: ScaleSpec;
86
+ })[];
82
87
  protected parseCoordinateSpec(): CoordinateSpec[];
83
88
  protected setMainMarkEnterEncode(): Partial<any>;
84
89
  protected setMainMarkSpec(): {};