@mixd-id/web-scaffold 0.2.240702 → 0.2.240704

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 (95) hide show
  1. package/docs/schema/user-action.json +266 -0
  2. package/package.json +6 -2
  3. package/public/assets/dashboard/bar.png +0 -0
  4. package/public/assets/dashboard/doughnut.png +0 -0
  5. package/public/assets/dashboard/metric.png +0 -0
  6. package/public/assets/dashboard/pie.png +0 -0
  7. package/public/assets/dashboard/polar-area.png +0 -0
  8. package/public/assets/dashboard/virtual-table.png +0 -0
  9. package/public/static/dashboard/bar.png +0 -0
  10. package/public/static/dashboard/doughnut.png +0 -0
  11. package/public/static/dashboard/metric.png +0 -0
  12. package/public/static/dashboard/pie.png +0 -0
  13. package/public/static/dashboard/polar-area.png +0 -0
  14. package/public/static/dashboard/virtual-table.png +0 -0
  15. package/src/components/Button.vue +179 -160
  16. package/src/components/Checkbox.vue +0 -1
  17. package/src/components/Datepicker.vue +8 -6
  18. package/src/components/GHeatMaps.vue +317 -0
  19. package/src/components/GmapsDirection.vue +191 -0
  20. package/src/components/Grid.vue +2 -0
  21. package/src/components/HTMLEditor.vue +2 -2
  22. package/src/components/List.vue +384 -308
  23. package/src/components/Modal.vue +2 -3
  24. package/src/components/PresetSelectorFilterItem.vue +15 -2
  25. package/src/components/Switch.vue +3 -0
  26. package/src/components/Tabs.vue +1 -1
  27. package/src/components/TextWithTag.vue +67 -25
  28. package/src/components/Textbox.vue +5 -0
  29. package/src/components/VirtualGrid.vue +224 -228
  30. package/src/components/VirtualTable.vue +46 -28
  31. package/src/configs/dashboard/bar.js +10 -0
  32. package/src/configs/dashboard/collection-1.js +5 -0
  33. package/src/configs/dashboard/doughnut.js +7 -0
  34. package/src/configs/dashboard/gheatmaps.js +9 -0
  35. package/src/configs/dashboard/grid-2.js +34 -0
  36. package/src/configs/dashboard/grid-3.js +34 -0
  37. package/src/configs/dashboard/grid-4.js +34 -0
  38. package/src/configs/dashboard/grid.js +15 -0
  39. package/src/configs/dashboard/metric.js +10 -0
  40. package/src/configs/dashboard/pie.js +7 -0
  41. package/src/configs/dashboard/polar-area.js +7 -0
  42. package/src/configs/dashboard/virtual-table.js +9 -0
  43. package/src/defs/dashboard-preset.js +22 -0
  44. package/src/index.js +37 -23
  45. package/src/mixin/ready-state.js +37 -0
  46. package/src/stores/datasource.js +11 -0
  47. package/src/themes/default/index.js +1 -1
  48. package/src/utils/dashboard.js +1080 -0
  49. package/src/utils/event-bus.js +8 -0
  50. package/src/utils/helpers.js +56 -8
  51. package/src/utils/helpers.mjs +35 -1
  52. package/src/utils/preset-selector.js +5 -2
  53. package/src/utils/preset-selector.mjs +23 -13
  54. package/src/widgets/BotEditor/BotEditorActions.vue +162 -0
  55. package/src/widgets/BotEditor.vue +228 -0
  56. package/src/widgets/Dashboard/BarChart.vue +330 -0
  57. package/src/widgets/Dashboard/BarChartSetting.vue +317 -0
  58. package/src/widgets/Dashboard/DatasourceFilterSharing.vue +93 -0
  59. package/src/widgets/Dashboard/DatasourcePreview.vue +93 -0
  60. package/src/widgets/Dashboard/DatasourceSelector.vue +122 -0
  61. package/src/widgets/Dashboard/Doughnut.vue +157 -0
  62. package/src/widgets/Dashboard/DoughnutSetting.vue +196 -0
  63. package/src/widgets/Dashboard/GHeatMapsSetting.vue +108 -0
  64. package/src/widgets/Dashboard/InteractionEdit.vue +228 -0
  65. package/src/widgets/Dashboard/Metric.vue +76 -0
  66. package/src/widgets/Dashboard/MetricSetting.vue +174 -0
  67. package/src/widgets/Dashboard/Pie.vue +139 -0
  68. package/src/widgets/Dashboard/PieSetting.vue +247 -0
  69. package/src/widgets/Dashboard/PolarArea.vue +159 -0
  70. package/src/widgets/Dashboard/PolarAreaSetting.vue +195 -0
  71. package/src/widgets/Dashboard/SharingModal.vue +116 -0
  72. package/src/widgets/Dashboard/ViewSelector.vue +183 -0
  73. package/src/widgets/Dashboard/VirtualColumnEdit.vue +97 -0
  74. package/src/widgets/Dashboard/VirtualTableSetting.vue +234 -0
  75. package/src/widgets/Dashboard.vue +1773 -0
  76. package/src/widgets/PresetBar.vue +136 -175
  77. package/src/widgets/PresetBarPivot.vue +186 -0
  78. package/src/widgets/PresetSelector.vue +2 -2
  79. package/src/widgets/UserActionBuilder/UserActionCondition.vue +99 -0
  80. package/src/widgets/UserActionBuilder/UserActionConsole.vue +77 -0
  81. package/src/widgets/UserActionBuilder/UserActionItem.vue +166 -58
  82. package/src/widgets/UserActionBuilder/UserActionOutput.vue +35 -9
  83. package/src/widgets/UserActionBuilder/UserActionOutputDelay.vue +27 -0
  84. package/src/widgets/UserActionBuilder/UserActionOutputLog.vue +28 -0
  85. package/src/widgets/UserActionBuilder/UserActionOutputReply.vue +135 -0
  86. package/src/widgets/UserActionBuilder/UserActionProps.vue +213 -0
  87. package/src/widgets/UserActionBuilder.vue +68 -199
  88. package/src/widgets/WebPageBuilder4/GridSetting.vue +123 -73
  89. package/src/widgets/WebPageBuilder4/HeightSetting.vue +14 -11
  90. package/src/widgets/WebPageBuilder4/MarginSetting.vue +4 -1
  91. package/src/widgets/WebPageBuilder4/MultiValueSetting.vue +12 -4
  92. package/src/widgets/WebPageBuilder4/PaddingSetting.vue +4 -0
  93. package/src/widgets/WebPageBuilder4/TreeView.vue +6 -3
  94. package/src/widgets/WebPageBuilder4/TreeViewItem.vue +32 -58
  95. package/tailwind.config.js +2 -2
@@ -0,0 +1,139 @@
1
+ <template>
2
+ <div v-if="readyState === 1" class="flex flex-col gap-2">
3
+
4
+ <Pie class="aspect-square"
5
+ :options="chartOptions"
6
+ :data="chartData" />
7
+
8
+ <div class="px-3 text-center text-ellipsis overflow-hidden whitespace-nowrap capitalize">
9
+ {{ label }}
10
+ </div>
11
+
12
+ </div>
13
+
14
+ <div v-else-if="readyState === 2" class="aspect-square flex items-center justify-center">
15
+ <label class="text-text-300">Loading...</label>
16
+ </div>
17
+ </template>
18
+
19
+ <script>
20
+
21
+ import {Pie} from 'vue-chartjs'
22
+ import {color} from 'chart.js/helpers'
23
+ import {strVars} from "../../utils/helpers.mjs";
24
+ import {readyStateMixin} from "../../mixin/ready-state";
25
+
26
+ export default{
27
+
28
+ components: {
29
+ Pie
30
+ },
31
+
32
+ computed: {
33
+
34
+ chartData(){
35
+ if(!this.value?.datasets)
36
+ return { labels:[], datasets:[] }
37
+
38
+ return {
39
+ labels: this.value?.labels ?? [],
40
+ datasets: this.value.datasets.map(_ => {
41
+ return {
42
+ ..._,
43
+ borderWidth: 1,
44
+ borderColor: function(context, options) {
45
+ const hex = options.color;
46
+ return color(hex).darken(0.5).rgbString()
47
+ }
48
+ }
49
+ })
50
+ }
51
+ },
52
+
53
+ chartOptions(){
54
+ return {
55
+ responsive: true,
56
+ maintainAspectRatio: true,
57
+ plugins: {
58
+ legend: {
59
+ display: false
60
+ },
61
+ tooltip: {
62
+ callbacks: {
63
+ title: function(tooltipItems) {
64
+ return `${tooltipItems[0].label}`;
65
+ },
66
+ label: (tooltipItem) => {
67
+ const total = tooltipItem.dataset.data.reduce((a, b) => a + b, 0)
68
+ const percentage = ((tooltipItem.raw / total) * 100).toFixed(1)
69
+
70
+ return `${tooltipItem.dataset.label}: ${tooltipItem.raw} (${percentage}%)`;
71
+ }
72
+ },
73
+ },
74
+ },
75
+ onClick: this.onClick
76
+ }
77
+ },
78
+
79
+ },
80
+
81
+ inject: [ 'selectPreset' ],
82
+
83
+ methods: {
84
+
85
+ onClick(e, segments){
86
+
87
+ const clickInteractions = (this.interactions ?? []).filter(_ => _.event === 'click')
88
+ const segment = segments[0]
89
+ if(!segment) return
90
+
91
+ const dataset = this.value.datasets[segment.datasetIndex]
92
+ const obj = {
93
+ segment: this.value.labels[segment.index],
94
+ key: dataset.label,
95
+ value: dataset.data[segment.index]
96
+ }
97
+
98
+ for(let click of clickInteractions){
99
+ const { action, presetUid, filters } = click
100
+
101
+ const params = filters.reduce((res, cur) => {
102
+ res[cur.datasourceUid + '.filters.' + cur.key + '.' + cur.operator] = strVars(cur.value, obj)
103
+ return res
104
+ }, {})
105
+
106
+ switch(action){
107
+
108
+ case 'openDashboardPreset':
109
+ if(typeof this.selectPreset === 'function')
110
+ this.selectPreset(presetUid, params)
111
+ break
112
+ }
113
+ }
114
+
115
+ }
116
+
117
+ },
118
+
119
+ mixins: [ readyStateMixin ],
120
+
121
+ props: {
122
+
123
+ label: String,
124
+
125
+ value: Object,
126
+
127
+ column: Object,
128
+
129
+ datasourceUid: String,
130
+
131
+ interactions: Array,
132
+
133
+ uid: String
134
+
135
+ }
136
+
137
+ }
138
+
139
+ </script>
@@ -0,0 +1,247 @@
1
+ <template>
2
+ <div class="flex flex-col gap-6 p-6">
3
+
4
+ <div class="flex flex-row items-center">
5
+ <label class="flex-1">Active</label>
6
+ <Switch v-model="value.props.enabled" :readonly="readonly" @change="$emit('change')" />
7
+ </div>
8
+
9
+ <div>
10
+ <div class="flex flex-row gap-2">
11
+ <label class="flex-1">Datasource</label>
12
+ <button type="button" class="text-primary"
13
+ @click="previewDatasource(selectedDatasource)">Preview</button>
14
+ </div>
15
+ <Dropdown class="min-w-[150px]"
16
+ :readonly="readonly"
17
+ v-model="value.props.datasourceUid"
18
+ @change="delete value.props.columns">
19
+ <option v-for="obj in datasource"
20
+ :value="obj.uid">
21
+ {{ obj.name }}
22
+ </option>
23
+ </Dropdown>
24
+ </div>
25
+
26
+ <div class="flex flex-col gap-1">
27
+ <label class="text-text-400">Label</label>
28
+ <Textbox v-model="value.props.label" maxlength="50" placeholder="Label" :readonly="readonly" />
29
+ </div>
30
+
31
+ <div v-if="value.props.datasourceUid" class="flex flex-col gap-5">
32
+ <div>
33
+ <label class="text-text-400">Segment</label>
34
+ <div class="flex flex-row gap-2">
35
+ <Dropdown class="min-w-[150px]"
36
+ v-model="value.props.rows"
37
+ :readonly="readonly"
38
+ @change="$emit('change')">
39
+ <option v-for="column in selectedDatasourceColumns"
40
+ :value="column.key">
41
+ {{ column.label }}
42
+ </option>
43
+ </Dropdown>
44
+
45
+ <Dropdown v-model="value.props.rowsModifier"
46
+ :readonly="readonly"
47
+ class="w-[125px]"
48
+ @change="$emit('change')">
49
+ <option value="">-</option>
50
+ <option value="lowercase">Lower</option>
51
+ <option value="capitalize">Capitalize</option>
52
+ <option value="uppercase">Upper</option>
53
+ <option disabled>-----</option>
54
+ <option value="date">Date</option>
55
+ <option value="month">Month</option>
56
+ <option value="year">Year</option>
57
+ <option value="hour">Hour</option>
58
+ <option value="minute">Minute</option>
59
+ </Dropdown>
60
+ </div>
61
+ </div>
62
+
63
+ <div>
64
+ <div class="flex flex-row">
65
+ <label class="flex-1 text-primary cursor-pointer"
66
+ ref="yAxis"
67
+ @click="$refs.context2.open($refs.yAxis)">
68
+ {{ value.props.multipleValues ? 'Multiple Values' : 'Value' }}
69
+ <svg class="fill-primary inline relative top-[-1px]" width="12" height="12" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><!--! Font Awesome Pro 6.0.0-alpha3 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) --><path d="M310.6 246.6l-127.1 128C176.4 380.9 168.2 384 160 384s-16.38-3.125-22.63-9.375l-127.1-128C.2244 237.5-2.516 223.7 2.438 211.8S19.07 192 32 192h255.1c12.94 0 24.62 7.781 29.58 19.75S319.8 237.5 310.6 246.6z"/></svg>
70
+ </label>
71
+ <ContextMenu ref="context2">
72
+ <div class="flex flex-col min-w-[100px]">
73
+
74
+ <button class="w-full p-3 text-left flex flex-row" :class="appStyle.menuItem"
75
+ @click="value.props.multipleValues = false;$emit('change')">
76
+ Single
77
+ </button>
78
+ <button class="w-full p-3 text-left flex flex-row" :class="appStyle.menuItem"
79
+ @click="value.props.multipleValues = true;$emit('change')">
80
+ Multiple
81
+ </button>
82
+ </div>
83
+ </ContextMenu>
84
+ <button v-if="value.props.multipleValues && !readonly" type="button" class="text-primary" @click="column.push({})">
85
+ <svg width="14" height="14" class="fill-primary" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Pro 6.0.0-alpha3 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) --><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"/></svg>
86
+ </button>
87
+ </div>
88
+ <ListItem :items="column"
89
+ class="mt-2 bg-transparent"
90
+ container-class="flex flex-col gap-2"
91
+ @reorder="(from, to) => { column.splice(to, 0, column.splice(from, 1)[0]); $emit('change') }">
92
+ <template v-slot="{ item, index }">
93
+ <div class="flex flex-row items-center gap-2">
94
+ <div data-reorder v-if="column.length > 1">
95
+ <svg width="14" height="14" class="fill-text-300" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M496 288H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h480c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16zm0-128H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h480c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16z"/></svg>
96
+ </div>
97
+ <div class="flex-1 flex flex-row gap-2">
98
+ <Dropdown class="flex-1"
99
+ v-model="item.key"
100
+ :readonly="readonly"
101
+ @change="$emit('change')">
102
+ <option v-for="column in selectedDatasourceColumns"
103
+ :value="column.key">
104
+ {{ column.label }}
105
+ </option>
106
+ </Dropdown>
107
+
108
+ <Dropdown v-model="item.modifier"
109
+ :readonly="readonly"
110
+ class="w-[125px]"
111
+ @change="$emit('change')">
112
+ <option value="">-</option>
113
+ <option value="count">Count</option>
114
+ <option value="countDistinct">Unique Count</option>
115
+ <option value="sum">Sum</option>
116
+ <option value="avg">Avg</option>
117
+ <option value="min">Min</option>
118
+ <option value="max">Max</option>
119
+ </Dropdown>
120
+ </div>
121
+ <button v-if="column.length > 1 && !readonly" type="button" @click="column.splice(index, 1);$emit('change')">
122
+ <svg width="16" height="16" class="fill-text-300 hover:fill-red-500" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M207.6 256l107.72-107.72c6.23-6.23 6.23-16.34 0-22.58l-25.03-25.03c-6.23-6.23-16.34-6.23-22.58 0L160 208.4 52.28 100.68c-6.23-6.23-16.34-6.23-22.58 0L4.68 125.7c-6.23 6.23-6.23 16.34 0 22.58L112.4 256 4.68 363.72c-6.23 6.23-6.23 16.34 0 22.58l25.03 25.03c6.23 6.23 16.34 6.23 22.58 0L160 303.6l107.72 107.72c6.23 6.23 16.34 6.23 22.58 0l25.03-25.03c6.23-6.23 6.23-16.34 0-22.58L207.6 256z"/></svg>
123
+ </button>
124
+ </div>
125
+ </template>
126
+ </ListItem>
127
+ </div>
128
+
129
+ <div>
130
+ <div class="flex flex-row gap-2">
131
+ <label class="text-text-400 flex-1">Interactions</label>
132
+ <button type="button" class="text-primary" @click="$refs.interactionEdit.create()">
133
+ <svg width="14" height="14" class="fill-primary" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Pro 6.0.0-alpha3 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) --><path d="M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"/></svg>
134
+ </button>
135
+ </div>
136
+ <div class="mt-1">
137
+ <ListItem :items="interactions"
138
+ class="rounded-xl"
139
+ container-class="flex flex-col divide-y divide-text-50"
140
+ @reorder="(from, to) => { interactions.splice(to, 0, interactions.splice(from, 1)[0]); }">
141
+ <template v-slot="{ item, index }">
142
+ <div class="flex flex-row items-center gap-3 px-3">
143
+ <div data-reorder v-if="interactions.length > 1">
144
+ <svg width="14" height="14" class="fill-text-300" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M496 288H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h480c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16zm0-128H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h480c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16z"/></svg>
145
+ </div>
146
+ <div class="flex-1 p-3 cursor-pointer" @click="$refs.interactionEdit.open(item)">
147
+ {{ item.event }}
148
+ {{ item.eventModifier ? item.eventModifier : '' }}
149
+ </div>
150
+ <button type="button" @click="interactions.splice(index, 1)">
151
+ <svg width="16" height="16" class="fill-text-300 hover:fill-red-500" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M207.6 256l107.72-107.72c6.23-6.23 6.23-16.34 0-22.58l-25.03-25.03c-6.23-6.23-16.34-6.23-22.58 0L160 208.4 52.28 100.68c-6.23-6.23-16.34-6.23-22.58 0L4.68 125.7c-6.23 6.23-6.23 16.34 0 22.58L112.4 256 4.68 363.72c-6.23 6.23-6.23 16.34 0 22.58l25.03 25.03c6.23 6.23 16.34 6.23 22.58 0L160 303.6l107.72 107.72c6.23 6.23 16.34 6.23 22.58 0l25.03-25.03c6.23-6.23 6.23-16.34 0-22.58L207.6 256z"/></svg>
152
+ </button>
153
+ </div>
154
+ </template>
155
+ </ListItem>
156
+
157
+ <InteractionEdit ref="interactionEdit" @save="addInteraction" />
158
+ </div>
159
+ </div>
160
+ </div>
161
+
162
+ </div>
163
+ </template>
164
+
165
+ <script>
166
+
167
+ import InteractionEdit from "./InteractionEdit.vue";
168
+
169
+ export default{
170
+ components: {InteractionEdit},
171
+
172
+ computed: {
173
+
174
+ column(){
175
+ if(!Array.isArray(this.value.props.column))
176
+ this.value.props.column = [ { key:'' } ]
177
+
178
+ if(this.value.props.multipleValues)
179
+ return this.value.props.column
180
+ return [ this.value.props.column[0] ]
181
+ },
182
+
183
+ interactions(){
184
+ if(!Array.isArray(this.value.props.interactions))
185
+ this.value.props.interactions = []
186
+ return this.value.props.interactions
187
+ },
188
+
189
+ selectedDatasource(){
190
+ return this.datasource.find(d => d.uid === this.value.props.datasourceUid)
191
+ },
192
+
193
+ selectedDatasourceColumns(){
194
+ if(!this.selectedDatasource) return []
195
+
196
+ return this.selectedDatasource.pivot?.enabled ?
197
+ this.selectedDatasource.pivot.columns :
198
+ [
199
+ ...(this.selectedDatasource.computedColumns ?? []),
200
+ ...this.selectedDatasource.columns
201
+ ]
202
+ },
203
+
204
+ },
205
+
206
+ emits: [ 'change' ],
207
+
208
+ inject: [ 'appStyle', 'previewDatasource' ],
209
+
210
+ methods: {
211
+
212
+ addInteraction(obj){
213
+ this.$util.push(this.interactions, obj)
214
+ },
215
+
216
+ applyDefault(){
217
+ if(!this.value.props.datasourceUid && this.datasource?.length === 1){
218
+ this.value.props.datasourceUid = this.datasource[0].uid
219
+ }
220
+ },
221
+
222
+ onColumnChanged(){
223
+ if(!this.value.props.label)
224
+ this.value.props.label = this.column[0]
225
+
226
+ this.$emit('change')
227
+ }
228
+
229
+ },
230
+
231
+ mounted() {
232
+ this.applyDefault()
233
+ },
234
+
235
+ props: {
236
+
237
+ datasource: Object,
238
+
239
+ readonly: [ Boolean, Number ],
240
+
241
+ value: Object
242
+
243
+ }
244
+
245
+ }
246
+
247
+ </script>
@@ -0,0 +1,159 @@
1
+ <template>
2
+ <div v-if="readyState === 1" class="flex flex-col gap-2">
3
+ <PolarArea class="aspect-square"
4
+ :options="chartOptions"
5
+ :data="chartData" />
6
+
7
+ <div class="px-3 text-center text-ellipsis overflow-hidden whitespace-nowrap capitalize">
8
+ {{ label }}
9
+ </div>
10
+ </div>
11
+
12
+ <div v-else-if="readyState === 2" class="aspect-square flex items-center justify-center">
13
+ <label class="text-text-300">Loading...</label>
14
+ </div>
15
+ </template>
16
+
17
+ <script>
18
+
19
+ import {PolarArea} from 'vue-chartjs'
20
+ import {color} from 'chart.js/helpers'
21
+ import {strVars} from "../../utils/helpers.mjs";
22
+ import {readyStateMixin} from "../../mixin/ready-state";
23
+
24
+ export default{
25
+
26
+ components: {
27
+ PolarArea
28
+ },
29
+
30
+ computed: {
31
+
32
+ chartData(){
33
+ if(!this.value?.datasets)
34
+ return { labels:[], datasets:[] }
35
+
36
+ return {
37
+ labels: this.value?.labels ?? [],
38
+ datasets: this.value.datasets.map(_ => {
39
+ return {
40
+ ..._,
41
+ borderWidth: 1,
42
+ borderColor: function(context, options) {
43
+ const hex = options.color;
44
+ return color(hex).darken(0.5).rgbString()
45
+ }
46
+ }
47
+ })
48
+ }
49
+ },
50
+
51
+ chartOptions(){
52
+ return {
53
+ responsive: true,
54
+ maintainAspectRatio: true,
55
+ plugins: {
56
+ legend: {
57
+ display: false
58
+ },
59
+ tooltip: {
60
+ callbacks: {
61
+ title: function(tooltipItems) {
62
+ return `${tooltipItems[0].label}`;
63
+ },
64
+ label: (tooltipItem) => {
65
+ const total = tooltipItem.dataset.data.reduce((a, b) => a + b, 0)
66
+ const percentage = ((tooltipItem.raw / total) * 100).toFixed(1)
67
+
68
+ return `${tooltipItem.dataset.label}: ${tooltipItem.raw} (${percentage}%)`;
69
+ }
70
+ },
71
+ },
72
+ },
73
+ scales: {
74
+ r: {
75
+ display: false
76
+ }
77
+ },
78
+ onClick: this.onClick
79
+ }
80
+ },
81
+
82
+ },
83
+
84
+ data(){
85
+ return {
86
+ backgroundColors: [
87
+ '#5D9CEC',
88
+ '#A0D468',
89
+ '#FFCE54',
90
+ '#FC6E51',
91
+ '#48CFAD',
92
+ '#AC92EC',
93
+ '#4FC1E9',
94
+ '#FFCE54',
95
+ '#ED5565',
96
+ '#EC87C0'
97
+ ],
98
+ }
99
+ },
100
+
101
+ inject: [ 'selectPreset' ],
102
+
103
+ methods: {
104
+
105
+ onClick(e, segments){
106
+
107
+ const clickInteractions = (this.interactions ?? []).filter(_ => _.event === 'click')
108
+ const segment = segments[0]
109
+ if(!segment) return
110
+
111
+ const dataset = this.value.datasets[segment.datasetIndex]
112
+ const obj = {
113
+ segment: this.value.labels[segment.index],
114
+ key: dataset.label,
115
+ value: dataset.data[segment.index]
116
+ }
117
+
118
+ for(let click of clickInteractions){
119
+ const { action, presetUid, filters } = click
120
+
121
+ const params = filters.reduce((res, cur) => {
122
+ res[cur.datasourceUid + '.filters.' + cur.key + '.' + cur.operator] = strVars(cur.value, obj)
123
+ return res
124
+ }, {})
125
+
126
+ switch(action){
127
+
128
+ case 'openDashboardPreset':
129
+ if(typeof this.selectPreset === 'function')
130
+ this.selectPreset(presetUid, params)
131
+ break
132
+ }
133
+ }
134
+
135
+ }
136
+
137
+ },
138
+
139
+ mixins: [ readyStateMixin ],
140
+
141
+ props: {
142
+
143
+ label: String,
144
+
145
+ value: Object,
146
+
147
+ column: String,
148
+
149
+ datasourceUid: String,
150
+
151
+ interactions: Array,
152
+
153
+ uid: String,
154
+
155
+ }
156
+
157
+ }
158
+
159
+ </script>