@visactor/vgrammar-plot 0.6.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 (173) hide show
  1. package/README.md +3 -0
  2. package/README.zh-CN.md +0 -0
  3. package/cjs/area.d.ts +14 -0
  4. package/cjs/area.js +83 -0
  5. package/cjs/area.js.map +1 -0
  6. package/cjs/cell.d.ts +14 -0
  7. package/cjs/cell.js +51 -0
  8. package/cjs/cell.js.map +1 -0
  9. package/cjs/circle-packing.d.ts +17 -0
  10. package/cjs/circle-packing.js +76 -0
  11. package/cjs/circle-packing.js.map +1 -0
  12. package/cjs/enums.d.ts +24 -0
  13. package/cjs/enums.js +17 -0
  14. package/cjs/enums.js.map +1 -0
  15. package/cjs/image.d.ts +13 -0
  16. package/cjs/image.js +77 -0
  17. package/cjs/image.js.map +1 -0
  18. package/cjs/index.d.ts +1 -0
  19. package/cjs/index.js +15 -0
  20. package/cjs/index.js.map +1 -0
  21. package/cjs/interval.d.ts +19 -0
  22. package/cjs/interval.js +102 -0
  23. package/cjs/interval.js.map +1 -0
  24. package/cjs/line.d.ts +14 -0
  25. package/cjs/line.js +52 -0
  26. package/cjs/line.js.map +1 -0
  27. package/cjs/path.d.ts +11 -0
  28. package/cjs/path.js +25 -0
  29. package/cjs/path.js.map +1 -0
  30. package/cjs/plot-all.d.ts +2 -0
  31. package/cjs/plot-all.js +19 -0
  32. package/cjs/plot-all.js.map +1 -0
  33. package/cjs/plot.d.ts +46 -0
  34. package/cjs/plot.js +265 -0
  35. package/cjs/plot.js.map +1 -0
  36. package/cjs/polygon.d.ts +12 -0
  37. package/cjs/polygon.js +44 -0
  38. package/cjs/polygon.js.map +1 -0
  39. package/cjs/rect-x.d.ts +13 -0
  40. package/cjs/rect-x.js +67 -0
  41. package/cjs/rect-x.js.map +1 -0
  42. package/cjs/rect-y.d.ts +13 -0
  43. package/cjs/rect-y.js +67 -0
  44. package/cjs/rect-y.js.map +1 -0
  45. package/cjs/rect.d.ts +13 -0
  46. package/cjs/rect.js +82 -0
  47. package/cjs/rect.js.map +1 -0
  48. package/cjs/rule-x.d.ts +12 -0
  49. package/cjs/rule-x.js +37 -0
  50. package/cjs/rule-x.js.map +1 -0
  51. package/cjs/rule-y.d.ts +12 -0
  52. package/cjs/rule-y.js +36 -0
  53. package/cjs/rule-y.js.map +1 -0
  54. package/cjs/rule.d.ts +12 -0
  55. package/cjs/rule.js +45 -0
  56. package/cjs/rule.js.map +1 -0
  57. package/cjs/sankey.d.ts +46 -0
  58. package/cjs/sankey.js +139 -0
  59. package/cjs/sankey.js.map +1 -0
  60. package/cjs/semantic-mark.d.ts +88 -0
  61. package/cjs/semantic-mark.js +846 -0
  62. package/cjs/semantic-mark.js.map +1 -0
  63. package/cjs/sunburst.d.ts +45 -0
  64. package/cjs/sunburst.js +134 -0
  65. package/cjs/sunburst.js.map +1 -0
  66. package/cjs/symbol.d.ts +13 -0
  67. package/cjs/symbol.js +53 -0
  68. package/cjs/symbol.js.map +1 -0
  69. package/cjs/text.d.ts +12 -0
  70. package/cjs/text.js +32 -0
  71. package/cjs/text.js.map +1 -0
  72. package/cjs/tree.d.ts +20 -0
  73. package/cjs/tree.js +128 -0
  74. package/cjs/tree.js.map +1 -0
  75. package/cjs/treemap.d.ts +41 -0
  76. package/cjs/treemap.js +109 -0
  77. package/cjs/treemap.js.map +1 -0
  78. package/cjs/util.d.ts +3 -0
  79. package/cjs/util.js +11 -0
  80. package/cjs/util.js.map +1 -0
  81. package/cjs/wordcloud-shape.d.ts +13 -0
  82. package/cjs/wordcloud-shape.js +85 -0
  83. package/cjs/wordcloud-shape.js.map +1 -0
  84. package/cjs/wordcloud.d.ts +13 -0
  85. package/cjs/wordcloud.js +81 -0
  86. package/cjs/wordcloud.js.map +1 -0
  87. package/dist/index.js +3291 -0
  88. package/dist/index.min.js +1 -0
  89. package/es/area.d.ts +14 -0
  90. package/es/area.js +83 -0
  91. package/es/area.js.map +1 -0
  92. package/es/cell.d.ts +14 -0
  93. package/es/cell.js +49 -0
  94. package/es/cell.js.map +1 -0
  95. package/es/circle-packing.d.ts +17 -0
  96. package/es/circle-packing.js +75 -0
  97. package/es/circle-packing.js.map +1 -0
  98. package/es/enums.d.ts +24 -0
  99. package/es/enums.js +13 -0
  100. package/es/enums.js.map +1 -0
  101. package/es/image.d.ts +13 -0
  102. package/es/image.js +74 -0
  103. package/es/image.js.map +1 -0
  104. package/es/index.d.ts +1 -0
  105. package/es/index.js +2 -0
  106. package/es/index.js.map +1 -0
  107. package/es/interval.d.ts +19 -0
  108. package/es/interval.js +103 -0
  109. package/es/interval.js.map +1 -0
  110. package/es/line.d.ts +14 -0
  111. package/es/line.js +50 -0
  112. package/es/line.js.map +1 -0
  113. package/es/path.d.ts +11 -0
  114. package/es/path.js +23 -0
  115. package/es/path.js.map +1 -0
  116. package/es/plot-all.d.ts +2 -0
  117. package/es/plot-all.js +50 -0
  118. package/es/plot-all.js.map +1 -0
  119. package/es/plot.d.ts +46 -0
  120. package/es/plot.js +263 -0
  121. package/es/plot.js.map +1 -0
  122. package/es/polygon.d.ts +12 -0
  123. package/es/polygon.js +43 -0
  124. package/es/polygon.js.map +1 -0
  125. package/es/rect-x.d.ts +13 -0
  126. package/es/rect-x.js +69 -0
  127. package/es/rect-x.js.map +1 -0
  128. package/es/rect-y.d.ts +13 -0
  129. package/es/rect-y.js +69 -0
  130. package/es/rect-y.js.map +1 -0
  131. package/es/rect.d.ts +13 -0
  132. package/es/rect.js +84 -0
  133. package/es/rect.js.map +1 -0
  134. package/es/rule-x.d.ts +12 -0
  135. package/es/rule-x.js +35 -0
  136. package/es/rule-x.js.map +1 -0
  137. package/es/rule-y.d.ts +12 -0
  138. package/es/rule-y.js +34 -0
  139. package/es/rule-y.js.map +1 -0
  140. package/es/rule.d.ts +12 -0
  141. package/es/rule.js +45 -0
  142. package/es/rule.js.map +1 -0
  143. package/es/sankey.d.ts +46 -0
  144. package/es/sankey.js +137 -0
  145. package/es/sankey.js.map +1 -0
  146. package/es/semantic-mark.d.ts +88 -0
  147. package/es/semantic-mark.js +833 -0
  148. package/es/semantic-mark.js.map +1 -0
  149. package/es/sunburst.d.ts +45 -0
  150. package/es/sunburst.js +133 -0
  151. package/es/sunburst.js.map +1 -0
  152. package/es/symbol.d.ts +13 -0
  153. package/es/symbol.js +51 -0
  154. package/es/symbol.js.map +1 -0
  155. package/es/text.d.ts +12 -0
  156. package/es/text.js +30 -0
  157. package/es/text.js.map +1 -0
  158. package/es/tree.d.ts +20 -0
  159. package/es/tree.js +127 -0
  160. package/es/tree.js.map +1 -0
  161. package/es/treemap.d.ts +41 -0
  162. package/es/treemap.js +108 -0
  163. package/es/treemap.js.map +1 -0
  164. package/es/util.d.ts +3 -0
  165. package/es/util.js +3 -0
  166. package/es/util.js.map +1 -0
  167. package/es/wordcloud-shape.d.ts +13 -0
  168. package/es/wordcloud-shape.js +84 -0
  169. package/es/wordcloud-shape.js.map +1 -0
  170. package/es/wordcloud.d.ts +13 -0
  171. package/es/wordcloud.js +80 -0
  172. package/es/wordcloud.js.map +1 -0
  173. package/package.json +73 -0
package/cjs/sankey.js ADDED
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.SankeySemanticMark = void 0;
6
+
7
+ const semantic_mark_1 = require("./semantic-mark"), vgrammar_1 = require("@visactor/vgrammar"), enums_1 = require("./enums"), vgrammar_util_1 = require("@visactor/vgrammar-util");
8
+
9
+ class SankeySemanticMark extends semantic_mark_1.SemanticMark {
10
+ constructor(id) {
11
+ super(enums_1.PlotMakType.sankey, id), (0, vgrammar_1.getTransform)(enums_1.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
+ (0, vgrammar_1.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
+ }
14
+ setMarkType() {
15
+ return vgrammar_1.GrammarMarkType.rect;
16
+ }
17
+ setDefaultDataTransform() {
18
+ var _a;
19
+ return [ {
20
+ type: "sankey",
21
+ width: {
22
+ signal: "viewWidth"
23
+ },
24
+ height: {
25
+ signal: "viewHeight"
26
+ },
27
+ nodeKey: null === (_a = this.spec.encode) || void 0 === _a ? void 0 : _a.node
28
+ } ];
29
+ }
30
+ getDataIdOfLink() {
31
+ var _a, _b;
32
+ return `${null !== (_b = null === (_a = this.spec.data) || void 0 === _a ? void 0 : _a.id) && void 0 !== _b ? _b : this.spec.id}-data-link`;
33
+ }
34
+ setMultipleData() {
35
+ return [ {
36
+ id: this.getDataIdOfFiltered(),
37
+ transform: [ {
38
+ type: "map",
39
+ all: !0,
40
+ callback: datum => datum[0].nodes
41
+ } ]
42
+ }, {
43
+ source: this.getDataIdOfMain(),
44
+ id: this.getDataIdOfLink(),
45
+ transform: [ {
46
+ type: "map",
47
+ all: !0,
48
+ callback: datum => datum[0].links
49
+ } ]
50
+ } ];
51
+ }
52
+ parseScaleByEncode(channel, option) {
53
+ return "color" === channel ? {
54
+ type: "ordinal",
55
+ id: this.getScaleId("color"),
56
+ domain: {
57
+ data: this.getDataIdOfFiltered(),
58
+ field: option
59
+ },
60
+ range: (0, vgrammar_1.getPalette)()
61
+ } : null;
62
+ }
63
+ convertMarkEncode(encode) {
64
+ var _a, _b, _c;
65
+ const markEncoder = this.convertSimpleMarkEncode(encode), res = {
66
+ x: {
67
+ field: "x0"
68
+ },
69
+ x1: {
70
+ field: "x1"
71
+ },
72
+ y: {
73
+ field: "y0"
74
+ },
75
+ y1: {
76
+ field: "y1"
77
+ }
78
+ };
79
+ if (markEncoder.color) {
80
+ const scaleColorId = this.getScaleId("color"), colorAccessor = (0, vgrammar_util_1.field)(markEncoder.color.field);
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 : (0,
83
+ vgrammar_1.getPalette)()[0];
84
+ return res;
85
+ }
86
+ setMainMarkSpec() {
87
+ return {
88
+ key: "key"
89
+ };
90
+ }
91
+ setLabelTextGetter(channel, option) {
92
+ const textGetter = (0, vgrammar_util_1.field)(channel);
93
+ return (datum, el, params) => textGetter(datum.datum);
94
+ }
95
+ setMultiMarksSpec() {
96
+ var _a;
97
+ return [ {
98
+ id: `${this.getMarkId()}-link`,
99
+ type: "glyph",
100
+ glyphType: "linkPath",
101
+ from: {
102
+ data: this.getDataIdOfLink()
103
+ },
104
+ layout: {
105
+ position: "content",
106
+ skipBeforeLayouted: !0
107
+ },
108
+ key: "index",
109
+ dependency: this.viewSpec.scales.map((scale => scale.id)).concat(vgrammar_1.SIGNAL_VIEW_BOX),
110
+ animation: this.convertMarkAnimation(),
111
+ encode: Object.assign({}, this.spec.state, {
112
+ enter: Object.assign({
113
+ backgroundStyle: {
114
+ fillColor: "#ccc",
115
+ fillOpacity: .2
116
+ },
117
+ fillOpacity: .8,
118
+ round: !0
119
+ }, null === (_a = this.spec.style) || void 0 === _a ? void 0 : _a.linkStyle),
120
+ update: (datum, el, params) => {
121
+ var _a, _b, _c;
122
+ return {
123
+ direction: datum.vertical ? "vertical" : "horizontal",
124
+ x0: datum.x0,
125
+ x1: datum.x1,
126
+ y0: datum.y0,
127
+ y1: datum.y1,
128
+ thickness: datum.thickness,
129
+ 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 : (0,
130
+ vgrammar_1.getPalette)()[0]
131
+ };
132
+ }
133
+ })
134
+ } ];
135
+ }
136
+ }
137
+
138
+ exports.SankeySemanticMark = SankeySemanticMark, SankeySemanticMark.type = enums_1.PlotMakType.sankey;
139
+ //# sourceMappingURL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AC/E,SAAS,EAAE,IAAI,CAAC,oBAAoB,EAAE;gBACtC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;oBACzC,KAAK,EAAE,MAAM,CAAC,MAAM,CAClB;wBACE,eAAe,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE;wBACxD,WAAW,EAAE,GAAG;wBAChB,KAAK,EAAE,IAAI;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,IAAA,qBAAU,GAAE,CAAC,CAAC,CAAC;yBAC1D,CAAC;oBACJ,CAAC;iBACF,CAAC;aACH;SACF,CAAC;IACJ,CAAC;;AA1KH,gDA2KC;AA1KiB,uBAAI,GAAG,mBAAW,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"]}
@@ -0,0 +1,88 @@
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';
3
+ import type { ITextAttribute } from '@visactor/vrender';
4
+ export declare abstract class SemanticMark<EncodeSpec, K extends string> implements ISemanticMark<EncodeSpec, K> {
5
+ spec: ISemanticMarkSpec<EncodeSpec, K>;
6
+ viewSpec?: ViewSpec;
7
+ readonly uid: number;
8
+ protected _logger: ILogger;
9
+ protected _coordinate: CoordinateOption;
10
+ readonly type: string;
11
+ constructor(type: string, id?: string | number);
12
+ parseSpec(spec: Partial<ISemanticMarkSpec<EncodeSpec, K>>): this;
13
+ coordinate(option: CoordinateOption): this;
14
+ data(values: any, transform?: TransformSpec[], id?: string): this;
15
+ encode(channel: K, option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): this;
16
+ scale(channel: string, option: Partial<ScaleSpec>): this;
17
+ style(style: Partial<EncodeSpec & any>): this;
18
+ transform(option: TransformSpec | TransformSpec[]): this;
19
+ state(state: string, option: Partial<EncodeSpec>): this;
20
+ animate(state: string, option: IAnimationConfig | IAnimationConfig[]): this;
21
+ axis(channel: string, option?: SemanticAxisOption | boolean, layout?: MarkRelativeItemSpec): this;
22
+ legend(channel: string, option?: SemanticLegendOption | boolean, layout?: MarkRelativeItemSpec): this;
23
+ crosshair(channel: string, option?: SemanticCrosshairOption | boolean): this;
24
+ tooltip(option: SemanticTooltipOption | boolean): this;
25
+ slider(channel: string, option?: SemanticSliderOption | boolean, layout?: MarkRelativeItemSpec): this;
26
+ datazoom(channel: string, option?: SemanticDataZoomOption | boolean, layout?: MarkRelativeItemSpec): this;
27
+ label(channel: string, option?: SemanticLabelOption | boolean): this;
28
+ player(data?: any[], option?: SemanticPlayerOption | boolean, layout?: MarkRelativeItemSpec): this;
29
+ abstract setMarkType(): MarkType;
30
+ abstract parseScaleByEncode(channel: K, option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): ScaleSpec | Nil;
31
+ abstract convertMarkEncode(encode: WithDefaultEncode<EncodeSpec, K>): GenerateBaseEncodeSpec<EncodeSpec>;
32
+ protected setDefaultDataTransform(): TransformSpec[];
33
+ protected setMultipleData(): DataSpec[];
34
+ protected setDefaultMarkTransform(): TransformSpec[];
35
+ protected convertMarkTransform(userTransform: TransformSpec[], defaultTransform?: TransformSpec[]): TransformSpec[];
36
+ protected convertMarkAnimation(): MarkAnimationSpec;
37
+ protected convertSimpleMarkEncode(encode: WithDefaultEncode<EncodeSpec, K>): ParsedSimpleEncode<EncodeSpec, K>;
38
+ protected getDataIdOfFiltered(): string;
39
+ protected getDataIdOfMain(): string;
40
+ protected getDataIdOfPlayer(): string;
41
+ protected getDataZoomScaleId(channel: string): {
42
+ x: string;
43
+ y: string;
44
+ };
45
+ protected getScaleId(channel: string): any;
46
+ protected getMarkId(): string;
47
+ protected getScaleSpec(scaleId: string): ScaleSpec;
48
+ protected parseScaleOfEncodeX(option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): ScaleSpec | Nil;
49
+ protected parseScaleOfEncodeY(option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): ScaleSpec | Nil;
50
+ protected parseScaleOfEncodeColor(option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): ScaleSpec | Nil;
51
+ protected parseScaleOfEncodeGroup(option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): ScaleSpec | Nil;
52
+ protected parseScaleOfCommonEncode(channel: K, option: ValueOf<WithDefaultEncode<EncodeSpec, K>, K>): ScaleSpec | Nil;
53
+ protected setDefaultAxis(): Record<string, Partial<AxisSpec>>;
54
+ protected parseAxisSpec(): AxisSpec[];
55
+ protected parseOption<T>(spec: {
56
+ option: T | boolean;
57
+ layout?: MarkRelativeItemSpec;
58
+ } | T | boolean): {
59
+ option: boolean | T;
60
+ layout: MarkRelativeItemSpec;
61
+ };
62
+ protected setDefaultLegend(): Record<string, Partial<LegendSpec>>;
63
+ protected parseLegendSpec(): LegendSpec[];
64
+ protected setDefaultCrosshair(): Record<string, Pick<CrosshairSpec, 'crosshairShape' | 'crosshairType'>>;
65
+ protected getVisualChannel(channel: 'x' | 'y'): 'x' | 'y' | 'angle' | 'radius';
66
+ protected parseCrosshairSpec(): CrosshairSpec[];
67
+ protected setDefaultTooltip(): SemanticTooltipOption | Nil;
68
+ protected parseTooltipSpec(): Array<TooltipSpec | DimensionTooltipSpec> | Nil;
69
+ protected setDefaultSlider(): Record<string, Partial<SliderSpec>>;
70
+ protected parseSliderSpec(): SliderSpec[];
71
+ protected setDefaultDataZoom(): Record<string, Partial<DatazoomSpec>>;
72
+ protected getVisiualPositionByDimension(channel: string): "left" | "bottom";
73
+ protected parseDataZoomSpec(): DatazoomSpec[];
74
+ protected setDefaultLabel(): Record<string, Partial<LabelSpec>>;
75
+ protected getLabelPosition(): string;
76
+ protected setLabelTextGetter(channel: string, option: SemanticLabelOption | boolean): ChannelEncodeType<ITextAttribute['text']>;
77
+ protected parseLabelSpec(): LabelSpec[];
78
+ protected setDefaultPlayer(): Record<string, Partial<PlayerSpec>>;
79
+ protected parsePlayerSpec(): PlayerSpec[];
80
+ protected parseDataSpec(): DataSpec[];
81
+ protected parseScaleSpec(): ScaleSpec[];
82
+ protected parseCoordinateSpec(): CoordinateSpec[];
83
+ protected setMainMarkEnterEncode(): Partial<any>;
84
+ protected setMainMarkSpec(): {};
85
+ protected setMultiMarksSpec(): MarkSpec[];
86
+ toViewSpec(): ViewSpec;
87
+ clear(): void;
88
+ }