@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,372 @@
1
+ import d3chart from '../d3.chart';
2
+ import { select, selectAll } from 'd3-selection';
3
+ import { scaleLinear, scaleOrdinal } from 'd3-scale';
4
+ import { max, min, sum } from 'd3-array';
5
+ import { pie, arc } from 'd3-shape';
6
+ import { transition } from 'd3-transition';
7
+ import { interpolate } from 'd3-interpolate';
8
+ import {
9
+ easeLinear,
10
+ easePolyIn,
11
+ easePolyOut,
12
+ easePoly,
13
+ easePolyInOut,
14
+ easeQuadIn,
15
+ easeQuadOut,
16
+ easeQuad,
17
+ easeQuadInOut,
18
+ easeCubicIn,
19
+ easeCubicOut,
20
+ easeCubic,
21
+ easeCubicInOut,
22
+ easeSinIn,
23
+ easeSinOut,
24
+ easeSin,
25
+ easeSinInOut,
26
+ easeExpIn,
27
+ easeExpOut,
28
+ easeExp,
29
+ easeExpInOut,
30
+ easeCircleIn,
31
+ easeCircleOut,
32
+ easeCircle,
33
+ easeCircleInOut,
34
+ easeElasticIn,
35
+ easeElastic,
36
+ easeElasticOut,
37
+ easeElasticInOut,
38
+ easeBackIn,
39
+ easeBackOut,
40
+ easeBack,
41
+ easeBackInOut,
42
+ easeBounceIn,
43
+ easeBounce,
44
+ easeBounceOut,
45
+ easeBounceInOut,
46
+ } from 'd3-ease';
47
+ import {
48
+ schemeCategory10,
49
+ schemeAccent,
50
+ schemeDark2,
51
+ schemePaired,
52
+ schemePastel1,
53
+ schemePastel2,
54
+ schemeSet1,
55
+ schemeSet2,
56
+ schemeSet3,
57
+ schemeTableau10,
58
+ } from 'd3-scale-chromatic';
59
+
60
+ const d3 = {
61
+ select,
62
+ selectAll,
63
+ scaleLinear,
64
+ scaleOrdinal,
65
+ max,
66
+ min,
67
+ sum,
68
+ transition,
69
+ pie,
70
+ arc,
71
+ interpolate,
72
+ easeLinear,
73
+ easePolyIn,
74
+ easePolyOut,
75
+ easePoly,
76
+ easePolyInOut,
77
+ easeQuadIn,
78
+ easeQuadOut,
79
+ easeQuad,
80
+ easeQuadInOut,
81
+ easeCubicIn,
82
+ easeCubicOut,
83
+ easeCubic,
84
+ easeCubicInOut,
85
+ easeSinIn,
86
+ easeSinOut,
87
+ easeSin,
88
+ easeSinInOut,
89
+ easeExpIn,
90
+ easeExpOut,
91
+ easeExp,
92
+ easeExpInOut,
93
+ easeCircleIn,
94
+ easeCircleOut,
95
+ easeCircle,
96
+ easeCircleInOut,
97
+ easeElasticIn,
98
+ easeElastic,
99
+ easeElasticOut,
100
+ easeElasticInOut,
101
+ easeBackIn,
102
+ easeBackOut,
103
+ easeBack,
104
+ easeBackInOut,
105
+ easeBounceIn,
106
+ easeBounce,
107
+ easeBounceOut,
108
+ easeBounceInOut,
109
+ schemeCategory10,
110
+ schemeAccent,
111
+ schemeDark2,
112
+ schemePaired,
113
+ schemePastel1,
114
+ schemePastel2,
115
+ schemeSet1,
116
+ schemeSet2,
117
+ schemeSet3,
118
+ schemeTableau10,
119
+ };
120
+
121
+ /**
122
+ * D3 Slices Chart
123
+ */
124
+ class d3sliceschart extends d3chart {
125
+ constructor(selection, data, config) {
126
+ super(selection, data, config, {
127
+ margin: { top: 40, right: 20, bottom: 40, left: 20 },
128
+ key: '',
129
+ value: 'value',
130
+ color: {
131
+ key: false,
132
+ keys: false,
133
+ scheme: false,
134
+ current: '#1f77b4',
135
+ default: '#AAA',
136
+ axis: '#000',
137
+ },
138
+ radius: { inner: false, outter: false, padding: 0, round: 0 },
139
+ transition: { duration: 350, ease: 'easeLinear' },
140
+ });
141
+ }
142
+
143
+ /**
144
+ * Init chart
145
+ */
146
+ initChart() {
147
+ // Set up dimensions
148
+ this.getDimensions();
149
+ this.initChartFrame('sliceschart');
150
+
151
+ this.cScale = d3.scaleOrdinal();
152
+ this.rScale = d3.scaleLinear();
153
+ this.arc = d3.arc();
154
+ this.pie = d3
155
+ .pie()
156
+ .sort(null)
157
+ .value(() => 1)
158
+ .padAngle(this.cfg.radius.padding);
159
+
160
+ if (this.cfg.radius && this.cfg.radius.inner) {
161
+ const outRadius = this.cfg.radius.outter
162
+ ? this.cfg.radius.outter
163
+ : Math.min(this.cfg.width, this.cfg.height) / 2;
164
+ this.cfg.radius.relation = this.cfg.radius.inner ? this.cfg.radius.inner / outRadius : 0;
165
+ }
166
+
167
+ this.gcenter = this.g.append('g');
168
+ this.setChartDimension();
169
+ this.updateChart();
170
+
171
+ this.centerText = this.g
172
+ .append('text')
173
+ .attr('x', this.cfg.width / 2)
174
+ .attr('y', this.cfg.height / 2 + 10)
175
+ .attr('text-anchor', 'middle');
176
+ }
177
+
178
+ /**
179
+ * Set up chart dimensions (non depending on data)
180
+ */
181
+ setChartDimension() {
182
+ // SVG element
183
+ this.svg
184
+ .attr(
185
+ 'viewBox',
186
+ `0 0 ${this.cfg.width + this.cfg.margin.left + this.cfg.margin.right} ${this.cfg.height + this.cfg.margin.top + this.cfg.margin.bottom}`
187
+ )
188
+ .attr('width', this.cfg.width + this.cfg.margin.left + this.cfg.margin.right)
189
+ .attr('height', this.cfg.height + this.cfg.margin.top + this.cfg.margin.bottom);
190
+
191
+ // Center element
192
+ this.gcenter.attr('transform', `translate(${this.cfg.width / 2}, ${this.cfg.height / 2})`);
193
+ }
194
+
195
+ /**
196
+ * Bind data to main elements groups
197
+ */
198
+ bindData() {
199
+ this.itemg = this.gcenter
200
+ .selectAll('.chart__slice-group')
201
+ .data(this.pie(this.data), (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
+ // Set up radius
215
+ this.cfg.radius.outter =
216
+ this.cfg.radius && this.cfg.radius.outter
217
+ ? this.cfg.radius.outter
218
+ : Math.min(this.cfg.width, this.cfg.height) / 2;
219
+ this.inRadius = this.cfg.radius && this.cfg.radius.inner ? this.cfg.radius.inner : 0;
220
+ if (this.cfg.radius.relation) {
221
+ this.inRadius = this.cfg.radius.outter * this.cfg.radius.relation;
222
+ }
223
+
224
+ // Set up arcs
225
+ this.arc = d3
226
+ .arc()
227
+ .outerRadius(this.cfg.radius.outter)
228
+ .innerRadius(this.inRadius)
229
+ .cornerRadius(this.cfg.radius.round);
230
+
231
+ let max = d3.max(this.data, (d) => d[this.cfg.value]);
232
+ if (max == 0) {
233
+ max = 1;
234
+ }
235
+
236
+ this.rScale.range([this.inRadius, this.cfg.radius.outter]).domain([0, max]);
237
+
238
+ // Set up color scheme
239
+ if (this.cfg.color.scheme) {
240
+ if (this.cfg.color.scheme instanceof Array === true) {
241
+ this.colorScale = d3
242
+ .scaleOrdinal()
243
+ .domain(this.data.map((d) => d[this.cfg.key]))
244
+ .range(this.cfg.color.scheme);
245
+ } else {
246
+ this.colorScale = d3
247
+ .scaleOrdinal(d3[this.cfg.color.scheme])
248
+ .domain(this.data.map((d) => d[this.cfg.key]));
249
+ }
250
+ }
251
+ }
252
+
253
+ /**
254
+ * Add new chart's elements
255
+ */
256
+ enterElements() {
257
+ const newg = this.itemg
258
+ .enter()
259
+ .append('g')
260
+ .attr('class', 'chart__slice-group chart__slice-group--sliceschart');
261
+
262
+ // BACKGROUNDS
263
+ newg
264
+ .append('path')
265
+ .attr('class', 'chart__slice chart__slice--sliceschart')
266
+ //.on('mouseover', (d, i) => {
267
+ // const key = d.data[this.cfg.key];
268
+ // const value = d.data[this.cfg.value];
269
+ // this.tooltip.html(() => {
270
+ // return `<div>${key}: ${value}</div>`;
271
+ // })
272
+ // .classed('active', true);
273
+ //})
274
+ //.on('mouseout', () => {
275
+ // this.tooltip.classed('active', false);
276
+ //})
277
+ //.on('mousemove', () => {
278
+ // this.tooltip
279
+ // .style('left', window.event['pageX'] - 28 + 'px')
280
+ // .style('top', window.event['pageY'] - 40 + 'px');
281
+ //})
282
+ .on('mouseover', (event, d) => {
283
+ const total = d3.sum(this.data, (d) => d.value);
284
+ const value = d.data.value > 0 && total > 0 ? Math.round((d.data.value / total) * 100) : 0;
285
+ const key = d.data[this.cfg.key];
286
+ this.centerText.text(`${key}: ${value}%`);
287
+ })
288
+ .on('mouseout', () => {
289
+ this.centerText.text('');
290
+ })
291
+ .transition(this.transition)
292
+ .delay((d, i) => i * this.cfg.transition.duration)
293
+ .attrTween('d', (d) => {
294
+ const i = d3.interpolate(d.startAngle + 0.1, d.endAngle);
295
+ return (t) => {
296
+ d.endAngle = i(t);
297
+ return this.arc(d);
298
+ };
299
+ })
300
+ .style('fill', (d) => this.cfg.color.default)
301
+ .style('opacity', 1);
302
+
303
+ // FILLS
304
+ newg
305
+ .append('path')
306
+ .attr('class', 'chart__slice chart__slice--sliceschart')
307
+ .transition(this.transition)
308
+ .delay((d, i) => i * this.cfg.transition.duration)
309
+ .attrTween('d', (d) => {
310
+ const i = d3.interpolate(d.startAngle + 0.1, d.endAngle);
311
+ const arc = d3
312
+ .arc()
313
+ .outerRadius(this.rScale(d.data[this.cfg.value]))
314
+ .innerRadius(this.inRadius)
315
+ .cornerRadius(this.cfg.radius.round);
316
+ return (t) => {
317
+ d.endAngle = i(t);
318
+ return arc(d);
319
+ };
320
+ })
321
+ .style('fill', (d) => this.colorElement(d.data))
322
+ .style('pointer-events', 'none')
323
+ .style('opacity', 1);
324
+ }
325
+
326
+ /**
327
+ * Update chart's elements based on data change
328
+ */
329
+ updateElements() {
330
+ /*
331
+ // PATHS
332
+ this.itemg.selectAll(".chart__slice")
333
+ .style('opacity', 0)
334
+ .data(this.pie(this.data), d => d.data[this.cfg.key])
335
+ .transition(this.transition)
336
+ .delay((d,i) => i * this.cfg.transition.duration)
337
+ .attrTween('d', d => {
338
+ const i = d3.interpolate(d.startAngle+0.1, d.endAngle);
339
+ return t => {
340
+ d.endAngle = i(t);
341
+ return this.arc(d)
342
+ }
343
+ })
344
+ .style("fill", this.cfg.color.default)
345
+ .style('opacity', 1);
346
+ */
347
+ }
348
+
349
+ /**
350
+ * Remove chart's elements without data
351
+ */
352
+ exitElements() {
353
+ this.itemg.exit().transition(this.transition).style('opacity', 0).remove();
354
+ }
355
+
356
+ midAngle(d) {
357
+ return d.startAngle + (d.endAngle - d.startAngle) / 2;
358
+ }
359
+
360
+ /**
361
+ * Store the displayed angles in _current.
362
+ * Then, interpolate from _current to the new angles.
363
+ * During the transition, _current is updated in-place by d3.interpolate.
364
+ */
365
+ arcTween(a) {
366
+ var i = d3.interpolate(this._current, a);
367
+ this._current = i(0);
368
+ return (t) => this.arc(i(t));
369
+ }
370
+ }
371
+
372
+ export default d3sliceschart;
@@ -0,0 +1,20 @@
1
+ <script>
2
+ import D3Chart from '../d3.chart.vue';
3
+ import d3sliceschart from './d3.sliceschart';
4
+
5
+ export default {
6
+ name: 'D3SlicesChart',
7
+ extends: D3Chart,
8
+ mounted() {
9
+ this.chart = new d3sliceschart(
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
+ @import '../styles';
20
+ </style>