fluency-v8-components 1.3.5 → 1.3.7

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-ChEFiXF5.mjs} +12 -11
  4. package/dist/{index.es-PAPL4E6Y.mjs → index.es-CjjN70eV.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 +495 -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,395 @@
1
+ <template>
2
+ <div :id="id">
3
+ <div :id="id + 'tooltip'" role="tooltip" class="tooltip"></div>
4
+ </div>
5
+ <div class="overflow-auto" :style="`width: ${width}px; overflow: auto`">
6
+ <div :id="id + 'legend'"></div>
7
+ </div>
8
+ </template>
9
+ <script>
10
+ import * as d3 from "d3";
11
+ import { platformMetricsLabels, chartColors } from "@/constants/colors";
12
+ import { humanCount, dataCount, costCount } from "@/utils/formatOutput";
13
+ import { adjustText } from "@/constants/font-map";
14
+
15
+ export default {
16
+ props: {
17
+ id: {
18
+ type: String,
19
+ required: true,
20
+ },
21
+ data: {
22
+ type: Object,
23
+ required: true,
24
+ },
25
+ names: {
26
+ type: Object,
27
+ default: {},
28
+ },
29
+ unit: {
30
+ type: String,
31
+ default: "Cost ($)",
32
+ },
33
+ width: {
34
+ type: Number,
35
+ default: 575,
36
+ },
37
+ height: {
38
+ type: Number,
39
+ default: 350,
40
+ },
41
+ isTime: {
42
+ type: Boolean,
43
+ default: true,
44
+ },
45
+ tooltipOffset: {
46
+ type: String,
47
+ default: "layer",
48
+ },
49
+ slotName: {
50
+ type: String,
51
+ default: "Field",
52
+ },
53
+ valueName: {
54
+ type: String,
55
+ default: "Value",
56
+ },
57
+ theme: {
58
+ type: String,
59
+ default: "light",
60
+ },
61
+ },
62
+ data() {
63
+ return {
64
+ svg: null,
65
+ legend: null,
66
+ };
67
+ },
68
+ mounted() {
69
+ this.initializeChart();
70
+ this.createChart(this.data);
71
+ },
72
+ methods: {
73
+ initializeChart() {
74
+ this.svg = d3
75
+ .select("#" + this.id)
76
+ .append("svg")
77
+ .attr("width", this.width)
78
+ .attr("height", this.height);
79
+ },
80
+ createChart(data) {
81
+ // Declare the chart dimensions and margins.
82
+ const width = this.width;
83
+ const height = this.height;
84
+ const marginTop = 20;
85
+ const marginRight = 15;
86
+ const marginBottom = 30;
87
+ const marginLeft = 50;
88
+ // initialize the actions and instances
89
+ const actions = {};
90
+ const instances = {};
91
+ data.forEach((d) => {
92
+ actions[d.action] = d.action;
93
+ instances[d.instance] = d.instance;
94
+ });
95
+ const hidden = [];
96
+ const namesIndex = Object.keys(actions);
97
+ const instancesIndex = Object.keys(instances);
98
+ // get the series data
99
+ const seriesData = [];
100
+ data.forEach((d) => {
101
+ d.slots.forEach((s, i) => {
102
+ seriesData.push({
103
+ slot: s,
104
+ action: d.action,
105
+ instance: d.instance,
106
+ value: d.values[i],
107
+ });
108
+ });
109
+ });
110
+
111
+ // Declare the tooltip mouseover functions
112
+ const mouseover = (event, d) => {
113
+ const slot = this.isTime
114
+ ? new Date(d.data[0]).toUTCString()
115
+ : d.data[0];
116
+ const val = d[1] - d[0];
117
+ const action = d.key.split(":")[0];
118
+ const instance = this.names[d.key.split(":")[1]] || d.key.split(":")[1];
119
+ const value =
120
+ this.unit === "Bytes (B)"
121
+ ? dataCount(val) + "B"
122
+ : this.unit === "Percent (%)"
123
+ ? val.toFixed(2) + "%"
124
+ : this.unit === "Cost ($)"
125
+ ? "$" + val.toFixed(2)
126
+ : humanCount(val);
127
+ event.target.style.opacity = 0.7;
128
+ d3.select("#" + this.id + "tooltip")
129
+ .html(
130
+ `${action}<br>Instance: ${instance}<br>${
131
+ this.isTime ? "Time" : this.slotName
132
+ }: ${slot}<br>${this.valueName}: ${value}`
133
+ )
134
+ .style("opacity", 1)
135
+ .style("left", event[this.tooltipOffset + "X"] + 10 + "px")
136
+ .style("top", event[this.tooltipOffset + "Y"] + "px");
137
+ };
138
+ const mouseout = (event, d) => {
139
+ event.target.style.opacity = 1;
140
+ d3.select("#" + this.id + "tooltip")
141
+ .style("opacity", 0)
142
+ .style("left", "0px")
143
+ .style("top", "0px");
144
+ };
145
+ // Declare the legend mouseover functions
146
+ const legendMouseover = (event, d) => {
147
+ const action = namesIndex.indexOf(d);
148
+ d3.selectAll("." + this.id + "bar").style("opacity", 0.7);
149
+ d3.selectAll("." + this.id + action + "bar").style("opacity", 1);
150
+ d3.selectAll("#" + this.id + action + "dots").attr("r", 6);
151
+ d3.selectAll("." + this.id + action + "labels").attr(
152
+ "font-weight",
153
+ 1000
154
+ );
155
+ };
156
+ const legendMouseout = (event, d) => {
157
+ const action = namesIndex.indexOf(d);
158
+ d3.selectAll("." + this.id + "bar").style("opacity", 1);
159
+ d3.selectAll("#" + this.id + action + "dots").attr("r", 5);
160
+ d3.selectAll("." + this.id + action + "labels").attr(
161
+ "font-weight",
162
+ 500
163
+ );
164
+ };
165
+ const legendClick = (event, d) => {
166
+ const action = namesIndex.indexOf(d);
167
+ // redraw the axis and the series
168
+ d3.select("." + this.id + "xaxis").remove();
169
+ d3.select("." + this.id + "yaxis").remove();
170
+ d3.selectAll("#" + this.id + " rect").remove();
171
+ if (event.target.classList.contains("show")) {
172
+ hidden.push(d);
173
+ event.target.classList.remove("show");
174
+ event.target.classList.add("hide");
175
+ d3.selectAll("#" + this.id + action + "dots").attr("opacity", "0.5");
176
+ } else {
177
+ hidden.splice(hidden.indexOf(d), 1);
178
+ event.target.classList.remove("hide");
179
+ event.target.classList.add("show");
180
+ d3.selectAll("#" + this.id + action + "dots").attr("opacity", "1");
181
+ }
182
+ drawChart();
183
+ };
184
+
185
+ const drawChart = () => {
186
+ const seriesVals = seriesData.filter((d) => !hidden.includes(d.action));
187
+ // Declare the x (horizontal position) scale.
188
+ const slots = seriesVals
189
+ .map((d) => d.slot)
190
+ .filter((v, i, a) => a.indexOf(v) === i);
191
+ // add buffer tp the scale
192
+ const slotHighest = d3.max(slots);
193
+ const slotLowest = d3.min(slots);
194
+ const interval = (slotHighest - slotLowest) / 20;
195
+ const buffer =
196
+ !slotHighest || !slotLowest ? null : slotHighest + interval;
197
+ const x = this.isTime
198
+ ? d3.scaleUtc(d3.extent([...slots, buffer]), [
199
+ marginLeft,
200
+ width - marginRight,
201
+ ])
202
+ : d3.scaleBand(slots, [marginLeft, width - marginRight]);
203
+ const maxY = d3.max(seriesVals, (d) => d.value);
204
+ const yScale = [height - marginBottom, marginTop];
205
+ for (const action of namesIndex) {
206
+ if (hidden.includes(action)) {
207
+ continue;
208
+ } else {
209
+ const nI = namesIndex.indexOf(action);
210
+ const actionVals = seriesData.filter((d) => d.action === action);
211
+ const series = d3
212
+ .stack()
213
+ .keys(
214
+ d3.union(actionVals.map((d) => d.action + ":" + d.instance))
215
+ )
216
+ .value((d, key) => {
217
+ if (d[1].get(key) === undefined) {
218
+ return 0;
219
+ }
220
+ return d[1].get(key).value;
221
+ })(
222
+ d3.index(
223
+ actionVals,
224
+ (d) => d.slot,
225
+ (d) => d.action + ":" + d.instance
226
+ )
227
+ );
228
+ const y = d3.scaleLinear([0, maxY], yScale);
229
+ this.svg
230
+ .append("g")
231
+ .selectAll()
232
+ .data(series)
233
+ .join("g")
234
+ .attr(
235
+ "fill",
236
+ (d) =>
237
+ platformMetricsLabels.scale[d.key.split(":")[0]](
238
+ (0.5 * instancesIndex.indexOf(d.key.split(":")[1])) /
239
+ instancesIndex.length +
240
+ 0.5
241
+ ) ||
242
+ chartColors[
243
+ namesIndex.indexOf(d.key.split(":")[0]) % chartColors.length
244
+ ]
245
+ )
246
+ .selectAll("rect")
247
+ .data((D) => D.map((d) => ((d.key = D.key), d)))
248
+ .join("rect")
249
+ .attr("class", (d) => {
250
+ return `${this.id}${nI}bar ${this.id}bar`;
251
+ })
252
+ .attr("x", (d) => x(d.data[0]) + (30 * nI) / namesIndex.length)
253
+ .attr("y", (d) => height - marginBottom)
254
+ .attr(
255
+ "width",
256
+ Math.min(
257
+ (width - marginLeft - marginRight) / slots.length,
258
+ 25
259
+ ) / namesIndex.length
260
+ )
261
+ .attr("height", 0)
262
+ .attr("stroke", "black")
263
+ .attr("stroke-width", "0.5")
264
+ .on("mouseover", mouseover)
265
+ .on("mouseout", mouseout)
266
+ .transition()
267
+ .duration(1000)
268
+ .attr("y", (d) => y(d[1]))
269
+ .attr("height", (d) => y(d[0]) - y(d[1]));
270
+ }
271
+ }
272
+ // Declare the y (vertical position) scale.
273
+ const y = d3.scaleLinear([0, maxY], yScale);
274
+ // Add the x-axis.
275
+ this.svg
276
+ .append("g")
277
+ .attr("transform", `translate(0,${height - marginBottom})`)
278
+ .attr("class", this.id + "xaxis")
279
+ .call(
280
+ this.isTime
281
+ ? d3
282
+ .axisBottom(x)
283
+ .ticks(width / 80)
284
+ .tickSizeOuter(0)
285
+ : d3
286
+ .axisBottom(x)
287
+ .ticks(width / 20)
288
+ .tickSizeOuter(0)
289
+ .tickFormat((d) => {
290
+ if (!this.isTime) {
291
+ return adjustText(
292
+ d,
293
+ ((width - marginRight) / slots.length) * 8
294
+ );
295
+ }
296
+ })
297
+ );
298
+ // Add the y-axis, remove the domain line, add grid lines and a label.
299
+ this.svg
300
+ .append("g")
301
+ .attr("transform", `translate(${marginLeft},0)`)
302
+ .attr("class", this.id + "yaxis")
303
+ .call(
304
+ d3
305
+ .axisLeft(y)
306
+ .ticks(height / 40)
307
+ .tickFormat((d) => {
308
+ return this.unit === "Bytes (B)"
309
+ ? dataCount(d)
310
+ : this.unit === "Cost ($)"
311
+ ? costCount(d)
312
+ : humanCount(d);
313
+ })
314
+ )
315
+ .call((g) => g.select(".domain").remove())
316
+ .call((g) =>
317
+ g
318
+ .selectAll(".tick line")
319
+ .clone()
320
+ .attr("x2", width - marginLeft - marginRight)
321
+ .attr("stroke-opacity", 0.1)
322
+ )
323
+ .call((g) =>
324
+ g
325
+ .append("text")
326
+ .attr("x", -marginLeft)
327
+ .attr("y", 10)
328
+ .attr("fill", "currentColor")
329
+ .attr("text-anchor", "start")
330
+ .text(this.unit)
331
+ );
332
+ };
333
+
334
+ drawChart(data);
335
+ if (data.length === 0) {
336
+ this.svg
337
+ .append("text")
338
+ .attr("x", width / 2)
339
+ .attr("y", height / 2)
340
+ .attr("text-anchor", "middle")
341
+ .text("No data available")
342
+ .attr("fill", "currentColor");
343
+ }
344
+ // Add a legend
345
+ this.legend = d3
346
+ .select("#" + this.id + "legend")
347
+ .append("svg")
348
+ .attr("width", Math.max(this.width, namesIndex.length * 100))
349
+ .attr("height", 30);
350
+
351
+ // Add one dot in the legend for each name.
352
+ this.legend
353
+ .selectAll("legendDots")
354
+ .data(namesIndex)
355
+ .enter()
356
+ .append("circle")
357
+ .attr("id", (d) => this.id + namesIndex.indexOf(d) + "dots")
358
+ .attr("class", "show")
359
+ .attr("cx", (d, i) => width / (namesIndex.length + 1) + i * 100 - 10)
360
+ .attr("cy", 5)
361
+ .attr("r", 5)
362
+ .attr(
363
+ "fill",
364
+ (d, i) =>
365
+ platformMetricsLabels[this.theme][d] ||
366
+ chartColors[i % chartColors.length]
367
+ )
368
+ .on("mouseover", legendMouseover)
369
+ .on("mouseout", legendMouseout)
370
+ .on("click", legendClick);
371
+
372
+ // Add one dot in the legend for each name.
373
+ this.legend
374
+ .selectAll("legendLabels")
375
+ .data(namesIndex)
376
+ .enter()
377
+ .append("text")
378
+ .attr("class", (d) => this.id + namesIndex.indexOf(d) + "labels")
379
+ .attr("x", (d, i) => width / (namesIndex.length + 1) + i * 100)
380
+ .attr("y", 5)
381
+ .attr(
382
+ "fill",
383
+ (d, i) =>
384
+ platformMetricsLabels[this.theme][d] ||
385
+ chartColors[i % chartColors.length]
386
+ )
387
+ .text((d, i) => adjustText(d, 700))
388
+ .attr("font-weight", 500)
389
+ .attr("text-anchor", "left")
390
+ .attr("font-size", "11px")
391
+ .style("alignment-baseline", "middle");
392
+ },
393
+ },
394
+ };
395
+ </script>
@@ -0,0 +1,215 @@
1
+ <template>
2
+ <div class="col items-center">
3
+ <div class="text-center">
4
+ <span>{{ title }} Timeline ({{ total }} Events)</span>
5
+ </div>
6
+ <div ref="myplot" :class="['px-4', { 'pb-4': !props.flow }]"></div>
7
+ <div class="flex justify-end w-full mr-2">
8
+ <div ref="myplotLegend"></div>
9
+ </div>
10
+ </div>
11
+ </template>
12
+
13
+ <script setup>
14
+ import { ref, watch } from "vue";
15
+ import * as d3 from "d3";
16
+ import * as Plot from "@observablehq/plot";
17
+ import { dateLocalTime } from "@/utils/timeUtils";
18
+
19
+ // props
20
+ const props = defineProps({
21
+ title: String,
22
+ buckets: Array,
23
+ total: Number,
24
+ from: Number,
25
+ to: Number,
26
+ flow: {
27
+ type: Boolean,
28
+ default: false,
29
+ },
30
+ theme: {
31
+ type: String,
32
+ default: "light",
33
+ },
34
+ });
35
+ // states
36
+ const myplot = ref(null);
37
+ const myplotLegend = ref(null);
38
+ // watch for changes in data
39
+ watch([() => props.buckets], () => {
40
+ plotGraph();
41
+ });
42
+
43
+ // function defs
44
+ function plotGraph() {
45
+ if (!props.buckets) return;
46
+ let options = {
47
+ marginTop: 30,
48
+ marks: [
49
+ Plot.frame(),
50
+ Plot.text(["No data available!"], { frameAnchor: "middle" }),
51
+ ],
52
+ }
53
+
54
+ if (props.buckets.length > 0) {
55
+ if (props.flow) {
56
+ const b = props.buckets;
57
+
58
+ // Left axis (flow) domain = max of rx/tx
59
+ const leftMax = Math.max(
60
+ 1,
61
+ d3.max(b, d => Math.max(d?.rxHistogram?.value ?? 0, d?.txHistogram?.value ?? 0)) ?? 0
62
+ );
63
+
64
+ // Right axis (events) domain = doc_count
65
+ const rightMax = Math.max(1, d3.max(b, d => d?.doc_count ?? 0) ?? 0);
66
+
67
+ // Map right-axis data (doc_count) into left-axis scale
68
+ const k = leftMax / rightMax; // multiply doc_count by k to draw on left scale
69
+
70
+ // Nice ticks for the right axis; we’ll place them at tick*k but label as tick
71
+ const rightTicks = d3.ticks(0, rightMax, 5);
72
+ const leftTicks = d3.ticks(0, leftMax, 5)
73
+
74
+ options = {
75
+ x: { type: "time", label: "Time", tickSpacing: 100 },
76
+ y: {
77
+ label: "Flow",
78
+ domain: [0, leftMax]
79
+ },
80
+ grid: true,
81
+ marks: [
82
+ // Flow lines on left scale
83
+ Plot.lineY(b, {
84
+ x: "key",
85
+ y: d => d?.rxHistogram?.value ?? 0,
86
+ strokeWidth: 2.5,
87
+ curve: "catmull-rom",
88
+ stroke: "#22c55e", // rx
89
+ }),
90
+ Plot.lineY(b, {
91
+ x: "key",
92
+ y: d => d?.txHistogram?.value ?? 0,
93
+ strokeWidth: 2.5,
94
+ curve: "catmull-rom",
95
+ stroke: "#eab308", // tx
96
+ }),
97
+
98
+ // doc_count drawn on LEFT scale after scaling by k
99
+ Plot.lineY(b, {
100
+ x: "key",
101
+ y: d => (d?.doc_count ?? 0) * k,
102
+ strokeWidth: 2.5,
103
+ curve: "catmull-rom",
104
+ stroke: "#71b6e0", // count
105
+ }),
106
+ Plot.dotY(b, {
107
+ x: "key",
108
+ y: d => (d?.doc_count ?? 0) * k,
109
+ stroke: "#71b6e0",
110
+ strokeWidth: 3,
111
+ }),
112
+
113
+ // Left y-axis: place ticks at tick (left-scale coords), but format as original (tick)
114
+ Plot.axisY({
115
+ anchor: "left",
116
+ ticks: leftTicks.map(t => t),
117
+ tickFormat: (_, i) => d3.format("~s")(leftTicks[i]) + "B",
118
+ label: "Bytes",
119
+ }),
120
+
121
+ // Right y-axis: place ticks at tick*k (left-scale coords), but format as original (tick)
122
+ Plot.axisY({
123
+ anchor: "right",
124
+ ticks: rightTicks.map(t => t * k),
125
+ tickFormat: (_, i) => d3.format("~s")(rightTicks[i]),
126
+ label: "Events",
127
+ }),
128
+
129
+ // Pointer showing all three original values (no scaling in tooltip)
130
+ Plot.tip(
131
+ b,
132
+ Plot.pointerX({
133
+ x: "key",
134
+ y: d => (d?.doc_count ?? 0) * k, // so the tip follows the count line; could also use rx/tx
135
+ fill: props.theme === "light" ? "white" : "black",
136
+ title: d =>
137
+ `Time: ${dateLocalTime(d.key)}\n` +
138
+ `rx: ${d?.rxHistogram?.value ?? 0}B (~${d3.format(".0s")(d?.rxHistogram?.value)}B)\n` +
139
+ `tx: ${d?.txHistogram?.value ?? 0}B (~${d3.format(".0s")(d?.txHistogram?.value)}B)\n` +
140
+ `count: ${d?.doc_count ?? 0}`
141
+ })
142
+ ),
143
+ ]
144
+ };
145
+ } else {
146
+ options = {
147
+ x: {
148
+ type: "time",
149
+ label: "Time",
150
+ tickSpacing: 100,
151
+ },
152
+ y: {
153
+ label: "Count",
154
+ domain: [
155
+ 0,
156
+ Math.max(1,
157
+ d3.max(props.buckets, (d) => d.doc_count) ?? 0
158
+ ),
159
+ ],
160
+ },
161
+ grid: true,
162
+ marks: [
163
+ Plot.lineY(props.buckets, {
164
+ x: "key",
165
+ y: "doc_count",
166
+ strokeWidth: 3,
167
+ curve: "catmull-rom",
168
+ stroke: "#71b6e0",
169
+ }),
170
+ Plot.dotY(props.buckets, {
171
+ x: "key",
172
+ y: "doc_count",
173
+ stroke: "#71b6e0",
174
+ strokeWidth: 3,
175
+ }),
176
+ Plot.tip(
177
+ props.buckets,
178
+ Plot.pointerX({
179
+ x: "key",
180
+ y: "doc_count",
181
+ fill: props.theme === "light" ? "white" : "black",
182
+ title: (d) =>
183
+ `Time: ${dateLocalTime(d.key)}\nCount: ${d.doc_count}`,
184
+ })
185
+ ),
186
+ ],
187
+ }
188
+ }
189
+ }
190
+
191
+ const plot = Plot.plot({
192
+ marginLeft: 80,
193
+ marginRight: 80,
194
+ width: 1200,
195
+ height: 320,
196
+ marginBottom: 50,
197
+ inset: 20,
198
+ style: {
199
+ fontSize: "16px",
200
+ backgroundColor: props.theme === "light" ? "white" : "#1a202c",
201
+ },
202
+ ...options,
203
+ });
204
+ myplot.value.innerHTML = "";
205
+ myplot.value.appendChild(plot);
206
+ if (props.flow) {
207
+ const legend = Plot.legend({
208
+ color: { type: "categorical", domain: ["Received", "Sent", "Flows"], range: ["#22c55e", "#eab308", "#71b6e0"] },
209
+ swatchSize: 8
210
+ });
211
+ myplotLegend.value.innerHTML = "";
212
+ myplotLegend.value.appendChild(legend);
213
+ }
214
+ }
215
+ </script>