fluency-v8-components 1.3.5 → 1.3.6

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 (178) hide show
  1. package/dist/fluency-v8-components.es.js +1 -1
  2. package/dist/fluency-v8-components.umd.js +99 -99
  3. package/dist/{index-q2NbjdVo.mjs → index-BBxccHNP.mjs} +7 -6
  4. package/dist/{index.es-PAPL4E6Y.mjs → index.es-D_XhLSeH.mjs} +1 -1
  5. package/package.json +3 -2
  6. package/src/assets/images/ai.svg +1 -0
  7. package/src/assets/images/github-dark.svg +1 -0
  8. package/src/assets/images/github.svg +1 -0
  9. package/src/assets/images/high-priority.svg +1 -0
  10. package/src/assets/images/power-off.svg +1 -0
  11. package/src/assets/images/save.svg +1 -0
  12. package/src/assets/index.ts +15 -0
  13. package/src/assets/main.css +505 -0
  14. package/src/assets/prism-theme.css +290 -0
  15. package/src/components/buttons/ActionButtons.vue +374 -0
  16. package/src/components/buttons/DropdownButton.vue +104 -0
  17. package/src/components/buttons/IconButton.vue +63 -0
  18. package/src/components/buttons/ImageButton.vue +16 -0
  19. package/src/components/buttons/MenuButton.vue +138 -0
  20. package/src/components/buttons/SubmitButtons.vue +51 -0
  21. package/src/components/buttons/TextButton.vue +40 -0
  22. package/src/components/charts/AlertChart.vue +376 -0
  23. package/src/components/charts/BarChart.vue +212 -0
  24. package/src/components/charts/BarChartHorizontal.vue +243 -0
  25. package/src/components/charts/CronChart.vue +146 -0
  26. package/src/components/charts/EmptyChart.vue +76 -0
  27. package/src/components/charts/GradientChart.vue +310 -0
  28. package/src/components/charts/LineChart.test.js +59 -0
  29. package/src/components/charts/LineChart.vue +434 -0
  30. package/src/components/charts/PieChart.vue +293 -0
  31. package/src/components/charts/ProgressChart.vue +106 -0
  32. package/src/components/charts/StackedChart.vue +364 -0
  33. package/src/components/charts/StackedChartClustered.vue +395 -0
  34. package/src/components/charts/TimelineChart.vue +215 -0
  35. package/src/components/charts/WorkflowChart.vue +520 -0
  36. package/src/components/common/AutoCompleteSearchBar.vue +100 -0
  37. package/src/components/common/AutoRefreshButton.vue +53 -0
  38. package/src/components/common/Breadcrumb.vue +45 -0
  39. package/src/components/common/ButtonToggle.vue +24 -0
  40. package/src/components/common/Card.vue +116 -0
  41. package/src/components/common/Carousel.vue +66 -0
  42. package/src/components/common/CategoryCard.vue +28 -0
  43. package/src/components/common/CodeEditor.vue +59 -0
  44. package/src/components/common/DatePicker.vue +21 -0
  45. package/src/components/common/DatePickerInput.vue +109 -0
  46. package/src/components/common/Dialog.vue +103 -0
  47. package/src/components/common/EditorHeading.vue +10 -0
  48. package/src/components/common/EventList.vue +41 -0
  49. package/src/components/common/Facet.vue +206 -0
  50. package/src/components/common/Feed.vue +58 -0
  51. package/src/components/common/Flag.vue +27 -0
  52. package/src/components/common/HomeCard.vue +20 -0
  53. package/src/components/common/ItemBox.vue +49 -0
  54. package/src/components/common/Loading.vue +19 -0
  55. package/src/components/common/LoadingDots.vue +12 -0
  56. package/src/components/common/PageHeading.vue +30 -0
  57. package/src/components/common/Pagination.vue +105 -0
  58. package/src/components/common/Popover.vue +24 -0
  59. package/src/components/common/PowerToggle.vue +130 -0
  60. package/src/components/common/ProgressBar.vue +33 -0
  61. package/src/components/common/RadioButtons.vue +52 -0
  62. package/src/components/common/Schedule.vue +79 -0
  63. package/src/components/common/SearchBar.vue +30 -0
  64. package/src/components/common/Separator.vue +3 -0
  65. package/src/components/common/Slideout.vue +95 -0
  66. package/src/components/common/Sort.vue +83 -0
  67. package/src/components/common/Table.vue +48 -0
  68. package/src/components/common/Tabs.vue +129 -0
  69. package/src/components/common/Tag.vue +53 -0
  70. package/src/components/common/Tooltip.vue +49 -0
  71. package/src/components/common/VerticalTabs.vue +34 -0
  72. package/src/components/common/card/CardItem.vue +27 -0
  73. package/src/components/common/card/CardItemGroup.vue +45 -0
  74. package/src/components/common/facet/Leaf.vue +97 -0
  75. package/src/components/common/facet/TriState.vue +37 -0
  76. package/src/components/common/table/TableData.vue +48 -0
  77. package/src/components/common/table/TableHeader.vue +21 -0
  78. package/src/components/dialogs/ChooseValueDialog.vue +97 -0
  79. package/src/components/dialogs/ConfirmDialog.vue +73 -0
  80. package/src/components/dialogs/CopyDialog.vue +51 -0
  81. package/src/components/dialogs/DownloadDialog.vue +48 -0
  82. package/src/components/dialogs/NameDescDialog.vue +74 -0
  83. package/src/components/dialogs/NameDialog.vue +56 -0
  84. package/src/components/dialogs/PopupEditor.vue +113 -0
  85. package/src/components/dialogs/ProgressDialog.vue +58 -0
  86. package/src/components/dialogs/ResetPasswordDialog.vue +58 -0
  87. package/src/components/dialogs/Wizard.vue +99 -0
  88. package/src/components/dialogs/wizard/Stepper.vue +31 -0
  89. package/src/components/form/CheckBox.vue +26 -0
  90. package/src/components/form/Editor.vue +93 -0
  91. package/src/components/form/FormCol.vue +19 -0
  92. package/src/components/form/FormRow.vue +19 -0
  93. package/src/components/form/FormSection.vue +21 -0
  94. package/src/components/form/GreyForm.vue +7 -0
  95. package/src/components/form/GreyInput.vue +51 -0
  96. package/src/components/form/GreyInputAutocomplete.vue +100 -0
  97. package/src/components/form/GreyInputCopy.vue +66 -0
  98. package/src/components/form/GreyInputGrow.vue +42 -0
  99. package/src/components/form/GreyInputToken.vue +78 -0
  100. package/src/components/form/GreyPassword.vue +36 -0
  101. package/src/components/form/GreySelect.vue +154 -0
  102. package/src/components/form/GreySelectInput.vue +123 -0
  103. package/src/components/form/GreySelectInputMultiple.vue +218 -0
  104. package/src/components/form/GreyTel.vue +58 -0
  105. package/src/components/form/HamburgerItem.vue +95 -0
  106. package/src/components/form/KeyValueEntry.vue +74 -0
  107. package/src/components/form/RadioInput.vue +38 -0
  108. package/src/components/form/UploadFile.vue +99 -0
  109. package/src/components/icons/AiIcon.vue +6 -0
  110. package/src/components/icons/GithubIcon.vue +18 -0
  111. package/src/components/icons/HighPriorityIcon.vue +6 -0
  112. package/src/components/icons/PowerOffIcon.vue +6 -0
  113. package/src/components/icons/SaveIcon.vue +6 -0
  114. package/src/components/index.js +134 -0
  115. package/src/components/menu/DialogMenu.vue +142 -0
  116. package/src/components/menu/GrandChild.vue +39 -0
  117. package/src/components/menu/GridMenu.vue +88 -0
  118. package/src/components/menu/MenuAvatar.vue +66 -0
  119. package/src/components/menu/MenuDesktop.vue +90 -0
  120. package/src/components/notifications/Notify.vue +123 -0
  121. package/src/components/notifications/NotifyList.vue +130 -0
  122. package/src/components/page-structure/FacetPage.vue +77 -0
  123. package/src/components/query/Child.vue +63 -0
  124. package/src/components/query/LVDBQuery.vue +38 -0
  125. package/src/components/status/Active.vue +44 -0
  126. package/src/components/status/ScoreLevel.vue +43 -0
  127. package/src/components/status/Status.vue +51 -0
  128. package/src/components/status/TaskDot.vue +25 -0
  129. package/src/components/status/TaskStatus.vue +26 -0
  130. package/src/components/status/TicketStatus.vue +201 -0
  131. package/src/components/status/Trend.vue +20 -0
  132. package/src/components/tables/ArgumentRunTable.vue +96 -0
  133. package/src/components/tables/ArgumentTable.vue +67 -0
  134. package/src/components/tables/CloudFormationParameters.vue +25 -0
  135. package/src/constants/colors.js +248 -0
  136. package/src/constants/font-map.js +128 -0
  137. package/src/constants/fpl2.js +162 -0
  138. package/src/constants/icon-svg.js +405 -0
  139. package/src/constants/schedule.js +52 -0
  140. package/src/fpl/AddPanel.vue +237 -0
  141. package/src/fpl/Configs/Alert.vue +16 -0
  142. package/src/fpl/Configs/AlertSprite.vue +2 -0
  143. package/src/fpl/Configs/Chart.vue +63 -0
  144. package/src/fpl/Configs/Config.js +154 -0
  145. package/src/fpl/Configs/Counter.vue +35 -0
  146. package/src/fpl/Configs/Histogram.vue +70 -0
  147. package/src/fpl/Configs/IPMap.vue +37 -0
  148. package/src/fpl/Configs/Image.vue +163 -0
  149. package/src/fpl/Configs/MetricChart.vue +20 -0
  150. package/src/fpl/Configs/PieChart.vue +37 -0
  151. package/src/fpl/Configs/SparkChart.vue +41 -0
  152. package/src/fpl/Configs/StackedBarChart.vue +49 -0
  153. package/src/fpl/Configs/Table.vue +211 -0
  154. package/src/fpl/Configs/Text.vue +14 -0
  155. package/src/fpl/Configs/TopNChart.vue +37 -0
  156. package/src/fpl/Outputs/FPLAlert.vue +64 -0
  157. package/src/fpl/Outputs/FPLStream.vue +41 -0
  158. package/src/fpl/Outputs/FPLTable.vue +77 -0
  159. package/src/fpl/Panel.vue +202 -0
  160. package/src/fpl/Panels/Alert.vue +85 -0
  161. package/src/fpl/Panels/AlertSprite.vue +9 -0
  162. package/src/fpl/Panels/Chart.vue +98 -0
  163. package/src/fpl/Panels/Counter.vue +43 -0
  164. package/src/fpl/Panels/Histogram.vue +138 -0
  165. package/src/fpl/Panels/IPMap.vue +48 -0
  166. package/src/fpl/Panels/Image.vue +35 -0
  167. package/src/fpl/Panels/MetricChart.vue +97 -0
  168. package/src/fpl/Panels/PieChart.vue +54 -0
  169. package/src/fpl/Panels/SparkChart.vue +166 -0
  170. package/src/fpl/Panels/StackedBarChart.vue +74 -0
  171. package/src/fpl/Panels/Table.vue +103 -0
  172. package/src/fpl/Panels/Text.vue +24 -0
  173. package/src/fpl/Panels/TopNChart.vue +69 -0
  174. package/src/fpl/index.js +39 -0
  175. package/src/utils/download.js +220 -0
  176. package/src/utils/formatOutput.js +156 -0
  177. package/src/utils/random.js +32 -0
  178. package/src/utils/timeUtils.js +138 -0
@@ -0,0 +1,376 @@
1
+ <template>
2
+ <div :id="id" class="float-left">
3
+ <div :id="id + 'tooltip'" role="tooltip" class="tooltip"></div>
4
+ </div>
5
+ <div class="overflow-auto" :style="`height: ${height}px; overflow: auto`">
6
+ <div :id="id + 'legend'"></div>
7
+ </div>
8
+ </template>
9
+ <script>
10
+ import * as d3 from "d3";
11
+ import { alertChartColors, chartColors } from "@/constants/colors";
12
+ import { humanCount, dataCount } from "@/utils/formatOutput";
13
+
14
+ export default {
15
+ props: {
16
+ id: {
17
+ type: String,
18
+ required: true,
19
+ },
20
+ data: {
21
+ type: Object,
22
+ required: true,
23
+ },
24
+ unit: {
25
+ type: String,
26
+ default: "Count",
27
+ },
28
+ width: {
29
+ type: Number,
30
+ default: 350,
31
+ },
32
+ height: {
33
+ type: Number,
34
+ default: 200,
35
+ },
36
+ pannable: {
37
+ type: Boolean,
38
+ default: true,
39
+ },
40
+ theme: {
41
+ type: String,
42
+ default: "light",
43
+ },
44
+ },
45
+ data() {
46
+ return {
47
+ svg: null,
48
+ };
49
+ },
50
+ mounted() {
51
+ this.initializeChart();
52
+ this.createChart(this.data);
53
+ },
54
+ methods: {
55
+ initializeChart() {
56
+ this.svg = d3
57
+ .select("#" + this.id)
58
+ .append("svg")
59
+ .attr("width", this.width)
60
+ .attr("height", this.height);
61
+ },
62
+ createChart(rawData) {
63
+ let data = [];
64
+ rawData.series.forEach((d, i) => {
65
+ data.push({
66
+ ...d,
67
+ index: i,
68
+ });
69
+ });
70
+ // Declare the chart dimensions and margins.
71
+ const width = this.width;
72
+ const height = this.height;
73
+ const marginTop = 20;
74
+ const marginRight = 15;
75
+ const marginBottom = 30;
76
+ const marginLeft = 50;
77
+
78
+ // get the longest slots array and largest value
79
+ const hidden = [];
80
+
81
+ // Declare the tooltip mouseover functions
82
+ const mouseover = (event, d) => {
83
+ const slot = new Date(d.slots).toUTCString();
84
+ const value =
85
+ this.unit === "Bytes (B)"
86
+ ? dataCount(d.values) + "B"
87
+ : this.unit === "Percent (%)"
88
+ ? d.values.toFixed(2) + "%"
89
+ : humanCount(d.values);
90
+ const text = d.action
91
+ ? `${d.action}<br>Time: ${slot}<br>Value: ${value}`
92
+ : `Alert<br>Time: ${slot}<br>Value: ${value}`;
93
+ event.target.r.baseVal.value = 5;
94
+ d3.select("#" + this.id + "tooltip")
95
+ .html(text)
96
+ .style("opacity", 1)
97
+ .style("left", event.layerX + "px")
98
+ .style("top", event.layerY + "px");
99
+ };
100
+ const mouseout = (event, d) => {
101
+ event.target.r.baseVal.value = 3;
102
+ d3.select("#" + this.id + "tooltip")
103
+ .style("opacity", 0)
104
+ .style("left", "0px")
105
+ .style("top", "0px");
106
+ };
107
+
108
+ const drawAxis = () => {
109
+ const dat = data.filter((d) => !hidden.includes(d.index));
110
+ const axisVals = this.getAxisLargest(dat);
111
+ // Declare the x (horizontal position) scale.
112
+ const x = d3.scaleUtc(d3.extent(axisVals[0]), [
113
+ marginLeft,
114
+ width - marginRight,
115
+ ]);
116
+
117
+ // Declare the y (vertical position) scale.
118
+ const y = d3.scaleLinear(
119
+ [0, axisVals[1]],
120
+ [height - marginBottom, marginTop]
121
+ );
122
+
123
+ // Add the x-axis.
124
+ const xAxis = this.svg
125
+ .append("g")
126
+ .attr("class", this.id + "xaxis")
127
+ .attr("transform", `translate(0,${height - marginBottom})`)
128
+ .call(
129
+ d3
130
+ .axisBottom(x)
131
+ .ticks(width / 80)
132
+ .tickSizeOuter(0)
133
+ );
134
+
135
+ // Add the y-axis, remove the domain line, add grid lines and a label.
136
+ const yAxis = this.svg
137
+ .append("g")
138
+ .attr("class", this.id + "yaxis")
139
+ .attr("transform", `translate(${marginLeft},0)`)
140
+ .call(
141
+ d3
142
+ .axisLeft(y)
143
+ .ticks(height / 40)
144
+ .tickFormat((d) => {
145
+ return this.unit === "Bytes (B)" ? dataCount(d) : humanCount(d);
146
+ })
147
+ )
148
+ .call((g) => g.select(".domain").remove())
149
+ .call((g) =>
150
+ g
151
+ .selectAll(".tick line")
152
+ .clone()
153
+ .attr("x2", width - marginLeft - marginRight)
154
+ .attr("stroke-opacity", 0.1)
155
+ )
156
+ .call((g) =>
157
+ g
158
+ .append("text")
159
+ .attr("x", -marginLeft)
160
+ .attr("y", 10)
161
+ .attr("fill", "currentColor")
162
+ .attr("text-anchor", "start")
163
+ .text(this.unit)
164
+ );
165
+
166
+ // add brush to chart
167
+ if (this.pannable) {
168
+ let idleTimeout;
169
+ function idled() {
170
+ idleTimeout = null;
171
+ }
172
+
173
+ const updateChart = (event, d) => {
174
+ const extent = event.selection;
175
+ if (!extent) {
176
+ if (!idleTimeout) return (idleTimeout = setTimeout(idled, 500));
177
+ x.domain(d3.extent(rawData.slots));
178
+ } else {
179
+ x.domain([x.invert(extent[0]), x.invert(extent[1])]);
180
+ this.svg.select("." + this.id + "brush").call(brush.move, null);
181
+ }
182
+ xAxis.transition().duration(1000).call(d3.axisBottom(x));
183
+ this.svg.selectAll("." + this.id + "line").attr("d", function (d) {
184
+ return line(
185
+ d.values.map((val, i) => {
186
+ return { slots: rawData.slots[i], values: val };
187
+ })
188
+ );
189
+ });
190
+ this.svg
191
+ .selectAll("." + this.id + "points")
192
+ .attr("cx", (d) => x(d.slots));
193
+ };
194
+ const brush = d3
195
+ .brushX()
196
+ .extent([
197
+ [0, 0],
198
+ [width, height],
199
+ ])
200
+ .on("end", updateChart);
201
+ this.svg
202
+ .append("g")
203
+ .attr("class", (d) => this.id + "brush")
204
+ .call(brush);
205
+
206
+ this.svg.on("dblclick", function () {
207
+ x.domain(
208
+ d3.extent(axisVals[0], function (d) {
209
+ return d;
210
+ })
211
+ );
212
+ xAxis.transition().call(d3.axisBottom(x));
213
+ this.svg.selectAll("." + this.id + "line").attr("d", function (d) {
214
+ return line(
215
+ d.values.map((val, i) => {
216
+ return { slots: rawData.slots[i], values: val };
217
+ })
218
+ );
219
+ });
220
+ this.svg
221
+ .selectAll("." + this.id + "points")
222
+ .attr("cx", (d) => x(d.slots));
223
+ });
224
+ }
225
+
226
+ // Declare the line generator.
227
+ const line = d3
228
+ .line()
229
+ .x((d, i) => {
230
+ return x(d.slots);
231
+ })
232
+ .y((d, i) => {
233
+ return y(d.values);
234
+ });
235
+
236
+ this.svg
237
+ .selectAll(".line")
238
+ .data(dat)
239
+ .enter()
240
+ .append("path")
241
+ .attr("class", (d) => this.id + d.index + "line " + this.id + "line")
242
+ .attr("fill", "none")
243
+ .attr("z-index", 1)
244
+ .style(
245
+ "stroke",
246
+ (d) =>
247
+ alertChartColors[this.theme][d.action] ||
248
+ chartColors[d.index % chartColors.length]
249
+ )
250
+ .style("stroke-dasharray", "3, 3")
251
+ .attr("stroke-width", 1)
252
+ .attr("d", function (d) {
253
+ return line(
254
+ d.values.map((val, i) => {
255
+ return { slots: rawData.slots[i], values: val };
256
+ })
257
+ );
258
+ });
259
+ this.svg
260
+ .selectAll(".line")
261
+ .data([rawData])
262
+ .enter()
263
+ .append("path")
264
+ .attr("class", this.id + "line")
265
+ .attr("fill", "none")
266
+ .attr("z-index", 1)
267
+ .style("stroke", alertChartColors[this.theme]["Alert"])
268
+ .attr("stroke-width", 1.5)
269
+ .attr("d", function (d) {
270
+ return line(
271
+ d.slots.map((slot, i) => {
272
+ return { slots: slot, values: d.values[i] };
273
+ })
274
+ );
275
+ });
276
+
277
+ // add alert to chart
278
+ const alertData = rawData.slots.map((slot, i) => {
279
+ return {
280
+ slots: slot,
281
+ values: rawData.values[i],
282
+ isAlert: rawData.metric.bools[i],
283
+ };
284
+ });
285
+ this.svg
286
+ .selectAll(".point")
287
+ .data(alertData)
288
+ .enter()
289
+ .append("circle")
290
+ .attr("class", (d, i) => this.id + i + "points " + this.id + "points")
291
+ .attr("fill", chartColors[3])
292
+ .attr("display", (d) => (d.isAlert ? "" : "none"))
293
+ .attr("r", 3)
294
+ .attr("cx", (d) => x(d.slots))
295
+ .attr("cy", (d) => y(d.values))
296
+ .on("mouseover", mouseover)
297
+ .on("mouseout", mouseout);
298
+ };
299
+
300
+ drawAxis();
301
+ // Append a path for the line chart for each series
302
+ if (!rawData.series) {
303
+ this.svg
304
+ .append("text")
305
+ .attr("x", width / 2)
306
+ .attr("y", height / 2)
307
+ .attr("text-anchor", "middle")
308
+ .attr("fill", "currentColor")
309
+ .text("No data available");
310
+ }
311
+
312
+ if (rawData.series.length > 0) {
313
+ // Add a legend
314
+ this.legend = d3
315
+ .select("#" + this.id + "legend")
316
+ .append("svg")
317
+ .attr("width", this.width > 600 ? 200 : 75)
318
+ .attr("height", Math.max(25 * rawData.series.length, height - 20));
319
+
320
+ // Add one dot in the legend for each name.
321
+ this.legend
322
+ .selectAll("legendDots")
323
+ .data([...data, { action: "Alert", index: data.length }])
324
+ .enter()
325
+ .append("circle")
326
+ .attr("id", (d) => this.id + d.index + "dots")
327
+ .attr("class", "show")
328
+ .attr("cx", 10)
329
+ .attr("cy", (d, i) => height / (data.length + 2) + i * 25)
330
+ .attr("r", 5)
331
+ .style(
332
+ "fill",
333
+ (d) =>
334
+ alertChartColors[this.theme][d.action] ||
335
+ chartColors[d.index % chartColors.length]
336
+ );
337
+
338
+ // Add one dot in the legend for each name.
339
+ this.legend
340
+ .selectAll("legendLabels")
341
+ .data([...data, { action: "Alert", index: data.length }])
342
+ .enter()
343
+ .append("text")
344
+ .attr("class", (d) => this.id + d.index + "labels")
345
+ .attr("x", 20)
346
+ .attr("y", (d, i) => height / (data.length + 2) + i * 25)
347
+ .style(
348
+ "fill",
349
+ (d) =>
350
+ alertChartColors[this.theme][d.action] ||
351
+ chartColors[d.index % chartColors.length]
352
+ )
353
+ .text((d) =>
354
+ d.action === "Alert" ? rawData.action : d.action || "(no name)"
355
+ )
356
+ .attr("font-weight", 500)
357
+ .attr("text-anchor", "left")
358
+ .attr("font-size", "11px")
359
+ .style("alignment-baseline", "middle");
360
+ }
361
+ },
362
+
363
+ getAxisLargest(data) {
364
+ let longestSlots = this.data.slots;
365
+ let largestValue = Math.max(...this.data.values);
366
+ data.forEach((d, i) => {
367
+ const max = Math.max(...d.values);
368
+ if (max > largestValue) {
369
+ largestValue = max;
370
+ }
371
+ });
372
+ return [longestSlots, largestValue];
373
+ },
374
+ },
375
+ };
376
+ </script>
@@ -0,0 +1,212 @@
1
+ <template>
2
+ <div :id="id">
3
+ <div :id="id + 'tooltip'" role="tooltip" class="tooltip"></div>
4
+ </div>
5
+ </template>
6
+ <script>
7
+ import * as d3 from "d3";
8
+ import { chartColors } from "@/constants/colors";
9
+ import { humanCount, dataCount, costCount } from "@/utils/formatOutput";
10
+
11
+ export default {
12
+ props: {
13
+ id: {
14
+ type: String,
15
+ required: true,
16
+ },
17
+ data: {
18
+ type: Object,
19
+ required: true,
20
+ },
21
+ unit: {
22
+ type: String,
23
+ default: "Cost ($)",
24
+ },
25
+ width: {
26
+ type: Number,
27
+ default: 800,
28
+ },
29
+ height: {
30
+ type: Number,
31
+ default: 400,
32
+ },
33
+ title: {
34
+ type: String,
35
+ default: "",
36
+ },
37
+ valueName: {
38
+ type: String,
39
+ default: "Value",
40
+ },
41
+ theme: {
42
+ type: String,
43
+ default: "light",
44
+ },
45
+ },
46
+ data() {
47
+ return {
48
+ svg: null,
49
+ };
50
+ },
51
+ mounted() {
52
+ this.initializeChart();
53
+ this.createChart(this.data);
54
+ },
55
+ methods: {
56
+ initializeChart() {
57
+ this.svg = d3
58
+ .select("#" + this.id)
59
+ .append("svg")
60
+ .attr("width", this.width)
61
+ .attr("height", this.title ? this.height + 40 : this.height);
62
+ },
63
+ createChart(data) {
64
+ // Declare the chart dimensions and margins.
65
+ const width = this.width;
66
+ const height = this.title ? this.height + 30 : this.height;
67
+ const marginTop = 20;
68
+ const marginRight = 15;
69
+ const marginBottom = 30;
70
+ const marginLeft = 50;
71
+
72
+ // get the largest value
73
+ let largestValue = this.unit === "Percent (%)" ? 100 : 0;
74
+ data.values.forEach((val) => {
75
+ if (val > largestValue) {
76
+ largestValue = val;
77
+ }
78
+ });
79
+
80
+ // Declare the x (horizontal position) scale.
81
+ const x = d3.scaleUtc(d3.extent(data.slots), [
82
+ marginLeft,
83
+ width - marginRight,
84
+ ]);
85
+
86
+ // Declare the y (vertical position) scale.
87
+ const yScale = this.title
88
+ ? [height - marginBottom, marginTop + 30]
89
+ : [height - marginBottom, marginTop];
90
+ const y = d3.scaleLinear([0, largestValue], yScale);
91
+
92
+ // Declare the tooltip mouseover functions
93
+ const mouseover = (event, d) => {
94
+ const slot = new Date(d.slots).toUTCString();
95
+ const value =
96
+ this.unit === "Bytes (B)" || this.unit === "B"
97
+ ? dataCount(d.values) + "B"
98
+ : this.unit === "Percent (%)"
99
+ ? d.values.toFixed(2) + "%"
100
+ : this.unit === "Cost ($)"
101
+ ? costCount(d.values)
102
+ : humanCount(d.values);
103
+ const tooltip = d3
104
+ .select("#" + this.id + "tooltip")
105
+ .html(`${this.data.name}<br>${slot}<br>${this.valueName}: ${value}`)
106
+ .style("opacity", 1)
107
+ .style("top", event.layerY + "px");
108
+ if (event.layerX > (width * 3) / 4) {
109
+ const tooltipWidth = tooltip.node().getBoundingClientRect().width;
110
+ tooltip.style("left", event.layerX - tooltipWidth + "px");
111
+ } else {
112
+ tooltip.style("left", event.layerX + "px");
113
+ }
114
+ };
115
+ const mouseout = (event, d) => {
116
+ d3.select("#" + this.id + "tooltip")
117
+ .style("opacity", 0)
118
+ .style("left", "0px")
119
+ .style("top", "0px");
120
+ };
121
+
122
+ // Add the x-axis.
123
+ this.svg
124
+ .append("g")
125
+ .attr("transform", `translate(0,${height - marginBottom})`)
126
+ .call(
127
+ d3
128
+ .axisBottom(x)
129
+ .ticks(width / 80)
130
+ .tickSizeOuter(0)
131
+ );
132
+
133
+ // Add the y-axis, remove the domain line, add grid lines and a label.
134
+ this.svg
135
+ .append("g")
136
+ .attr("transform", `translate(${marginLeft},0)`)
137
+ .call(
138
+ d3
139
+ .axisLeft(y)
140
+ .ticks(height / 40)
141
+ .tickFormat((d) => {
142
+ return this.unit === "Bytes (B)" || this.unit === "B"
143
+ ? dataCount(d)
144
+ : this.unit === "Cost ($)"
145
+ ? costCount(d)
146
+ : humanCount(d);
147
+ })
148
+ )
149
+ .call((g) => g.select(".domain").remove())
150
+ .call((g) =>
151
+ g
152
+ .selectAll(".tick line")
153
+ .clone()
154
+ .attr("x2", width - marginLeft - marginRight)
155
+ .attr("stroke-opacity", 0.1)
156
+ )
157
+ .call((g) =>
158
+ g
159
+ .append("text")
160
+ .attr("x", -marginLeft)
161
+ .attr("y", this.title ? 40 : 10)
162
+ .attr("fill", "currentColor")
163
+ .attr("text-anchor", "start")
164
+ .text(this.unit)
165
+ )
166
+ .call((g) =>
167
+ g
168
+ .append("text")
169
+ .attr("x", -marginLeft)
170
+ .attr("y", 20)
171
+ .attr("fill", "currentColor")
172
+ .attr("text-anchor", "start")
173
+ .attr("font-weight", "bold")
174
+ .attr("font-size", "2em")
175
+ .text(this.title)
176
+ );
177
+
178
+ // Append a bar chart for each data point
179
+ if (data.slots.length > 0) {
180
+ const seriesData = data.slots.map((slot, i) => {
181
+ return {
182
+ slots: slot,
183
+ values: data.values[i],
184
+ };
185
+ });
186
+
187
+ this.svg
188
+ .selectAll(".rect")
189
+ .data(seriesData)
190
+ .enter()
191
+ .append("rect")
192
+ .attr("class", (d) => this.id + "bar")
193
+ .attr("z-index", 1)
194
+ .attr("x", (d) => x(d.slots) - 2)
195
+ .attr("y", (d) => y(d.values))
196
+ .attr("width", 10)
197
+ .attr("height", (d) => height - marginBottom - y(d.values))
198
+ .attr("fill", chartColors[0])
199
+ .on("mouseover", mouseover)
200
+ .on("mouseout", mouseout);
201
+ } else {
202
+ this.svg
203
+ .append("text")
204
+ .attr("x", width / 2)
205
+ .attr("y", height / 2)
206
+ .attr("text-anchor", "middle")
207
+ .text("No data available");
208
+ }
209
+ },
210
+ },
211
+ };
212
+ </script>