w-plot-vue 1.0.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 (172) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.js +55 -0
  4. package/.jsdoc +25 -0
  5. package/LICENSE +21 -0
  6. package/README.md +89 -0
  7. package/SECURITY.md +5 -0
  8. package/babel.config.js +15 -0
  9. package/dist/w-geo-vue.umd.js +7 -0
  10. package/dist/w-geo-vue.umd.js.map +1 -0
  11. package/docs/examples/app.html +65 -0
  12. package/docs/examples/app.umd.js +7 -0
  13. package/docs/examples/app.umd.js.map +1 -0
  14. package/docs/examples/w-bar_horizontal_multi-set(color).html +492 -0
  15. package/docs/examples/w-bar_horizontal_multi-set(color, gradient).html +492 -0
  16. package/docs/examples/w-bar_horizontal_multi-set(series color).html +492 -0
  17. package/docs/examples/w-bar_horizontal_multi-set(series color, gradient).html +492 -0
  18. package/docs/examples/w-bar_horizontal_multi-set.html +492 -0
  19. package/docs/examples/w-bar_horizontal_multi-set__barDisplay(stackNormal).html +495 -0
  20. package/docs/examples/w-bar_horizontal_multi-set__barDisplay(stackPercent).html +496 -0
  21. package/docs/examples/w-bar_horizontal_multi-set__hide legned.html +492 -0
  22. package/docs/examples/w-bar_horizontal_multi-set__show labels.html +492 -0
  23. package/docs/examples/w-bar_horizontal_multi-set_barKpColor(gradient).html +508 -0
  24. package/docs/examples/w-bar_horizontal_multi-set_barKpColor.html +506 -0
  25. package/docs/examples/w-bar_horizontal_multi-set_barWidthRatio.html +493 -0
  26. package/docs/examples/w-bar_horizontal_multi-set_barWidthRatio_barGroupWidthRatio.html +498 -0
  27. package/docs/examples/w-bar_horizontal_one-set(color).html +490 -0
  28. package/docs/examples/w-bar_horizontal_one-set(color, gradient).html +490 -0
  29. package/docs/examples/w-bar_horizontal_one-set.html +490 -0
  30. package/docs/examples/w-bar_horizontal_one-set_barColor(gradient).html +491 -0
  31. package/docs/examples/w-bar_horizontal_one-set_barColor.html +491 -0
  32. package/docs/examples/w-bar_horizontal_one-set_barKpColor(gradient).html +500 -0
  33. package/docs/examples/w-bar_horizontal_one-set_barKpColor.html +498 -0
  34. package/docs/examples/w-bar_horizontal_one-set_barWidthRatio.html +491 -0
  35. package/docs/examples/w-bar_horizontal_one-set_barWidthRatio_barGroupWidthRatio.html +496 -0
  36. package/docs/examples/w-bar_horizontal_one-set_hide labels.html +491 -0
  37. package/docs/examples/w-bar_horizontal_one-set_marginLeft_marginRight.html +495 -0
  38. package/docs/examples/w-bar_horizontal_one-set_show legned.html +491 -0
  39. package/docs/examples/w-bar_multi-set(color).html +489 -0
  40. package/docs/examples/w-bar_multi-set(color, gradient).html +489 -0
  41. package/docs/examples/w-bar_multi-set(series color).html +489 -0
  42. package/docs/examples/w-bar_multi-set(series color, gradient).html +489 -0
  43. package/docs/examples/w-bar_multi-set.html +489 -0
  44. package/docs/examples/w-bar_multi-set__barDisplay(stackNormal).html +490 -0
  45. package/docs/examples/w-bar_multi-set__barDisplay(stackNormal)_.html +492 -0
  46. package/docs/examples/w-bar_multi-set__barDisplay(stackPercent).html +491 -0
  47. package/docs/examples/w-bar_multi-set__hide legned.html +489 -0
  48. package/docs/examples/w-bar_multi-set__show labels.html +489 -0
  49. package/docs/examples/w-bar_multi-set_barKpColor(gradient).html +503 -0
  50. package/docs/examples/w-bar_multi-set_barKpColor.html +503 -0
  51. package/docs/examples/w-bar_multi-set_barWidthRatio.html +490 -0
  52. package/docs/examples/w-bar_multi-set_barWidthRatio_barGroupWidthRatio_barBorderRadius.html +495 -0
  53. package/docs/examples/w-bar_one-set(color).html +487 -0
  54. package/docs/examples/w-bar_one-set(color, gradient).html +487 -0
  55. package/docs/examples/w-bar_one-set.html +487 -0
  56. package/docs/examples/w-bar_one-set_barColor(gradient).html +488 -0
  57. package/docs/examples/w-bar_one-set_barColor.html +488 -0
  58. package/docs/examples/w-bar_one-set_barKpColor(gradient).html +495 -0
  59. package/docs/examples/w-bar_one-set_barKpColor.html +495 -0
  60. package/docs/examples/w-bar_one-set_barWidthRatio.html +488 -0
  61. package/docs/examples/w-bar_one-set_barWidthRatio_barGroupWidthRatio_barBorderRadius.html +493 -0
  62. package/docs/examples/w-bar_one-set_hide labels.html +488 -0
  63. package/docs/examples/w-bar_one-set_marginLeft_marginRight_marginTop.html +493 -0
  64. package/docs/examples/w-bar_one-set_show legned.html +488 -0
  65. package/docs/examples/w-pie_one-set(color).html +251 -0
  66. package/docs/examples/w-pie_one-set(color, gradient).html +251 -0
  67. package/docs/examples/w-pie_one-set.html +251 -0
  68. package/docs/examples/w-pie_one-set_hide labels.html +252 -0
  69. package/docs/examples/w-pie_one-set_hide legned.html +252 -0
  70. package/docs/examples/w-pie_one-set_marginLeft_marginRight_marginTop.html +257 -0
  71. package/docs/examples/w-pie_one-set_pieBorderRadius.html +252 -0
  72. package/docs/examples/w-pie_one-set_pieBorderWidth_pieBorderRadius.html +253 -0
  73. package/docs/examples/w-pie_one-set_pieKpColor(gradient).html +259 -0
  74. package/docs/examples/w-pie_one-set_pieKpColor.html +259 -0
  75. package/docs/examples/w-pie_one-set_pieThicknessRatio.html +252 -0
  76. package/docs/examples/w-plot_default.html +174 -0
  77. package/docs/examples/w-rose_multi-set(color).html +489 -0
  78. package/docs/examples/w-rose_multi-set(color, gradient).html +489 -0
  79. package/docs/examples/w-rose_multi-set(series color).html +489 -0
  80. package/docs/examples/w-rose_multi-set(series color, gradient).html +489 -0
  81. package/docs/examples/w-rose_multi-set.html +489 -0
  82. package/docs/examples/w-rose_multi-set__hide legned.html +489 -0
  83. package/docs/examples/w-rose_multi-set__show labels.html +489 -0
  84. package/docs/examples/w-rose_multi-set_roseBorderWidth.html +490 -0
  85. package/docs/examples/w-rose_multi-set_roseKpColor(gradient).html +503 -0
  86. package/docs/examples/w-rose_multi-set_roseKpColor.html +503 -0
  87. package/docs/examples/w-rose_multi-set_roseWidthRatio.html +490 -0
  88. package/docs/examples/w-rose_one-set(color).html +487 -0
  89. package/docs/examples/w-rose_one-set(color, gradient).html +487 -0
  90. package/docs/examples/w-rose_one-set.html +487 -0
  91. package/docs/examples/w-rose_one-set_marginLeft_marginRight_marginTop.html +493 -0
  92. package/docs/examples/w-rose_one-set_roseBorderWidth.html +488 -0
  93. package/docs/examples/w-rose_one-set_roseKpColor(gradient).html +495 -0
  94. package/docs/examples/w-rose_one-set_roseKpColor.html +495 -0
  95. package/docs/examples/w-rose_one-set_roseShowLabels.html +488 -0
  96. package/docs/examples/w-rose_one-set_roseWidthRatio.html +488 -0
  97. package/docs/examples/w-rose_one-set_showLegend.html +488 -0
  98. package/docs/examples/w-rose_one-set_showLegend_legendPosition.html +489 -0
  99. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  100. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  101. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  102. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  103. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  104. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  105. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  106. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  107. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  108. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  109. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  110. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  111. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  112. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  113. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  114. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  115. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  116. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  117. package/docs/getDefAxis.mjs.html +157 -0
  118. package/docs/getDefChart.mjs.html +123 -0
  119. package/docs/getDefLegend.mjs.html +115 -0
  120. package/docs/getDefOpt.mjs.html +137 -0
  121. package/docs/global.html +1088 -0
  122. package/docs/index.html +84 -0
  123. package/docs/module-WBar.html +216 -0
  124. package/docs/module-WPie.html +216 -0
  125. package/docs/module-WPlot.html +216 -0
  126. package/docs/module-WRose.html +216 -0
  127. package/docs/scripts/collapse.js +39 -0
  128. package/docs/scripts/commonNav.js +28 -0
  129. package/docs/scripts/linenumber.js +25 -0
  130. package/docs/scripts/nav.js +12 -0
  131. package/docs/scripts/polyfill.js +4 -0
  132. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  133. package/docs/scripts/prettify/lang-css.js +2 -0
  134. package/docs/scripts/prettify/prettify.js +28 -0
  135. package/docs/scripts/search.js +99 -0
  136. package/docs/setLegendLoc.mjs.html +176 -0
  137. package/docs/styles/jsdoc.css +776 -0
  138. package/docs/styles/prettify.css +80 -0
  139. package/g.mjs +0 -0
  140. package/package.json +68 -0
  141. package/public/index.html +38 -0
  142. package/src/App.vue +118 -0
  143. package/src/AppZoneWBar.vue +1454 -0
  144. package/src/AppZoneWPie.vue +324 -0
  145. package/src/AppZoneWPlot.vue +78 -0
  146. package/src/AppZoneWRose.vue +735 -0
  147. package/src/components/WBar.vue +107 -0
  148. package/src/components/WGeoVue.vue +18 -0
  149. package/src/components/WPie.vue +107 -0
  150. package/src/components/WPlot.vue +86 -0
  151. package/src/components/WRose.vue +107 -0
  152. package/src/components/demolink.vue +105 -0
  153. package/src/js/genBarOpt.mjs +303 -0
  154. package/src/js/genPieOpt.mjs +233 -0
  155. package/src/js/genRoseOpt.mjs +297 -0
  156. package/src/js/getDefAxis.mjs +85 -0
  157. package/src/js/getDefChart.mjs +51 -0
  158. package/src/js/getDefLegend.mjs +43 -0
  159. package/src/js/getDefOpt.mjs +65 -0
  160. package/src/js/setLegendLoc.mjs +104 -0
  161. package/src/main.js +8 -0
  162. package/test/all.test.mjs +10 -0
  163. package/toolg/addVersion.mjs +4 -0
  164. package/toolg/cleanFolder.mjs +4 -0
  165. package/toolg/cvCasename.mjs +43 -0
  166. package/toolg/gDistApp.mjs +38 -0
  167. package/toolg/gDistRollupComps.mjs +21 -0
  168. package/toolg/gDocExams.mjs +47 -0
  169. package/toolg/gExtractHtml.mjs +263 -0
  170. package/toolg/gMergeComps.mjs +75 -0
  171. package/toolg/modifyReadme.mjs +4 -0
  172. package/vue.config.js +21 -0
@@ -0,0 +1,303 @@
1
+ import get from 'lodash-es/get'
2
+ import map from 'lodash-es/map'
3
+ import each from 'lodash-es/each'
4
+ import size from 'lodash-es/size'
5
+ import merge from 'lodash-es/merge'
6
+ import isNumber from 'lodash-es/isNumber'
7
+ // import cloneDeep from 'lodash-es/cloneDeep'
8
+ import haskey from 'wsemi/src/haskey.mjs'
9
+ // import isestr from 'wsemi/src/isestr.mjs'
10
+ import iseobj from 'wsemi/src/iseobj.mjs'
11
+ import isearr from 'wsemi/src/isearr.mjs'
12
+ import getDefOpt from './getDefOpt.mjs'
13
+ import getDefChart from './getDefChart.mjs'
14
+ import getDefAxis from './getDefAxis.mjs'
15
+ import getDefLegend from './getDefLegend.mjs'
16
+ import setLegendLoc from './setLegendLoc.mjs'
17
+
18
+
19
+ function genBarOpt(width, height, keys, rds, optPlot = {}) {
20
+
21
+ //marginLeft, marginRight, marginTop, marginBottom
22
+ let marginLeft = get(optPlot, 'marginLeft', null)
23
+ let marginRight = get(optPlot, 'marginRight', null)
24
+ let marginTop = get(optPlot, 'marginTop', null)
25
+ let marginBottom = get(optPlot, 'marginBottom', null)
26
+
27
+ //direction
28
+ let direction = get(optPlot, 'direction', 'vertical')
29
+
30
+ //xTitle
31
+ let xTitle = get(optPlot, 'xTitle', '')
32
+
33
+ //yTitle
34
+ let yTitle = get(optPlot, 'yTitle', '')
35
+
36
+ //barColor
37
+ let barColor = get(optPlot, 'barColor', undefined)
38
+
39
+ //barKpColor
40
+ let barKpColor = get(optPlot, 'barKpColor', undefined)
41
+
42
+ //barGroupWidthRatio
43
+ let barGroupWidthRatio = get(optPlot, 'barGroupWidthRatio', 0.2)
44
+
45
+ //barWidthRatio
46
+ let barWidthRatio = get(optPlot, 'barWidthRatio', 0.2)
47
+
48
+ // //barPointWidth
49
+ // let barPointWidth = get(optPlot, 'barPointWidth', 13)
50
+
51
+ //barBorderWidth
52
+ let barBorderWidth = get(optPlot, 'barBorderWidth', 1)
53
+
54
+ //barDisplay
55
+ let barDisplay = get(optPlot, 'barDisplay', 'separate')
56
+ if (barDisplay !== 'separate' && barDisplay !== 'stackNormal' && barDisplay !== 'stackPercent') {
57
+ barDisplay = 'separate'
58
+ }
59
+
60
+ //barStacking
61
+ let barStacking
62
+ if (barDisplay === 'stackNormal') {
63
+ barStacking = 'normal'
64
+ }
65
+ else if (barDisplay === 'stackPercent') {
66
+ barStacking = 'percent'
67
+ }
68
+
69
+ //barBorderRadius
70
+ let barBorderRadius = get(optPlot, 'barBorderRadius', 4)
71
+
72
+ //barShowLabels
73
+ let barShowLabels = get(optPlot, 'barShowLabels', true)
74
+
75
+ //showLegend
76
+ let showLegend = get(optPlot, 'showLegend', false)
77
+
78
+ //categories
79
+ let categories = keys
80
+ // console.log('categories', categories)
81
+
82
+ //gvc
83
+ let gvc = (color) => {
84
+ if (isearr(color)) {
85
+ let n = size(color)
86
+ if (n === 1) {
87
+ color = color[0]
88
+ }
89
+ else {
90
+ let stops = map(color, (c, kc) => {
91
+ return [kc / (n - 1), c]
92
+ })
93
+ color = {
94
+ linearGradient: { x1: 0, x2: 0, y1: 0, y2: 1 },
95
+ stops,
96
+ }
97
+ }
98
+ }
99
+ return color
100
+ }
101
+
102
+ //ds
103
+ let ds = []
104
+ each(rds, (rd, krd) => {
105
+
106
+ //name
107
+ let name = get(rd, 'name', '')
108
+ // console.log('name', name)
109
+
110
+ //_color1
111
+ let _color1 = barColor
112
+
113
+ //_color2
114
+ let _color2 = get(rd, 'color', undefined)
115
+
116
+ //_data
117
+ let _data = get(rd, 'data', {})
118
+
119
+ //data
120
+ let colorFirst = null
121
+ let data = []
122
+ each(keys, (k) => {
123
+
124
+ //vo
125
+ let vo = get(_data, k, null)
126
+
127
+ //v
128
+ let v = vo
129
+ if (iseobj(v)) {
130
+ if (!haskey(v, 'value')) {
131
+ throw new Error('bar data is an object but no value')
132
+ }
133
+ v = get(v, 'value', null)
134
+ }
135
+ // console.log(k, v)
136
+
137
+ //_color3, _color4, _color5
138
+ let _color3 = get(barKpColor, k, undefined)
139
+ let _color4 = get(barKpColor, `${krd}.${k}`, undefined)
140
+ let _color5 = get(vo, 'color', undefined)
141
+
142
+ //color
143
+ let color = gvc(_color1 || _color2 || _color3 || _color4 || _color5) //指定各bar顏色
144
+
145
+ if (colorFirst === null) {
146
+ colorFirst = color
147
+ }
148
+
149
+ //push
150
+ data.push({
151
+ name: k,
152
+ y: v,
153
+ color,
154
+ })
155
+
156
+ })
157
+ // console.log('colorFirst', colorFirst)
158
+ // console.log('data', data)
159
+
160
+ //push
161
+ ds.push({
162
+ name,
163
+ data,
164
+ color: colorFirst,
165
+ })
166
+
167
+ })
168
+ // console.log('ds', ds)
169
+
170
+ //dopt
171
+ let dopt = getDefOpt(optPlot)
172
+
173
+ //dct
174
+ let dct = getDefChart(optPlot)
175
+
176
+ //dax
177
+ let _dax1 = getDefAxis(optPlot)
178
+ let _dax2 = {
179
+ categories,
180
+ crosshair: true,
181
+ panningEnabled: false,
182
+ labels: {
183
+ allowOverlap: true,
184
+ // autoRotationLimit: 0,
185
+ // rotation: 50,
186
+ },
187
+ }
188
+ let dax = merge(_dax1, _dax2)
189
+ dax.title.text = xTitle
190
+ // dax.min = xmin
191
+ // dax.max = xmax
192
+ // if (!isestr(xtitle)) {
193
+ // dax.labels.formatter = function () {
194
+ // return ''
195
+ // }
196
+ // }
197
+ dax.opposite = false
198
+ // console.log('dax', dax)
199
+
200
+ //day
201
+ let day = getDefAxis(optPlot)
202
+ day.title.text = yTitle
203
+ day.min = 0 //從0開始
204
+ // day.opposite = false
205
+ // console.log('day', day)
206
+
207
+ //dlg
208
+ let dlg = getDefLegend(optPlot)
209
+ // console.log('dlg', dlg)
210
+
211
+ //optHc
212
+ let optHc = {
213
+ ...dopt,
214
+
215
+ chart: {
216
+ ...dct,
217
+ type: direction === 'vertical' ? 'column' : 'bar',
218
+ width,
219
+ height,
220
+ },
221
+
222
+ xAxis: dax,
223
+
224
+ yAxis: day,
225
+
226
+ legend: dlg,
227
+
228
+ series: ds,
229
+
230
+ }
231
+
232
+ // optHc.tooltip = {
233
+ // headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
234
+ // pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
235
+ // '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
236
+ // footerFormat: '</table>',
237
+ // shared: true,
238
+ // useHTML: true
239
+ // }
240
+
241
+ //margin
242
+ if (true) {
243
+ if (isNumber(marginLeft)) {
244
+ optHc.chart.marginLeft = marginLeft
245
+ }
246
+ if (isNumber(marginRight)) {
247
+ optHc.chart.marginRight = marginRight
248
+ }
249
+ if (isNumber(marginTop)) {
250
+ optHc.chart.marginTop = marginTop
251
+ }
252
+ if (isNumber(marginBottom)) {
253
+ optHc.chart.marginBottom = marginBottom
254
+ }
255
+ // console.log('optHc(margin)', optHc)
256
+ }
257
+
258
+ //column
259
+ if (true) {
260
+ optHc.plotOptions = {
261
+ ...optHc.plotOptions,
262
+
263
+ series: {
264
+ groupPadding: barGroupWidthRatio,
265
+ pointPadding: barWidthRatio,
266
+ // pointWidth: barPointWidth,
267
+ borderWidth: barBorderWidth,
268
+ // crisp: false,
269
+ // centerInCategory: false,
270
+ grouping: true,
271
+ borderRadius: barBorderRadius,
272
+ // dataSorting: {
273
+ // enabled: true,
274
+ // },
275
+ stacking: barStacking, //undefined, "normal", "overlap", "percent", "stream"
276
+ dataLabels: {
277
+ enabled: barShowLabels,
278
+ allowOverlap: true,
279
+ // align: 'center',
280
+ },
281
+ },
282
+
283
+ }
284
+ // console.log('optHc(column)', optHc)
285
+ }
286
+
287
+ //legend
288
+ if (true) {
289
+
290
+ //setLegendLoc
291
+ optHc = setLegendLoc(optHc, optPlot)
292
+
293
+ //showLegend
294
+ optHc.legend.enabled = showLegend
295
+
296
+ // console.log('optHc(legend)', optHc)
297
+ }
298
+
299
+ return optHc
300
+ }
301
+
302
+
303
+ export default genBarOpt
@@ -0,0 +1,233 @@
1
+ import get from 'lodash-es/get'
2
+ import map from 'lodash-es/map'
3
+ import each from 'lodash-es/each'
4
+ import size from 'lodash-es/size'
5
+ // import merge from 'lodash-es/merge'
6
+ import isNumber from 'lodash-es/isNumber'
7
+ // import cloneDeep from 'lodash-es/cloneDeep'
8
+ import haskey from 'wsemi/src/haskey.mjs'
9
+ // import isestr from 'wsemi/src/isestr.mjs'
10
+ import iseobj from 'wsemi/src/iseobj.mjs'
11
+ import isearr from 'wsemi/src/isearr.mjs'
12
+ import getDefOpt from './getDefOpt.mjs'
13
+ import getDefChart from './getDefChart.mjs'
14
+ // import getDefAxis from './getDefAxis.mjs'
15
+ import getDefLegend from './getDefLegend.mjs'
16
+ import setLegendLoc from './setLegendLoc.mjs'
17
+
18
+
19
+ function genPieOpt(width, height, keys, rds, optPlot = {}) {
20
+
21
+ //marginLeft, marginRight, marginTop, marginBottom
22
+ let marginLeft = get(optPlot, 'marginLeft', null)
23
+ let marginRight = get(optPlot, 'marginRight', null)
24
+ let marginTop = get(optPlot, 'marginTop', null)
25
+ let marginBottom = get(optPlot, 'marginBottom', null)
26
+
27
+ //pieThicknessRatio
28
+ let pieThicknessRatio = get(optPlot, 'pieThicknessRatio', 0.6)
29
+ pieThicknessRatio = Math.min(pieThicknessRatio, 1)
30
+ pieThicknessRatio = Math.max(pieThicknessRatio, 0)
31
+
32
+ //pieBorderRadius
33
+ let pieBorderRadius = get(optPlot, 'pieBorderRadius', 4)
34
+
35
+ //pieKpColor
36
+ let pieKpColor = get(optPlot, 'pieKpColor', undefined)
37
+
38
+ //pieBorderWidth
39
+ let pieBorderWidth = get(optPlot, 'pieBorderWidth', 1)
40
+
41
+ //pieShowLabels
42
+ let pieShowLabels = get(optPlot, 'pieShowLabels', true)
43
+
44
+ //showLegend
45
+ let showLegend = get(optPlot, 'showLegend', true)
46
+
47
+ //gvc
48
+ let gvc = (color) => {
49
+ if (isearr(color)) {
50
+ let n = size(color)
51
+ if (n === 1) {
52
+ color = color[0]
53
+ }
54
+ else {
55
+ let stops = map(color, (c, kc) => {
56
+ return [kc / (n - 1), c]
57
+ })
58
+ color = {
59
+ linearGradient: { x1: 0, x2: 0, y1: 0, y2: 1 },
60
+ stops,
61
+ }
62
+ }
63
+ }
64
+ return color
65
+ }
66
+
67
+ //ds
68
+ let ds = []
69
+ each(rds, (rd, krd) => {
70
+
71
+ //name
72
+ let name = get(rd, 'name', '')
73
+ // console.log('name', name)
74
+
75
+ //_color1
76
+ let _color1 = null
77
+
78
+ //_color2
79
+ let _color2 = get(rd, 'color', undefined)
80
+
81
+ //_data
82
+ let _data = get(rd, 'data', {})
83
+
84
+ //data
85
+ let colorFirst = null
86
+ let data = []
87
+ each(keys, (k) => {
88
+
89
+ //vo
90
+ let vo = get(_data, k, null)
91
+
92
+ //v
93
+ let v = vo
94
+ if (iseobj(v)) {
95
+ if (!haskey(v, 'value')) {
96
+ throw new Error('pie data is an object but no value')
97
+ }
98
+ v = get(v, 'value', null)
99
+ }
100
+ // console.log(k, v)
101
+
102
+ //_color3, _color4, _color5
103
+ let _color3 = get(pieKpColor, k, undefined)
104
+ let _color4 = get(pieKpColor, `${krd}.${k}`, undefined)
105
+ let _color5 = get(vo, 'color', undefined)
106
+
107
+ //color
108
+ let color = gvc(_color1 || _color2 || _color3 || _color4 || _color5) //指定各pie顏色
109
+
110
+ if (colorFirst === null) {
111
+ colorFirst = color
112
+ }
113
+
114
+ //push
115
+ data.push({
116
+ name: k,
117
+ y: v,
118
+ color,
119
+ })
120
+
121
+ })
122
+ // console.log('colorFirst', colorFirst)
123
+ // console.log('data', data)
124
+
125
+ //push
126
+ ds.push({
127
+ name,
128
+ data,
129
+ color: colorFirst,
130
+ })
131
+
132
+ })
133
+ // console.log('ds', ds)
134
+
135
+ //dopt
136
+ let dopt = getDefOpt(optPlot)
137
+
138
+ //dct
139
+ let dct = getDefChart({
140
+ ...optPlot,
141
+ marginLeftShift: 0,
142
+ marginRightShift: 0,
143
+ marginTopShift: 0,
144
+ marginBottomShift: 0,
145
+ plotBorderColor: 'transparent',
146
+ })
147
+ // console.log('dct', dct)
148
+
149
+ //dlg
150
+ let dlg = getDefLegend(optPlot)
151
+ // console.log('dlg', dlg)
152
+
153
+ //optHc
154
+ let optHc = {
155
+ ...dopt,
156
+
157
+ chart: {
158
+ ...dct,
159
+ type: 'pie',
160
+ width,
161
+ height,
162
+ },
163
+
164
+ legend: dlg,
165
+
166
+ series: ds,
167
+
168
+ }
169
+
170
+ //margin
171
+ if (true) {
172
+ if (isNumber(marginLeft)) {
173
+ optHc.chart.marginLeft = marginLeft
174
+ }
175
+ if (isNumber(marginRight)) {
176
+ optHc.chart.marginRight = marginRight
177
+ }
178
+ if (isNumber(marginTop)) {
179
+ optHc.chart.marginTop = marginTop
180
+ }
181
+ if (isNumber(marginBottom)) {
182
+ optHc.chart.marginBottom = marginBottom
183
+ }
184
+ // console.log('optHc(margin)', optHc)
185
+ }
186
+
187
+ //pie
188
+ if (true) {
189
+ optHc.plotOptions = {
190
+ ...optHc.plotOptions,
191
+
192
+ series: {
193
+ borderWidth: pieBorderWidth,
194
+ dataLabels: {
195
+ enabled: pieShowLabels,
196
+ allowOverlap: true,
197
+ // distance: 10,
198
+ format: `
199
+ <div style="width:50px;">
200
+ <div style="font-weight:bold;">{point.name}</div>
201
+ <div style="opacity:0.6;">{point.percentage:.1f}%</div>
202
+ </div>
203
+ `,
204
+ },
205
+ innerSize: `${(1 - pieThicknessRatio) * 100}%`,
206
+ borderRadius: pieBorderRadius,
207
+ showInLegend: showLegend,
208
+ },
209
+
210
+ }
211
+ // console.log('optHc(pie)', optHc)
212
+ }
213
+
214
+ //legend
215
+ if (true) {
216
+
217
+ //setLegendLoc
218
+ optHc = setLegendLoc(optHc, {
219
+ ...optPlot,
220
+ legendIgnoreMargin: true,
221
+ })
222
+
223
+ //showLegend
224
+ optHc.legend.enabled = showLegend
225
+
226
+ // console.log('optHc(legend)', optHc)
227
+ }
228
+
229
+ return optHc
230
+ }
231
+
232
+
233
+ export default genPieOpt