@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/tree.js ADDED
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.TreeSemanticMark = 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 TreeSemanticMark extends semantic_mark_1.SemanticMark {
10
+ constructor(id) {
11
+ super(enums_1.PlotMakType.tree, id), (0, vgrammar_1.getTransform)(enums_1.PlotMakType.tree) || this._logger.error("Please add this line of code: import { registerTreeTransforms } from 'vgrammar-hierarchy', \n and run registerTreeTransforms() before use tree"),
12
+ (0, vgrammar_1.getGlyph)("treePath") || this._logger.error("Please add this line of code: import { registerTreePathGlyph } from '@visactor/vgrammar';\n and run registerTreePathGlyph() before use tree");
13
+ }
14
+ setMarkType() {
15
+ return vgrammar_1.GrammarMarkType.symbol;
16
+ }
17
+ setDefaultDataTransform() {
18
+ var _a;
19
+ return [ {
20
+ type: "tree",
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
+ flatten: !0
29
+ } ];
30
+ }
31
+ getDataIdOfLink() {
32
+ var _a, _b;
33
+ return `${null !== (_b = null === (_a = this.spec.data) || void 0 === _a ? void 0 : _a.id) && void 0 !== _b ? _b : this.spec.id}-data-link`;
34
+ }
35
+ setMultipleData() {
36
+ return [ {
37
+ id: this.getDataIdOfFiltered(),
38
+ transform: [ {
39
+ type: "map",
40
+ all: !0,
41
+ callback: datum => datum[0].nodes
42
+ } ]
43
+ }, {
44
+ source: this.getDataIdOfMain(),
45
+ id: this.getDataIdOfLink(),
46
+ transform: [ {
47
+ type: "map",
48
+ all: !0,
49
+ callback: datum => datum[0].links
50
+ } ]
51
+ } ];
52
+ }
53
+ parseScaleByEncode(channel, option) {
54
+ return "color" === channel ? {
55
+ type: "ordinal",
56
+ id: this.getScaleId("color"),
57
+ domain: {
58
+ data: this.getDataIdOfFiltered(),
59
+ field: option
60
+ },
61
+ range: (0, vgrammar_1.getPalette)()
62
+ } : null;
63
+ }
64
+ convertMarkEncode(encode) {
65
+ var _a, _b;
66
+ const markEncoder = this.convertSimpleMarkEncode(encode), res = {
67
+ x: {
68
+ field: "x"
69
+ },
70
+ y: {
71
+ field: "y"
72
+ }
73
+ };
74
+ if (markEncoder.color) {
75
+ const scaleColorId = this.getScaleId("color"), colorAccessor = (0, vgrammar_util_1.field)(markEncoder.color.field);
76
+ res.fill = (datum, el, params) => {
77
+ const scale = params[scaleColorId];
78
+ return (null == datum ? void 0 : datum.datum) ? scale.scale(colorAccessor(datum.datum[datum.datum.length - 1])) : void 0;
79
+ };
80
+ } else res.fill = null !== (_b = null === (_a = this.spec.style) || void 0 === _a ? void 0 : _a.fill) && void 0 !== _b ? _b : (0,
81
+ vgrammar_1.getPalette)()[0];
82
+ return res;
83
+ }
84
+ setLabelTextGetter(channel, option) {
85
+ const textGetter = (0, vgrammar_util_1.field)(channel);
86
+ return (datum, el, params) => textGetter(datum.datum[datum.datum.length - 1]);
87
+ }
88
+ setMainMarkSpec() {
89
+ return {
90
+ key: "key"
91
+ };
92
+ }
93
+ setMultiMarksSpec() {
94
+ if (!this.spec.label) return null;
95
+ const marks = [];
96
+ return marks.push({
97
+ type: "glyph",
98
+ glyphType: "treePath",
99
+ from: {
100
+ data: this.getDataIdOfLink()
101
+ },
102
+ key: "key",
103
+ zIndex: -1,
104
+ encode: {
105
+ update: {
106
+ x0: {
107
+ field: "x0"
108
+ },
109
+ x1: {
110
+ field: "x1"
111
+ },
112
+ y0: {
113
+ field: "y0"
114
+ },
115
+ y1: {
116
+ field: "y1"
117
+ },
118
+ thickness: 1,
119
+ round: !0,
120
+ stroke: "#333"
121
+ }
122
+ }
123
+ }), marks;
124
+ }
125
+ }
126
+
127
+ exports.TreeSemanticMark = TreeSemanticMark, TreeSemanticMark.type = enums_1.PlotMakType.tree;
128
+ //# sourceMappingURL=tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/tree.ts"],"names":[],"mappings":";;;AAgBA,mDAA+C;AAC/C,iDAAyF;AACzF,mCAAsC;AACtC,2DAAoE;AAGpE,MAAa,gBAAiB,SAAQ,4BAAoD;IAExF,YAAY,EAAoB;QAC9B,KAAK,CAAC,mBAAW,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAE5B,IAAI,CAAC,IAAA,uBAAY,EAAC,mBAAW,CAAC,IAAI,CAAC,EAAE;YACnC,IAAI,CAAC,OAAO,CAAC,KAAK,CAChB;yDACiD,CAClD,CAAC;SACH;QAED,IAAI,CAAC,IAAA,mBAAQ,EAAC,UAAU,CAAC,EAAE;YACzB,IAAI,CAAC,OAAO,CAAC,KAAK,CAChB;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n SemanticLabelOption,\n MarkSpec,\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, 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 TreeSemanticMark extends SemanticMark<PlotTreeEncodeSpec, TreeEncodeChannels> {\n static readonly type = PlotMakType.tree;\n constructor(id?: string | number) {\n super(PlotMakType.tree, id);\n\n if (!getTransform(PlotMakType.tree)) {\n this._logger.error(\n `Please add this line of code: import { registerTreeTransforms } from 'vgrammar-hierarchy', \n and run registerTreeTransforms() before use tree`\n );\n }\n\n if (!getGlyph('treePath')) {\n this._logger.error(\n `Please add this line of code: import { registerTreePathGlyph } from '@visactor/vgrammar';\n and run registerTreePathGlyph() before use tree`\n );\n }\n }\n\n setMarkType() {\n return GrammarMarkType.symbol;\n }\n\n setDefaultDataTransform(): TransformSpec[] {\n return [\n {\n type: 'tree',\n width: { signal: 'viewWidth' },\n height: { signal: 'viewHeight' },\n nodeKey: this.spec.encode?.node,\n flatten: true\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: TreeEncodeChannels,\n option: ValueOf<WithDefaultEncode<PlotTreeEncodeSpec, TreeEncodeChannels>, TreeEncodeChannels>\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<PlotTreeEncodeSpec, TreeEncodeChannels>\n ): GenerateBaseEncodeSpec<PlotTreeEncodeSpec> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n\n const res: GenerateEncoderSpec<PlotTreeEncodeSpec> = {\n x: { field: 'x' },\n y: { field: 'y' }\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 datum?.datum ? scale.scale(colorAccessor(datum.datum[datum.datum.length - 1])) : undefined;\n };\n } else {\n res.fill = this.spec.style?.fill ?? getPalette()[0];\n }\n\n return res;\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[datum.datum.length - 1]);\n };\n }\n\n setMainMarkSpec() {\n return { key: 'key' };\n }\n\n setMultiMarksSpec() {\n const label = this.spec.label;\n\n if (!label) {\n return null;\n }\n\n const marks: MarkSpec[] = [];\n\n marks.push({\n type: 'glyph',\n glyphType: 'treePath',\n from: { data: this.getDataIdOfLink() },\n key: 'key',\n zIndex: -1,\n encode: {\n update: {\n x0: { field: 'x0' },\n x1: { field: 'x1' },\n y0: { field: 'y0' },\n y1: { field: 'y1' },\n thickness: 1,\n round: true,\n stroke: '#333'\n }\n }\n });\n\n return marks;\n }\n}\n"]}
@@ -0,0 +1,41 @@
1
+ import type { TreemapEncodeChannels, WithDefaultEncode, PlotTreemapEncodeSpec, GenerateBaseEncodeSpec, Nil, ScaleSpec, ValueOf, TransformSpec, IElement, LabelSpec } from '@visactor/vgrammar';
2
+ import { SemanticMark } from './semantic-mark';
3
+ import { GrammarMarkType } from '@visactor/vgrammar';
4
+ import { PlotMakType } from './enums';
5
+ export declare class TreemapSemanticMark extends SemanticMark<PlotTreemapEncodeSpec, TreemapEncodeChannels> {
6
+ static readonly type = PlotMakType.treemap;
7
+ constructor(id?: string | number);
8
+ setMarkType(): GrammarMarkType;
9
+ setDefaultDataTransform(): TransformSpec[];
10
+ parseScaleByEncode(channel: TreemapEncodeChannels, option: ValueOf<WithDefaultEncode<PlotTreemapEncodeSpec, TreemapEncodeChannels>, TreemapEncodeChannels>): ScaleSpec | Nil;
11
+ convertMarkEncode(encode: WithDefaultEncode<PlotTreemapEncodeSpec, TreemapEncodeChannels>): GenerateBaseEncodeSpec<PlotTreemapEncodeSpec>;
12
+ setMainMarkSpec(): {
13
+ key: string;
14
+ };
15
+ protected parseLabelSpec(): LabelSpec[];
16
+ setMultiMarksSpec(): {
17
+ id: string;
18
+ type: string;
19
+ from: {
20
+ data: string;
21
+ };
22
+ layout: {
23
+ position: string;
24
+ skipBeforeLayouted: boolean;
25
+ };
26
+ key: string;
27
+ dependency: string[];
28
+ animation: import("@visactor/vgrammar").MarkAnimationSpec;
29
+ encode: {
30
+ enter: {
31
+ textAlign: string;
32
+ textBaseline: string;
33
+ } & Partial<import("@visactor/vrender").ITextGraphicAttribute>;
34
+ update: (datum: any, el: IElement, params: any) => {
35
+ x: number;
36
+ y: number;
37
+ text: any;
38
+ };
39
+ };
40
+ }[];
41
+ }
package/cjs/treemap.js ADDED
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.TreemapSemanticMark = 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 TreemapSemanticMark extends semantic_mark_1.SemanticMark {
10
+ constructor(id) {
11
+ super(enums_1.PlotMakType.treemap, id), (0, vgrammar_1.getTransform)("treemap") || this._logger.error("Please add this line of code: import { registerTreemapTransforms } from 'vgrammar-hierarchy'; \n and run registerTreemapTransforms() before use treemap");
12
+ }
13
+ setMarkType() {
14
+ return vgrammar_1.GrammarMarkType.rect;
15
+ }
16
+ setDefaultDataTransform() {
17
+ var _a;
18
+ return [ {
19
+ type: "treemap",
20
+ width: {
21
+ signal: "viewWidth"
22
+ },
23
+ height: {
24
+ signal: "viewHeight"
25
+ },
26
+ nodeKey: null === (_a = this.spec.encode) || void 0 === _a ? void 0 : _a.node,
27
+ flatten: !0
28
+ } ];
29
+ }
30
+ parseScaleByEncode(channel, option) {
31
+ return "color" === channel ? {
32
+ type: "ordinal",
33
+ id: this.getScaleId("color"),
34
+ domain: {
35
+ data: this.getDataIdOfFiltered(),
36
+ field: option
37
+ },
38
+ range: (0, vgrammar_1.getPalette)()
39
+ } : null;
40
+ }
41
+ convertMarkEncode(encode) {
42
+ var _a, _b;
43
+ const markEncoder = this.convertSimpleMarkEncode(encode), res = {
44
+ x: {
45
+ field: "x0"
46
+ },
47
+ x1: {
48
+ field: "x1"
49
+ },
50
+ y: {
51
+ field: "y0"
52
+ },
53
+ y1: {
54
+ field: "y1"
55
+ }
56
+ };
57
+ if (markEncoder.color) {
58
+ const scaleColorId = this.getScaleId("color"), colorAccessor = (0, vgrammar_util_1.field)(markEncoder.color.field);
59
+ res.fill = (datum, el, params) => {
60
+ const scale = params[scaleColorId];
61
+ return (null == datum ? void 0 : datum.datum) ? scale.scale(colorAccessor(datum.datum[datum.datum.length - 1])) : void 0;
62
+ };
63
+ } else res.fill = null !== (_b = null === (_a = this.spec.style) || void 0 === _a ? void 0 : _a.fill) && void 0 !== _b ? _b : (0,
64
+ vgrammar_1.getPalette)()[0];
65
+ return res;
66
+ }
67
+ setMainMarkSpec() {
68
+ return {
69
+ key: "key"
70
+ };
71
+ }
72
+ parseLabelSpec() {
73
+ return [];
74
+ }
75
+ setMultiMarksSpec() {
76
+ const label = this.spec.label;
77
+ return label ? Object.keys(label).map((key => {
78
+ const textGetter = (0, vgrammar_util_1.field)(key);
79
+ return {
80
+ id: `${this.getMarkId()}-text-${key}`,
81
+ type: "text",
82
+ from: {
83
+ data: this.getDataIdOfFiltered()
84
+ },
85
+ layout: {
86
+ position: "content",
87
+ skipBeforeLayouted: !0
88
+ },
89
+ key: "flattenIndex",
90
+ dependency: this.viewSpec.scales.map((scale => scale.id)).concat(vgrammar_1.SIGNAL_VIEW_BOX),
91
+ animation: this.convertMarkAnimation(),
92
+ encode: {
93
+ enter: Object.assign({
94
+ textAlign: "center",
95
+ textBaseline: "middle"
96
+ }, label[key].textStyle),
97
+ update: (datum, el, params) => ({
98
+ x: datum.labelRect ? (datum.labelRect.x0 + datum.labelRect.x1) / 2 : (datum.x0 + datum.x1) / 2,
99
+ y: datum.labelRect ? (datum.labelRect.y0 + datum.labelRect.y1) / 2 : (datum.y0 + datum.y1) / 2,
100
+ text: textGetter(datum.datum[datum.datum.length - 1])
101
+ })
102
+ }
103
+ };
104
+ })) : null;
105
+ }
106
+ }
107
+
108
+ exports.TreemapSemanticMark = TreemapSemanticMark, TreemapSemanticMark.type = enums_1.PlotMakType.treemap;
109
+ //# sourceMappingURL=treemap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/treemap.ts"],"names":[],"mappings":";;;AAaA,mDAA+C;AAC/C,iDAAgG;AAChG,mCAAsC;AACtC,2DAAoE;AAGpE,MAAa,mBAAoB,SAAQ,4BAA0D;IAEjG,YAAY,EAAoB;QAC9B,KAAK,CAAC,mBAAW,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAE/B,IAAI,CAAC,IAAA,uBAAY,EAAC,SAAS,CAAC,EAAE;YAC5B,IAAI,CAAC,OAAO,CAAC,KAAK,CAChB;+DACuD,CACxD,CAAC;SACH;IACH,CAAC;IAED,WAAW;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erateEncoderSpec,\n Nil,\n ScaleSpec,\n ValueOf,\n TransformSpec,\n IElement,\n LabelSpec\n} from '@visactor/vgrammar';\nimport { SemanticMark } from './semantic-mark';\nimport { getPalette, GrammarMarkType, getTransform, SIGNAL_VIEW_BOX } from '@visactor/vgrammar';\nimport { PlotMakType } from './enums';\nimport { field as getFieldAccessor } from '@visactor/vgrammar-util';\nimport type { BaseLabelAttrs } from '@visactor/vrender-components';\n\nexport class TreemapSemanticMark extends SemanticMark<PlotTreemapEncodeSpec, TreemapEncodeChannels> {\n static readonly type = PlotMakType.treemap;\n constructor(id?: string | number) {\n super(PlotMakType.treemap, id);\n\n if (!getTransform('treemap')) {\n this._logger.error(\n `Please add this line of code: import { registerTreemapTransforms } from 'vgrammar-hierarchy'; \n and run registerTreemapTransforms() before use treemap`\n );\n }\n }\n\n setMarkType() {\n return GrammarMarkType.rect;\n }\n\n setDefaultDataTransform(): TransformSpec[] {\n return [\n {\n type: 'treemap',\n width: { signal: 'viewWidth' },\n height: { signal: 'viewHeight' },\n nodeKey: this.spec.encode?.node,\n flatten: true\n }\n ];\n }\n parseScaleByEncode(\n channel: TreemapEncodeChannels,\n option: ValueOf<WithDefaultEncode<PlotTreemapEncodeSpec, TreemapEncodeChannels>, TreemapEncodeChannels>\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<PlotTreemapEncodeSpec, TreemapEncodeChannels>\n ): GenerateBaseEncodeSpec<PlotTreemapEncodeSpec> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n\n const res: GenerateEncoderSpec<PlotTreemapEncodeSpec> = {\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 datum?.datum ? scale.scale(colorAccessor(datum.datum[datum.datum.length - 1])) : undefined;\n };\n } else {\n res.fill = this.spec.style?.fill ?? getPalette()[0];\n }\n\n return res;\n }\n\n setMainMarkSpec() {\n return { key: 'key' };\n }\n\n protected parseLabelSpec(): LabelSpec[] {\n // TODO use arc label in the future\n return [];\n }\n\n setMultiMarksSpec() {\n const label = this.spec.label;\n\n if (!label) {\n return null;\n }\n\n return Object.keys(label).map(key => {\n const textGetter = getFieldAccessor(key);\n return {\n id: `${this.getMarkId()}-text-${key}`,\n type: 'text',\n from: {\n data: this.getDataIdOfFiltered()\n },\n layout: {\n position: 'content',\n skipBeforeLayouted: true\n },\n key: 'flattenIndex',\n dependency: this.viewSpec.scales.map(scale => scale.id).concat(SIGNAL_VIEW_BOX),\n animation: this.convertMarkAnimation(),\n encode: {\n enter: Object.assign(\n {\n textAlign: 'center',\n textBaseline: 'middle'\n },\n (label[key] as Partial<BaseLabelAttrs>).textStyle\n ),\n update: (datum: any, el: IElement, params: any) => {\n return {\n x: datum.labelRect ? (datum.labelRect.x0 + datum.labelRect.x1) / 2 : (datum.x0 + datum.x1) / 2,\n y: datum.labelRect ? (datum.labelRect.y0 + datum.labelRect.y1) / 2 : (datum.y0 + datum.y1) / 2,\n text: textGetter(datum.datum[datum.datum.length - 1])\n };\n }\n }\n };\n });\n }\n}\n"]}
package/cjs/util.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare const mergeGrammarSpecs: <T extends {
2
+ id?: string;
3
+ }>(newSpecs: T[], prevSpecs: T[]) => T[];
package/cjs/util.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.mergeGrammarSpecs = void 0;
6
+
7
+ const mergeGrammarSpecs = (newSpecs, prevSpecs) => newSpecs.reduce(((res, entry) => (entry.id && !res.some((prev => prev.id === entry.id)) && res.push(entry),
8
+ res)), prevSpecs);
9
+
10
+ exports.mergeGrammarSpecs = mergeGrammarSpecs;
11
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/util.ts"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB,GAAG,CAA4B,QAAa,EAAE,SAAc,EAAE,EAAE;IAC5F,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QACpC,IAAI,KAAK,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,CAAC,EAAE;YACvD,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjB;QAED,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,SAAS,CAAC,CAAC;AAChB,CAAC,CAAC;AARW,QAAA,iBAAiB,qBAQ5B","file":"util.js","sourcesContent":["export const mergeGrammarSpecs = <T extends { id?: string }>(newSpecs: T[], prevSpecs: T[]) => {\n return newSpecs.reduce((res, entry) => {\n if (entry.id && !res.some(prev => prev.id === entry.id)) {\n res.push(entry);\n }\n\n return res;\n }, prevSpecs);\n};\n"]}
@@ -0,0 +1,13 @@
1
+ import type { WordcloudShapeEncodeChannels, WithDefaultEncode, PlotWordcloudShapeEncodeSpec, GenerateBaseEncodeSpec, Nil, ScaleSpec, ValueOf, TransformSpec, LabelSpec } from '@visactor/vgrammar';
2
+ import { SemanticMark } from './semantic-mark';
3
+ import { GrammarMarkType } from '@visactor/vgrammar';
4
+ import { PlotMakType } from './enums';
5
+ export declare class WordcloudShapeSemanticMark extends SemanticMark<PlotWordcloudShapeEncodeSpec, WordcloudShapeEncodeChannels> {
6
+ static readonly type = PlotMakType.wordcloudShape;
7
+ constructor(id?: string | number);
8
+ setMarkType(): GrammarMarkType;
9
+ setDefaultDataTransform(): TransformSpec[];
10
+ parseScaleByEncode(channel: WordcloudShapeEncodeChannels, option: ValueOf<WithDefaultEncode<PlotWordcloudShapeEncodeSpec, WordcloudShapeEncodeChannels>, WordcloudShapeEncodeChannels>): ScaleSpec | Nil;
11
+ convertMarkEncode(encode: WithDefaultEncode<PlotWordcloudShapeEncodeSpec, WordcloudShapeEncodeChannels>): GenerateBaseEncodeSpec<PlotWordcloudShapeEncodeSpec>;
12
+ protected parseLabelSpec(): LabelSpec[];
13
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.WordcloudShapeSemanticMark = 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 WordcloudShapeSemanticMark extends semantic_mark_1.SemanticMark {
10
+ constructor(id) {
11
+ super(enums_1.PlotMakType.wordcloudShape, id), (0, vgrammar_1.getTransform)(enums_1.PlotMakType.wordcloudShape) || this._logger.error("Please add this line of code:\n import { registerWordCloudShapeTransforms } from '@visactor/vgrammar-wordcloud-shape'; \n and run registerWordCloudShapeTransforms() before use wordcloud-shape");
12
+ }
13
+ setMarkType() {
14
+ return vgrammar_1.GrammarMarkType.text;
15
+ }
16
+ setDefaultDataTransform() {
17
+ var _a;
18
+ return [ {
19
+ type: "wordcloudShape",
20
+ size: {
21
+ callback: params => [ params.viewBox.width(), params.viewBox.height() ],
22
+ dependency: [ "viewBox" ]
23
+ },
24
+ colorList: (0, vgrammar_1.getPalette)(),
25
+ text: {
26
+ field: null === (_a = this.spec.encode) || void 0 === _a ? void 0 : _a.text
27
+ }
28
+ } ];
29
+ }
30
+ parseScaleByEncode(channel, option) {
31
+ return "color" === channel ? {
32
+ type: "ordinal",
33
+ id: this.getScaleId("color"),
34
+ domain: {
35
+ data: this.getDataIdOfFiltered(),
36
+ field: option
37
+ },
38
+ range: (0, vgrammar_1.getPalette)()
39
+ } : null;
40
+ }
41
+ convertMarkEncode(encode) {
42
+ var _a, _b, _c;
43
+ const markEncoder = this.convertSimpleMarkEncode(encode), res = {
44
+ x: {
45
+ field: "x"
46
+ },
47
+ y: {
48
+ field: "y"
49
+ },
50
+ angle: {
51
+ field: "angle"
52
+ },
53
+ fontSize: {
54
+ field: "fontSize"
55
+ },
56
+ fontStyle: {
57
+ field: "fontStyle"
58
+ },
59
+ fontFamily: {
60
+ field: "fontFamily"
61
+ },
62
+ fontWeight: {
63
+ field: "fontWeight"
64
+ },
65
+ fillOpacity: {
66
+ field: "opacity"
67
+ },
68
+ text: {
69
+ field: null === (_a = this.spec.encode) || void 0 === _a ? void 0 : _a.text
70
+ }
71
+ };
72
+ if (markEncoder.color) {
73
+ const scaleColorId = this.getScaleId("color"), colorAccessor = (0, vgrammar_util_1.field)(markEncoder.color.field);
74
+ res.fill = (datum, el, params) => params[scaleColorId].scale(colorAccessor(datum));
75
+ } else res.fill = null !== (_c = null === (_b = this.spec.style) || void 0 === _b ? void 0 : _b.fill) && void 0 !== _c ? _c : (0,
76
+ vgrammar_1.getPalette)()[0];
77
+ return res;
78
+ }
79
+ parseLabelSpec() {
80
+ return [];
81
+ }
82
+ }
83
+
84
+ exports.WordcloudShapeSemanticMark = WordcloudShapeSemanticMark, WordcloudShapeSemanticMark.type = enums_1.PlotMakType.wordcloudShape;
85
+ //# sourceMappingURL=wordcloud-shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/wordcloud-shape.ts"],"names":[],"mappings":";;;AAaA,mDAA+C;AAC/C,iDAA+E;AAC/E,mCAAsC;AACtC,2DAAoE;AAEpE,MAAa,0BAA2B,SAAQ,4BAG/C;IAEC,YAAY,EAAoB;QAC9B,KAAK,CAAC,mBAAW,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;QAEtC,IAAI,CAAC,IAAA,uBAAY,EAAC,mBAAW,CAAC,cAAc,CAAC,EAAE;YAC7C,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AE,UAAU,EAAE;YAC/B,SAAS,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE;YACjC,UAAU,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE;YACnC,UAAU,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE;YACnC,WAAW,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE;YACjC,IAAI,EAAE,EAAE,KAAK,EAAE,MAAA,IAAI,CAAC,IAAI,CAAC,MAAM,0CAAE,IAAI,EAAE;SACxC,CAAC;QAEF,IAAI,WAAW,CAAC,KAAK,EAAE;YACrB,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAC9C,MAAM,aAAa,GAAG,IAAA,qBAAgB,EAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAEhE,GAAG,CAAC,IAAI,GAAG,CAAC,KAAU,EAAE,EAAY,EAAE,MAAW,EAAE,EAAE;gBACnD,MAAM,KAAK,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;gBACnC,OAAO,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;YAC3C,CAAC,CAAC;SACH;aAAM;YACL,GAAG,CAAC,IAAI,GAAG,MAAA,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,IAAI,mCAAI,IAAA,qBAAU,GAAE,CAAC,CAAC,CAAC,CAAC;SACrD;QAED,OAAO,GAAG,CAAC;IACb,CAAC;IAES,cAAc;QACtB,OAAO,EAAE,CAAC;IACZ,CAAC;;AA7FH,gEA8FC;AA1FiB,+BAAI,GAAG,mBAAW,CAAC,cAAc,CAAC","file":"wordcloud-shape.js","sourcesContent":["import type {\n WordcloudShapeEncodeChannels,\n WithDefaultEncode,\n PlotWordcloudShapeEncodeSpec,\n GenerateBaseEncodeSpec,\n GenerateEncoderSpec,\n Nil,\n ScaleSpec,\n ValueOf,\n TransformSpec,\n IElement,\n LabelSpec\n} from '@visactor/vgrammar';\nimport { SemanticMark } from './semantic-mark';\nimport { getPalette, GrammarMarkType, getTransform } from '@visactor/vgrammar';\nimport { PlotMakType } from './enums';\nimport { field as getFieldAccessor } from '@visactor/vgrammar-util';\n\nexport class WordcloudShapeSemanticMark extends SemanticMark<\n PlotWordcloudShapeEncodeSpec,\n WordcloudShapeEncodeChannels\n> {\n static readonly type = PlotMakType.wordcloudShape;\n constructor(id?: string | number) {\n super(PlotMakType.wordcloudShape, id);\n\n if (!getTransform(PlotMakType.wordcloudShape)) {\n this._logger.error(\n `Please add this line of code:\n import { registerWordCloudShapeTransforms } from '@visactor/vgrammar-wordcloud-shape'; \n and run registerWordCloudShapeTransforms() before use wordcloud-shape`\n );\n }\n }\n\n setMarkType() {\n return GrammarMarkType.text;\n }\n\n setDefaultDataTransform(): TransformSpec[] {\n return [\n {\n type: 'wordcloudShape',\n size: {\n callback: (params: any) => {\n return [params.viewBox.width(), params.viewBox.height()];\n },\n dependency: ['viewBox']\n },\n colorList: getPalette(),\n text: { field: this.spec.encode?.text }\n }\n ];\n }\n\n parseScaleByEncode(\n channel: WordcloudShapeEncodeChannels,\n option: ValueOf<\n WithDefaultEncode<PlotWordcloudShapeEncodeSpec, WordcloudShapeEncodeChannels>,\n WordcloudShapeEncodeChannels\n >\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<PlotWordcloudShapeEncodeSpec, WordcloudShapeEncodeChannels>\n ): GenerateBaseEncodeSpec<PlotWordcloudShapeEncodeSpec> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n\n const res: GenerateEncoderSpec<PlotWordcloudShapeEncodeSpec> = {\n x: { field: 'x' },\n y: { field: 'y' },\n angle: { field: 'angle' },\n fontSize: { field: 'fontSize' },\n fontStyle: { field: 'fontStyle' },\n fontFamily: { field: 'fontFamily' },\n fontWeight: { field: 'fontWeight' },\n fillOpacity: { field: 'opacity' },\n text: { field: this.spec.encode?.text }\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));\n };\n } else {\n res.fill = this.spec.style?.fill ?? getPalette()[0];\n }\n\n return res;\n }\n\n protected parseLabelSpec(): LabelSpec[] {\n return [];\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { WordcloudEncodeChannels, WithDefaultEncode, PlotWordcloudEncodeSpec, GenerateBaseEncodeSpec, Nil, ScaleSpec, ValueOf, TransformSpec, LabelSpec } from '@visactor/vgrammar';
2
+ import { SemanticMark } from './semantic-mark';
3
+ import { GrammarMarkType } from '@visactor/vgrammar';
4
+ import { PlotMakType } from './enums';
5
+ export declare class WordcloudSemanticMark extends SemanticMark<PlotWordcloudEncodeSpec, WordcloudEncodeChannels> {
6
+ static readonly type = PlotMakType.wordcloud;
7
+ constructor(id?: string | number);
8
+ setMarkType(): GrammarMarkType;
9
+ setDefaultMarkTransform(): TransformSpec[];
10
+ parseScaleByEncode(channel: WordcloudEncodeChannels, option: ValueOf<WithDefaultEncode<PlotWordcloudEncodeSpec, WordcloudEncodeChannels>, WordcloudEncodeChannels>): ScaleSpec | Nil;
11
+ convertMarkEncode(encode: WithDefaultEncode<PlotWordcloudEncodeSpec, WordcloudEncodeChannels>): GenerateBaseEncodeSpec<PlotWordcloudEncodeSpec>;
12
+ protected parseLabelSpec(): LabelSpec[];
13
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.WordcloudSemanticMark = 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 WordcloudSemanticMark extends semantic_mark_1.SemanticMark {
10
+ constructor(id) {
11
+ super(enums_1.PlotMakType.wordcloud, id), (0, vgrammar_1.getTransform)(enums_1.PlotMakType.wordcloud) || this._logger.error("Please add this line of code:\n 'import { registerWordCloudTransforms } from '@visactor/vgrammar-wordcloud'; \n and run registerWordCloudTransforms() before use wordcloud");
12
+ }
13
+ setMarkType() {
14
+ return vgrammar_1.GrammarMarkType.text;
15
+ }
16
+ setDefaultMarkTransform() {
17
+ var _a;
18
+ return [ {
19
+ type: "wordcloud",
20
+ size: {
21
+ callback: params => [ params.viewBox.width(), params.viewBox.height() ],
22
+ dependency: [ "viewBox" ]
23
+ },
24
+ text: {
25
+ field: null === (_a = this.spec.encode) || void 0 === _a ? void 0 : _a.text
26
+ }
27
+ } ];
28
+ }
29
+ parseScaleByEncode(channel, option) {
30
+ return "color" === channel ? {
31
+ type: "ordinal",
32
+ id: this.getScaleId("color"),
33
+ domain: {
34
+ data: this.getDataIdOfFiltered(),
35
+ field: option
36
+ },
37
+ range: (0, vgrammar_1.getPalette)()
38
+ } : null;
39
+ }
40
+ convertMarkEncode(encode) {
41
+ var _a, _b, _c;
42
+ const markEncoder = this.convertSimpleMarkEncode(encode), res = {
43
+ x: {
44
+ field: "x"
45
+ },
46
+ y: {
47
+ field: "y"
48
+ },
49
+ angle: {
50
+ field: "angle"
51
+ },
52
+ fontSize: {
53
+ field: "fontSize"
54
+ },
55
+ fontStyle: {
56
+ field: "fontStyle"
57
+ },
58
+ fontFamily: {
59
+ field: "fontFamily"
60
+ },
61
+ fontWeight: {
62
+ field: "fontWeight"
63
+ },
64
+ text: {
65
+ field: null === (_a = this.spec.encode) || void 0 === _a ? void 0 : _a.text
66
+ }
67
+ };
68
+ if (markEncoder.color) {
69
+ const scaleColorId = this.getScaleId("color"), colorAccessor = (0, vgrammar_util_1.field)(markEncoder.color.field);
70
+ res.fill = (datum, el, params) => params[scaleColorId].scale(colorAccessor(datum));
71
+ } else res.fill = null !== (_c = null === (_b = this.spec.style) || void 0 === _b ? void 0 : _b.fill) && void 0 !== _c ? _c : (0,
72
+ vgrammar_1.getPalette)()[0];
73
+ return res;
74
+ }
75
+ parseLabelSpec() {
76
+ return [];
77
+ }
78
+ }
79
+
80
+ exports.WordcloudSemanticMark = WordcloudSemanticMark, WordcloudSemanticMark.type = enums_1.PlotMakType.wordcloud;
81
+ //# sourceMappingURL=wordcloud.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/wordcloud.ts"],"names":[],"mappings":";;;AAaA,mDAA+C;AAC/C,iDAA+E;AAC/E,mCAAsC;AACtC,2DAAoE;AAEpE,MAAa,qBAAsB,SAAQ,4BAA8D;IAEvG,YAAY,EAAoB;QAC9B,KAAK,CAAC,mBAAW,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAEjC,IAAI,CAAC,IAAA,uBAAY,EAAC,mBAAW,CAAC,SAAS,CAAC,EAAE;YACxC,IAAI,CAAC,OAAO,CAAC,KAAK,CAChB;;mEAE2D,CAC5D,CAAC;SACH;IACH,CAAC;IAED,WAAW;QACT,OAAO,0BAAe,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED,uBAAuB;;QACrB,OAAO;YACL;gBACE,IAAI,EAAE,WAAW;gBACjB,IAAI,EAAE;oBACJ,QAAQ,EAAE,CAAC,MAAW,EAAE,EAAE;wBACxB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;oBAC3D,CAAC;oBACD,UAAU,EAAE,CAAC,SAAS,CAAC;iBACxB;gBACD,IAAI,EAAE,EAAE,KAAK,EAAE,MAAA,IAAI,CAAC,IAAI,CAAC,MAAM,0CAAE,IAAI,EAAE;aACxC;SACF,CAAC;IACJ,CAAC;IACD,kBAAkB,CAChB,OAAgC,EAChC,MAA6G;QAE7G,IAAI,OAAO,KAAK,OAAO,EAAE;YACvB,OA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YAC3C,CAAC,CAAC;SACH;aAAM;YACL,GAAG,CAAC,IAAI,GAAG,MAAA,MAAA,IAAI,CAAC,IAAI,CAAC,KAAK,0CAAE,IAAI,mCAAI,IAAA,qBAAU,GAAE,CAAC,CAAC,CAAC,CAAC;SACrD;QAED,OAAO,GAAG,CAAC;IACb,CAAC;IAES,cAAc;QACtB,OAAO,EAAE,CAAC;IACZ,CAAC;;AApFH,sDAqFC;AApFiB,0BAAI,GAAG,mBAAW,CAAC,SAAS,CAAC","file":"wordcloud.js","sourcesContent":["import type {\n WordcloudEncodeChannels,\n WithDefaultEncode,\n PlotWordcloudEncodeSpec,\n GenerateBaseEncodeSpec,\n GenerateEncoderSpec,\n Nil,\n ScaleSpec,\n ValueOf,\n TransformSpec,\n IElement,\n LabelSpec\n} from '@visactor/vgrammar';\nimport { SemanticMark } from './semantic-mark';\nimport { getPalette, GrammarMarkType, getTransform } from '@visactor/vgrammar';\nimport { PlotMakType } from './enums';\nimport { field as getFieldAccessor } from '@visactor/vgrammar-util';\n\nexport class WordcloudSemanticMark extends SemanticMark<PlotWordcloudEncodeSpec, WordcloudEncodeChannels> {\n static readonly type = PlotMakType.wordcloud;\n constructor(id?: string | number) {\n super(PlotMakType.wordcloud, id);\n\n if (!getTransform(PlotMakType.wordcloud)) {\n this._logger.error(\n `Please add this line of code:\n 'import { registerWordCloudTransforms } from '@visactor/vgrammar-wordcloud'; \n and run registerWordCloudTransforms() before use wordcloud`\n );\n }\n }\n\n setMarkType() {\n return GrammarMarkType.text;\n }\n\n setDefaultMarkTransform(): TransformSpec[] {\n return [\n {\n type: 'wordcloud',\n size: {\n callback: (params: any) => {\n return [params.viewBox.width(), params.viewBox.height()];\n },\n dependency: ['viewBox']\n },\n text: { field: this.spec.encode?.text }\n }\n ];\n }\n parseScaleByEncode(\n channel: WordcloudEncodeChannels,\n option: ValueOf<WithDefaultEncode<PlotWordcloudEncodeSpec, WordcloudEncodeChannels>, WordcloudEncodeChannels>\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<PlotWordcloudEncodeSpec, WordcloudEncodeChannels>\n ): GenerateBaseEncodeSpec<PlotWordcloudEncodeSpec> {\n const markEncoder = this.convertSimpleMarkEncode(encode);\n\n const res: GenerateEncoderSpec<PlotWordcloudEncodeSpec> = {\n x: { field: 'x' },\n y: { field: 'y' },\n angle: { field: 'angle' },\n fontSize: { field: 'fontSize' },\n fontStyle: { field: 'fontStyle' },\n fontFamily: { field: 'fontFamily' },\n fontWeight: { field: 'fontWeight' },\n text: { field: this.spec.encode?.text }\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));\n };\n } else {\n res.fill = this.spec.style?.fill ?? getPalette()[0];\n }\n\n return res;\n }\n\n protected parseLabelSpec(): LabelSpec[] {\n return [];\n }\n}\n"]}