@politicalwatch/tipi-uikit 1.0.0-dev

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 (238) hide show
  1. package/.browserslistrc +2 -0
  2. package/.editorconfig +7 -0
  3. package/.eslintrc.js +11 -0
  4. package/.postcssrc.json +5 -0
  5. package/.prettierrc.js +7 -0
  6. package/.storybook/main.js +19 -0
  7. package/.storybook/preview.js +17 -0
  8. package/.stylelintrc +24 -0
  9. package/README.md +21 -0
  10. package/dist/bng-890acecf.mjs +29 -0
  11. package/dist/coalicioncanaria-6f4c1db4.mjs +18 -0
  12. package/dist/compromis-5ea8e904.mjs +23 -0
  13. package/dist/cs-de2f22f8.mjs +21 -0
  14. package/dist/cup-83f9d201.mjs +25 -0
  15. package/dist/ehbildu-23275d48.mjs +25 -0
  16. package/dist/encomu-90f0f0ee.mjs +23 -0
  17. package/dist/erc-83cebd9f.mjs +33 -0
  18. package/dist/foroasturias-c86ed9f1.mjs +27 -0
  19. package/dist/iu-0d57eb1a.mjs +23 -0
  20. package/dist/jxcat-69202004.mjs +23 -0
  21. package/dist/maspais-a61a53ef.mjs +21 -0
  22. package/dist/nuevacanaria-559edad7.mjs +21 -0
  23. package/dist/pdecat-0ec3db5a.mjs +21 -0
  24. package/dist/pnv-7f6f4b34.mjs +29 -0
  25. package/dist/podemos-de793077.mjs +21 -0
  26. package/dist/pp-13bed712.mjs +25 -0
  27. package/dist/prc-8a3d42c1.mjs +29 -0
  28. package/dist/psoe-97af3ccf.mjs +21 -0
  29. package/dist/style.css +1 -0
  30. package/dist/sumar-7dfecef0.mjs +29 -0
  31. package/dist/teruelexiste-7d4a17ab.mjs +21 -0
  32. package/dist/tipi-uikit.es.js +26196 -0
  33. package/dist/tipi-uikit.umd.js +134 -0
  34. package/dist/unidaspodemos-43ae78cc.mjs +18 -0
  35. package/dist/upn-e7eb332f.mjs +35 -0
  36. package/dist/vox-64380b40.mjs +25 -0
  37. package/package.json +57 -0
  38. package/src/assets/.gitkeep +0 -0
  39. package/src/assets/birthday_bg.png +0 -0
  40. package/src/assets/index.js +64 -0
  41. package/src/assets/party_logos/bildu.png +0 -0
  42. package/src/assets/party_logos/bng.png +0 -0
  43. package/src/assets/party_logos/ca.jpeg +0 -0
  44. package/src/assets/party_logos/ciudadanos.png +0 -0
  45. package/src/assets/party_logos/compromis.jpg +0 -0
  46. package/src/assets/party_logos/cup.png +0 -0
  47. package/src/assets/party_logos/eajpnv.png +0 -0
  48. package/src/assets/party_logos/encomupodem.jpg +0 -0
  49. package/src/assets/party_logos/erc.png +0 -0
  50. package/src/assets/party_logos/fac.png +0 -0
  51. package/src/assets/party_logos/icon/bng.svg +4 -0
  52. package/src/assets/party_logos/icon/coalicioncanaria.svg +7 -0
  53. package/src/assets/party_logos/icon/compromis.svg +3 -0
  54. package/src/assets/party_logos/icon/cs.svg +3 -0
  55. package/src/assets/party_logos/icon/cup.svg +4 -0
  56. package/src/assets/party_logos/icon/ehbildu.svg +4 -0
  57. package/src/assets/party_logos/icon/encomu.svg +3 -0
  58. package/src/assets/party_logos/icon/erc.svg +5 -0
  59. package/src/assets/party_logos/icon/foroasturias.svg +4 -0
  60. package/src/assets/party_logos/icon/iu.svg +3 -0
  61. package/src/assets/party_logos/icon/jxcat.svg +3 -0
  62. package/src/assets/party_logos/icon/maspais.svg +3 -0
  63. package/src/assets/party_logos/icon/nuevacanaria.svg +3 -0
  64. package/src/assets/party_logos/icon/party-error.svg +3 -0
  65. package/src/assets/party_logos/icon/pdecat.svg +3 -0
  66. package/src/assets/party_logos/icon/pnv.svg +4 -0
  67. package/src/assets/party_logos/icon/podemos.svg +3 -0
  68. package/src/assets/party_logos/icon/pp.svg +4 -0
  69. package/src/assets/party_logos/icon/prc.svg +5 -0
  70. package/src/assets/party_logos/icon/psoe.svg +3 -0
  71. package/src/assets/party_logos/icon/sumar.svg +73 -0
  72. package/src/assets/party_logos/icon/teruelexiste.svg +3 -0
  73. package/src/assets/party_logos/icon/unidaspodemos.svg +27 -0
  74. package/src/assets/party_logos/icon/upn.svg +5 -0
  75. package/src/assets/party_logos/icon/vox.svg +4 -0
  76. package/src/assets/party_logos/iu.png +0 -0
  77. package/src/assets/party_logos/jxcat.png +0 -0
  78. package/src/assets/party_logos/mas-pais.jpg +0 -0
  79. package/src/assets/party_logos/nueva_canarias.png +0 -0
  80. package/src/assets/party_logos/pdecat.png +0 -0
  81. package/src/assets/party_logos/podemos.jpg +0 -0
  82. package/src/assets/party_logos/pp.png +0 -0
  83. package/src/assets/party_logos/prc.png +0 -0
  84. package/src/assets/party_logos/psc.png +0 -0
  85. package/src/assets/party_logos/pse-ee.png +0 -0
  86. package/src/assets/party_logos/psoe.png +0 -0
  87. package/src/assets/party_logos/teruelexiste.svg +4 -0
  88. package/src/assets/party_logos/unidaspodemos.png +0 -0
  89. package/src/assets/party_logos/upn.jpg +0 -0
  90. package/src/assets/party_logos/vox.png +0 -0
  91. package/src/assets/svg/icon-advanced.svg +3 -0
  92. package/src/assets/svg/icon-bell.svg +3 -0
  93. package/src/assets/svg/icon-birthday.svg +18 -0
  94. package/src/assets/svg/icon-building.svg +3 -0
  95. package/src/assets/svg/icon-calendar.svg +4 -0
  96. package/src/assets/svg/icon-chevron-down.svg +3 -0
  97. package/src/assets/svg/icon-chevron-left.svg +3 -0
  98. package/src/assets/svg/icon-chevron-right.svg +3 -0
  99. package/src/assets/svg/icon-chevron-up.svg +3 -0
  100. package/src/assets/svg/icon-clock.svg +4 -0
  101. package/src/assets/svg/icon-close-menu.svg +3 -0
  102. package/src/assets/svg/icon-close.svg +3 -0
  103. package/src/assets/svg/icon-conversation.svg +3 -0
  104. package/src/assets/svg/icon-denied.svg +3 -0
  105. package/src/assets/svg/icon-document.svg +4 -0
  106. package/src/assets/svg/icon-download.svg +3 -0
  107. package/src/assets/svg/icon-error.svg +3 -0
  108. package/src/assets/svg/icon-footprint.svg +3 -0
  109. package/src/assets/svg/icon-github.svg +9 -0
  110. package/src/assets/svg/icon-hamburger.svg +1 -0
  111. package/src/assets/svg/icon-info.svg +3 -0
  112. package/src/assets/svg/icon-less.svg +3 -0
  113. package/src/assets/svg/icon-location.svg +3 -0
  114. package/src/assets/svg/icon-logout.svg +13 -0
  115. package/src/assets/svg/icon-mail.svg +4 -0
  116. package/src/assets/svg/icon-more.svg +5 -0
  117. package/src/assets/svg/icon-open-blank.svg +3 -0
  118. package/src/assets/svg/icon-plus.svg +3 -0
  119. package/src/assets/svg/icon-search.svg +4 -0
  120. package/src/assets/svg/icon-success.svg +3 -0
  121. package/src/assets/svg/icon-twitter.svg +3 -0
  122. package/src/assets/svg/icon-upload.svg +3 -0
  123. package/src/assets/svg/icons.js +67 -0
  124. package/src/components/CSVDownload/CSVDownload.vue +146 -0
  125. package/src/components/Charts/Barchart/d3.barchart.js +484 -0
  126. package/src/components/Charts/Barchart/d3.barchart.vue +16 -0
  127. package/src/components/Charts/Sliceschart/d3.sliceschart.js +372 -0
  128. package/src/components/Charts/Sliceschart/d3.sliceschart.vue +20 -0
  129. package/src/components/Charts/Sunburst/d3.sunburst.js +412 -0
  130. package/src/components/Charts/Sunburst/d3.sunburst.vue +23 -0
  131. package/src/components/Charts/WordsCloud/d3.wordscloud.js +332 -0
  132. package/src/components/Charts/WordsCloud/d3.wordscloud.vue +16 -0
  133. package/src/components/Charts/d3.chart.js +242 -0
  134. package/src/components/Charts/d3.chart.vue +81 -0
  135. package/src/components/Charts/styles.scss +92 -0
  136. package/src/components/CongressLink/CongressLink.vue +19 -0
  137. package/src/components/Deputy/Deputy.vue +106 -0
  138. package/src/components/Header/Header.vue +19 -0
  139. package/src/components/Icon/Icon.vue +30 -0
  140. package/src/components/InitiativeCard/InitiativeCard.vue +94 -0
  141. package/src/components/InitiativeMeta/InitiativeMeta.vue +79 -0
  142. package/src/components/Loader/Loader.vue +23 -0
  143. package/src/components/Message/Message.vue +27 -0
  144. package/src/components/Navbar/Navbar.vue +117 -0
  145. package/src/components/Neuron/Neuron.vue +211 -0
  146. package/src/components/PartyLogo/PartyLogo.vue +58 -0
  147. package/src/components/PartyLogo/PartyLogoIcon.vue +239 -0
  148. package/src/components/Results/Results.vue +114 -0
  149. package/src/components/Splash/Splash.vue +43 -0
  150. package/src/components/Text/Text.vue +69 -0
  151. package/src/components/TipiCharts/TipiBarchart.vue +204 -0
  152. package/src/components/TopicCard/TopicCard.vue +52 -0
  153. package/src/components/TopicLink/TopicLink.vue +37 -0
  154. package/src/components/TopicPill/TopicPill.vue +67 -0
  155. package/src/components/Topics/Topics.vue +79 -0
  156. package/src/components/TwoCircles/TwoCircles.vue +134 -0
  157. package/src/components/index.js +57 -0
  158. package/src/main.js +11 -0
  159. package/src/stories/CSVDownload.stories.js +245 -0
  160. package/src/stories/CongressLink.stories.js +21 -0
  161. package/src/stories/D3BarChart.stories.js +40 -0
  162. package/src/stories/D3SlicesChart.stories.js +64 -0
  163. package/src/stories/D3Sunburst.stories.js +293 -0
  164. package/src/stories/D3WordsCloud.stories.js +64 -0
  165. package/src/stories/Deputy.stories.js +168 -0
  166. package/src/stories/Header.stories.js +26 -0
  167. package/src/stories/Icon.stories.js +25 -0
  168. package/src/stories/InitiativeCard.stories.js +58 -0
  169. package/src/stories/InitiativeMeta.stories.js +37 -0
  170. package/src/stories/Loader.stories.js +25 -0
  171. package/src/stories/Message.stories.js +49 -0
  172. package/src/stories/Navbar.stories.js +85 -0
  173. package/src/stories/Neuron.stories.js +210 -0
  174. package/src/stories/PartyLogo.stories.js +21 -0
  175. package/src/stories/PartyLogoIcon.stories.js +21 -0
  176. package/src/stories/Results.stories.js +350 -0
  177. package/src/stories/Splash.stories.js +25 -0
  178. package/src/stories/Text.stories.js +46 -0
  179. package/src/stories/TopicCard.stories.js +775 -0
  180. package/src/stories/TopicLink.stories.js +778 -0
  181. package/src/stories/TopicPill.stories.js +46 -0
  182. package/src/stories/Topics.stories.js +80 -0
  183. package/src/stories/TwoCircles.stories.js +144 -0
  184. package/src/stories/mocks.js +153 -0
  185. package/src/styles/01_settings/_settings__breakpoints.scss +28 -0
  186. package/src/styles/01_settings/_settings__colors.scss +30 -0
  187. package/src/styles/01_settings/_settings__fonts.scss +3 -0
  188. package/src/styles/01_settings/_settings__icons.scss +0 -0
  189. package/src/styles/01_settings/_settings__variables.scss +45 -0
  190. package/src/styles/02_tools/_tools__functions.scss +19 -0
  191. package/src/styles/02_tools/_tools__mixins.scss +321 -0
  192. package/src/styles/03_generic/_generic__box-sizing.scss +12 -0
  193. package/src/styles/03_generic/_generic__global.scss +20 -0
  194. package/src/styles/03_generic/_generic__normalize.scss +371 -0
  195. package/src/styles/04_base/_base__anchors.scss +8 -0
  196. package/src/styles/04_base/_base__blockquotes.scss +10 -0
  197. package/src/styles/04_base/_base__forms.scss +32 -0
  198. package/src/styles/04_base/_base__headings.scss +23 -0
  199. package/src/styles/04_base/_base__images.scss +4 -0
  200. package/src/styles/04_base/_base__lists.scss +66 -0
  201. package/src/styles/04_base/_base__paragraphs.scss +11 -0
  202. package/src/styles/04_base/_base__tables.scss +95 -0
  203. package/src/styles/05_objects/_objects__columns.scss +29 -0
  204. package/src/styles/05_objects/_objects__container.scss +19 -0
  205. package/src/styles/05_objects/_objects__grid.scss +57 -0
  206. package/src/styles/05_objects/_objects__masonry.scss +11 -0
  207. package/src/styles/05_objects/_objects__media.scss +24 -0
  208. package/src/styles/05_objects/_objects__section.scss +21 -0
  209. package/src/styles/06_components/_components__button.scss +178 -0
  210. package/src/styles/06_components/_components__congress-link.scss +12 -0
  211. package/src/styles/06_components/_components__decorator.scss +10 -0
  212. package/src/styles/06_components/_components__deputy.scss +177 -0
  213. package/src/styles/06_components/_components__disclaimer.scss +24 -0
  214. package/src/styles/06_components/_components__forms.scss +454 -0
  215. package/src/styles/06_components/_components__header.scss +37 -0
  216. package/src/styles/06_components/_components__icon.scss +27 -0
  217. package/src/styles/06_components/_components__initiative-card.scss +49 -0
  218. package/src/styles/06_components/_components__initiative-meta.scss +91 -0
  219. package/src/styles/06_components/_components__loader.scss +125 -0
  220. package/src/styles/06_components/_components__menu.scss +110 -0
  221. package/src/styles/06_components/_components__message.scss +66 -0
  222. package/src/styles/06_components/_components__navbar.scss +114 -0
  223. package/src/styles/06_components/_components__party-logo.scss +21 -0
  224. package/src/styles/06_components/_components__splash.scss +29 -0
  225. package/src/styles/06_components/_components__text.scss +69 -0
  226. package/src/styles/06_components/_components__topic-card.scss +40 -0
  227. package/src/styles/06_components/_components__topic-link.scss +37 -0
  228. package/src/styles/06_components/_components__topics.scss +107 -0
  229. package/src/styles/07_trumps/_trumps__borders.scss +1 -0
  230. package/src/styles/07_trumps/_trumps__colors.scss +3 -0
  231. package/src/styles/07_trumps/_trumps__grid.scss +1 -0
  232. package/src/styles/07_trumps/_trumps__helpers.scss +17 -0
  233. package/src/styles/07_trumps/_trumps__texts.scss +39 -0
  234. package/src/styles/07_trumps/_trumps__visibility.scss +56 -0
  235. package/src/styles/main.scss +54 -0
  236. package/src/utils/index.js +26 -0
  237. package/svgo.config.js +16 -0
  238. package/vite.config.js +54 -0
@@ -0,0 +1,412 @@
1
+ import d3chart from '../d3.chart';
2
+ import { select, selectAll } from 'd3-selection';
3
+ import { scaleLinear, scaleOrdinal, scaleSqrt } from 'd3-scale';
4
+ import { hierarchy, partition } from 'd3-hierarchy';
5
+ import { arc } from 'd3-shape';
6
+ import { path } from 'd3-path';
7
+ import { transition } from 'd3-transition';
8
+ import { interpolate } from 'd3-interpolate';
9
+ import {
10
+ easeLinear,
11
+ easePolyIn,
12
+ easePolyOut,
13
+ easePoly,
14
+ easePolyInOut,
15
+ easeQuadIn,
16
+ easeQuadOut,
17
+ easeQuad,
18
+ easeQuadInOut,
19
+ easeCubicIn,
20
+ easeCubicOut,
21
+ easeCubic,
22
+ easeCubicInOut,
23
+ easeSinIn,
24
+ easeSinOut,
25
+ easeSin,
26
+ easeSinInOut,
27
+ easeExpIn,
28
+ easeExpOut,
29
+ easeExp,
30
+ easeExpInOut,
31
+ easeCircleIn,
32
+ easeCircleOut,
33
+ easeCircle,
34
+ easeCircleInOut,
35
+ easeElasticIn,
36
+ easeElastic,
37
+ easeElasticOut,
38
+ easeElasticInOut,
39
+ easeBackIn,
40
+ easeBackOut,
41
+ easeBack,
42
+ easeBackInOut,
43
+ easeBounceIn,
44
+ easeBounce,
45
+ easeBounceOut,
46
+ easeBounceInOut,
47
+ } from 'd3-ease';
48
+ import {
49
+ schemeCategory10,
50
+ schemeAccent,
51
+ schemeDark2,
52
+ schemePaired,
53
+ schemePastel1,
54
+ schemePastel2,
55
+ schemeSet1,
56
+ schemeSet2,
57
+ schemeSet3,
58
+ schemeTableau10,
59
+ } from 'd3-scale-chromatic';
60
+
61
+ const d3 = {
62
+ select,
63
+ selectAll,
64
+ scaleLinear,
65
+ scaleOrdinal,
66
+ scaleSqrt,
67
+ hierarchy,
68
+ partition,
69
+ arc,
70
+ path,
71
+ transition,
72
+ interpolate,
73
+ easeLinear,
74
+ easePolyIn,
75
+ easePolyOut,
76
+ easePoly,
77
+ easePolyInOut,
78
+ easeQuadIn,
79
+ easeQuadOut,
80
+ easeQuad,
81
+ easeQuadInOut,
82
+ easeCubicIn,
83
+ easeCubicOut,
84
+ easeCubic,
85
+ easeCubicInOut,
86
+ easeSinIn,
87
+ easeSinOut,
88
+ easeSin,
89
+ easeSinInOut,
90
+ easeExpIn,
91
+ easeExpOut,
92
+ easeExp,
93
+ easeExpInOut,
94
+ easeCircleIn,
95
+ easeCircleOut,
96
+ easeCircle,
97
+ easeCircleInOut,
98
+ easeElasticIn,
99
+ easeElastic,
100
+ easeElasticOut,
101
+ easeElasticInOut,
102
+ easeBackIn,
103
+ easeBackOut,
104
+ easeBack,
105
+ easeBackInOut,
106
+ easeBounceIn,
107
+ easeBounce,
108
+ easeBounceOut,
109
+ easeBounceInOut,
110
+ schemeCategory10,
111
+ schemeAccent,
112
+ schemeDark2,
113
+ schemePaired,
114
+ schemePastel1,
115
+ schemePastel2,
116
+ schemeSet1,
117
+ schemeSet2,
118
+ schemeSet3,
119
+ schemeTableau10,
120
+ };
121
+
122
+ import pluralize from 'pluralize';
123
+
124
+ /**
125
+ * D3 Sunburst
126
+ */
127
+ class d3sunburst extends d3chart {
128
+ constructor(selection, data, config) {
129
+ super(selection, data, config, {
130
+ margin: { top: 20, right: 20, bottom: 20, left: 20 },
131
+ key: '',
132
+ value: '',
133
+ color: {
134
+ key: false,
135
+ keys: false,
136
+ scheme: false,
137
+ current: '#1f77b4',
138
+ default: '#AAA',
139
+ axis: '#000',
140
+ },
141
+ tooltip: { label: false, suffix: false, suffixPlural: false },
142
+ transition: { duration: 350, ease: 'easeLinear' },
143
+ charSpace: 8,
144
+ });
145
+ }
146
+
147
+ /**
148
+ * Init chart
149
+ */
150
+ initChart() {
151
+ // Set up dimensions
152
+ this.getDimensions();
153
+ this.initChartFrame('sunburst');
154
+
155
+ if (this.cfg.tooltip.suffix && this.cfg.tooltip.suffixPlural) {
156
+ pluralize.addIrregularRule(this.cfg.tooltip.suffix, this.cfg.tooltip.suffixPlural);
157
+ }
158
+
159
+ // Center group
160
+ this.gcenter = this.g.append('g');
161
+
162
+ this.setChartDimension();
163
+ this.updateChart();
164
+ }
165
+
166
+ /**
167
+ * Set up chart dimensions (non depending on data)
168
+ */
169
+ setChartDimension() {
170
+ // SVG element
171
+ this.svg
172
+ .attr(
173
+ 'viewBox',
174
+ `0 0 ${this.cfg.width + this.cfg.margin.left + this.cfg.margin.right} ${
175
+ this.cfg.height + this.cfg.margin.top + this.cfg.margin.bottom
176
+ }`
177
+ )
178
+ .attr('width', this.cfg.width + this.cfg.margin.left + this.cfg.margin.right)
179
+ .attr('height', this.cfg.height + this.cfg.margin.top + this.cfg.margin.bottom);
180
+
181
+ // Center group
182
+ this.gcenter.attr('transform', `translate(${this.cfg.width / 2}, ${this.cfg.height / 2})`);
183
+ }
184
+
185
+ /**
186
+ * Bind data to main elements groups
187
+ */
188
+ bindData() {
189
+ const partition = (data) => {
190
+ const root = d3
191
+ .hierarchy(data)
192
+ .sum((d) => d[this.cfg.value])
193
+ .sort((a, b) => b.name - a.name);
194
+ return d3.partition()(root);
195
+ };
196
+
197
+ this.hData = partition(this.data[0]).descendants();
198
+
199
+ this.itemg = this.gcenter
200
+ .selectAll('.chart__slice-group')
201
+ .data(this.hData, (d) => d.data[this.cfg.key]);
202
+
203
+ // Set transition
204
+ this.transition = d3
205
+ .transition('t')
206
+ .duration(this.cfg.transition.duration)
207
+ .ease(d3[this.cfg.transition.ease]);
208
+ }
209
+
210
+ /**
211
+ * Set up scales
212
+ */
213
+ setScales() {
214
+ this.radius = Math.min(this.cfg.width, this.cfg.height) / 2;
215
+
216
+ this.xScale = d3
217
+ .scaleLinear()
218
+ .range([0, 2 * Math.PI])
219
+ .clamp(true);
220
+
221
+ this.yScale = d3.scaleSqrt().range([this.radius * 0.1, this.radius]);
222
+
223
+ this.arc = d3
224
+ .arc()
225
+ .startAngle((d) => this.xScale(d.x0))
226
+ .endAngle((d) => this.xScale(d.x1))
227
+ .innerRadius((d) => Math.max(0, this.yScale(d.y0)))
228
+ .outerRadius((d) => Math.max(0, this.yScale(d.y1)));
229
+
230
+ // Set up color scheme
231
+ if (this.cfg.color.scheme) {
232
+ if (this.cfg.color.scheme instanceof Array === true) {
233
+ this.colorScale = d3.scaleOrdinal().range(this.cfg.color.scheme);
234
+ } else {
235
+ this.colorScale = d3.scaleOrdinal(d3[this.cfg.color.scheme]);
236
+ }
237
+ }
238
+ }
239
+
240
+ /**
241
+ * Add new chart's elements
242
+ */
243
+ enterElements() {
244
+ const newg = this.itemg
245
+ .enter()
246
+ .append('g')
247
+ .attr('class', 'chart__slice-group chart__slice-group--sunburst clickable')
248
+ .on('click', (event, d) => {
249
+ event.stopPropagation();
250
+ this.focusOn(d);
251
+ });
252
+
253
+ // PATHS
254
+ newg
255
+ .append('path')
256
+ .attr('class', 'chart__slice chart__slice--sunburst')
257
+ .style('fill', (d) => this.colorElement(d.data))
258
+ .on('mouseover', (event, d) => {
259
+ const label = this.cfg.tooltip.suffixPlural
260
+ ? pluralize(this.cfg.tooltip.suffix, d.value)
261
+ : this.cfg.tooltip.suffix;
262
+ const text = this.cfg.tooltip.suffix
263
+ ? `<div>${d.data[this.cfg.key]}: ${d.value} ${label}</div>`
264
+ : `<div>${d.data[this.cfg.key]}: ${d.value}</div>`;
265
+ this.tooltip.html(text).classed('active', true);
266
+ })
267
+ .on('mouseout', () => {
268
+ this.tooltip.classed('active', false);
269
+ })
270
+ .on('mousemove', (event) => {
271
+ this.tooltip
272
+ .style('left', event['pageX'] - 28 + 'px')
273
+ .style('top', event['pageY'] - 40 + 'px');
274
+ })
275
+ .transition(this.transition)
276
+ .attrTween('d', (d) => {
277
+ const iy0 = d3.interpolate(0, d.y0);
278
+ const iy1 = d3.interpolate(d.y0, d.y1);
279
+ const ix0 = d3.interpolate(0, d.x0);
280
+ const ix1 = d3.interpolate(0, d.x1);
281
+ return (t) => {
282
+ d.y0 = iy0(t);
283
+ d.y1 = iy1(t);
284
+ d.x0 = ix0(t);
285
+ d.x1 = ix1(t);
286
+ return this.arc(d);
287
+ };
288
+ });
289
+
290
+ // LABELS
291
+ newg
292
+ .append('path')
293
+ .attr('class', 'chart__line--hidden')
294
+ .attr('id', (_, i) => `hiddenArc${i}`)
295
+ .attr('d', (d) => this.middleArcLine(d));
296
+
297
+ this.labels = newg
298
+ .append('text')
299
+ .attr('class', 'chart__labels')
300
+ .attr('display', 'none')
301
+ .attr('text-anchor', 'middle')
302
+ .attr('dy', 2)
303
+ .attr('font-size', '10px')
304
+ .style('opacity', 0);
305
+
306
+ this.labels
307
+ .append('textPath')
308
+ .attr('startOffset', '50%')
309
+ .attr('xlink:href', (_, i) => `#hiddenArc${i}`)
310
+ .text((d) => d.data.name);
311
+ }
312
+
313
+ /**
314
+ * Update chart's elements based on data change
315
+ */
316
+ updateElements() {
317
+ this.itemg
318
+ .selectAll('.chart__slice')
319
+ .transition(this.transition)
320
+ .attrTween('d', (d) => {
321
+ const d2 = this.hData.filter((j) => j.data.name === d.data.name)[0];
322
+ const iy0 = d3.interpolate(d.y0, d2.y0);
323
+ const iy1 = d3.interpolate(d.y1, d2.y1);
324
+ const ix0 = d3.interpolate(d.x0, d2.x0);
325
+ const ix1 = d3.interpolate(d.x1, d2.x1);
326
+ return (t) => {
327
+ d2.y0 = iy0(t);
328
+ d2.y1 = iy1(t);
329
+ d2.x0 = ix0(t);
330
+ d2.x1 = ix1(t);
331
+ return this.arc(d2);
332
+ };
333
+ })
334
+ .style('fill', (d) => this.colorElement(d.data));
335
+
336
+ this.labels
337
+ .attr('display', (d) => (this.textFits(d) ? null : 'none'))
338
+ .transition(this.transition)
339
+ .duration(this.cfg.transition.duration / 2)
340
+ .delay(this.cfg.transition.duration / 2)
341
+ .style('opacity', 1);
342
+ }
343
+
344
+ /**
345
+ * Remove chart's elements without data
346
+ */
347
+ exitElements() {
348
+ this.itemg.exit().transition(this.transition).style('opacity', 0).remove();
349
+ }
350
+
351
+ /**
352
+ * Check if text fits in available space
353
+ */
354
+ textFits(d) {
355
+ if (!d.parent) return false;
356
+ const deltaAngle = this.xScale(d.x1) - this.xScale(d.x0);
357
+ const r = Math.max(0, (this.yScale(d.y0) + this.yScale(d.y1)) / 2);
358
+ return d.data[this.cfg.key].length * this.cfg.charSpace < r * deltaAngle;
359
+ }
360
+
361
+ /**
362
+ * Transition slice on focus
363
+ */
364
+ focusOn(d) {
365
+ const d2 = this.hData.filter((j) => j.data.name === d.data.name)[0];
366
+ const transition = this.svg
367
+ .transition()
368
+ .duration(this.cfg.transition.duration)
369
+ .ease(d3[this.cfg.transition.ease])
370
+ .tween('scale', () => {
371
+ const xd = d3.interpolate(this.xScale.domain(), [d2.x0, d2.x1]);
372
+ const yd = d3.interpolate(this.yScale.domain(), [d2.y0, 1]);
373
+ return (t) => {
374
+ this.xScale.domain(xd(t));
375
+ this.yScale.domain(yd(t));
376
+ };
377
+ });
378
+
379
+ transition.selectAll('.chart__slice').attrTween('d', (d) => () => {
380
+ const d3 = this.hData.filter((j) => j.data.name === d.data.name)[0];
381
+ return this.arc(d3);
382
+ });
383
+
384
+ transition.selectAll('.chart__line--hidden').attrTween('d', (da) => () => {
385
+ const d2 = this.hData.filter((j) => j.data.name === da.data.name)[0];
386
+ return this.middleArcLine(d2);
387
+ });
388
+
389
+ transition.selectAll('.chart__labels').attrTween('display', (da) => () => {
390
+ const d2 = this.hData.filter((j) => j.data.name === da.data.name)[0];
391
+ return this.textFits(d2) ? null : 'none';
392
+ });
393
+ }
394
+
395
+ middleArcLine(d) {
396
+ const halfPi = Math.PI / 2;
397
+ const angles = [this.xScale(d.x0) - halfPi, this.xScale(d.x1) - halfPi];
398
+ const r = Math.max(0, (this.yScale(d.y0) + this.yScale(d.y1)) / 2);
399
+
400
+ const middleAngle = (angles[1] + angles[0]) / 2;
401
+ const invertDirection = middleAngle > 0 && middleAngle < Math.PI;
402
+ if (invertDirection) {
403
+ angles.reverse();
404
+ }
405
+
406
+ const path = d3.path();
407
+ path.arc(0, 0, r, angles[0], angles[1], invertDirection);
408
+ return path.toString();
409
+ }
410
+ }
411
+
412
+ export default d3sunburst;
@@ -0,0 +1,23 @@
1
+ <script>
2
+ import D3Chart from '../d3.chart.vue';
3
+ import d3sunburst from './d3.sunburst';
4
+
5
+ export default {
6
+ name: 'D3Sunburst',
7
+ extends: D3Chart,
8
+ mounted() {
9
+ this.chart = new d3sunburst(
10
+ this.$refs.chart,
11
+ JSON.parse(JSON.stringify(this.datum)),
12
+ this.config,
13
+ );
14
+ },
15
+ };
16
+ </script>
17
+
18
+ <style lang="scss">
19
+ .chart__slice--sunburst {
20
+ stroke: white;
21
+ stroke-width: 1px;
22
+ }
23
+ </style>