@oneuptime/common 7.0.2990 → 7.0.3010

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 (197) hide show
  1. package/Models/AnalyticsModels/ExceptionInstance.ts +488 -0
  2. package/Models/AnalyticsModels/Index.ts +2 -0
  3. package/Models/AnalyticsModels/Span.ts +2 -2
  4. package/Models/DatabaseModels/Index.ts +4 -0
  5. package/Models/DatabaseModels/TelemetryException.ts +978 -0
  6. package/Server/API/StatusAPI.ts +63 -51
  7. package/Server/EnvironmentConfig.ts +3 -0
  8. package/Server/Infrastructure/Postgres/SchemaMigrations/1724610006927-MigrationName.ts +93 -0
  9. package/Server/Infrastructure/Postgres/SchemaMigrations/1724613666632-MigrationName.ts +60 -0
  10. package/Server/Infrastructure/Postgres/SchemaMigrations/1724659071843-MigrationName.ts +17 -0
  11. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +6 -0
  12. package/Server/Infrastructure/Queue.ts +36 -1
  13. package/Server/Infrastructure/QueueWorker.ts +2 -2
  14. package/Server/Services/DatabaseService.ts +4 -5
  15. package/Server/Services/ExceptionInstanceService.ts +11 -0
  16. package/Server/Services/Index.ts +5 -0
  17. package/Server/Services/StatusPageDomainService.ts +118 -59
  18. package/Server/Services/TelemetryExceptionService.ts +10 -0
  19. package/Server/Types/Database/Permissions/Index.ts +1 -1
  20. package/Server/Types/Database/UpdateByID.ts +1 -1
  21. package/Server/Utils/Greenlock/Greenlock.ts +331 -204
  22. package/Server/Utils/Logger.ts +8 -2
  23. package/Server/Utils/Telemetry.ts +109 -25
  24. package/Types/Code/CodeType.ts +1 -0
  25. package/Types/Database/PartialEntity.ts +14 -1
  26. package/Types/Date.ts +9 -1
  27. package/Types/Icon/IconProp.ts +2 -0
  28. package/Types/Permission.ts +39 -0
  29. package/UI/Components/ActionCard/ActionCard.tsx +66 -0
  30. package/UI/Components/Alerts/Alert.tsx +69 -60
  31. package/UI/Components/Card/Card.tsx +1 -0
  32. package/UI/Components/Charts/ChartGroup/ChartGroup.tsx +4 -17
  33. package/UI/Components/Charts/ChartLibrary/LineChart/LineChart.tsx +1005 -0
  34. package/UI/Components/Charts/ChartLibrary/Types/ChartDataPoint.ts +3 -0
  35. package/UI/Components/Charts/ChartLibrary/Utils/ChartColors.ts +117 -0
  36. package/UI/Components/Charts/ChartLibrary/Utils/Cx.ts +8 -0
  37. package/UI/Components/Charts/ChartLibrary/Utils/GetYAxisDomain.ts +15 -0
  38. package/UI/Components/Charts/ChartLibrary/Utils/HasOnlyOneValueForKey.ts +19 -0
  39. package/UI/Components/Charts/ChartLibrary/Utils/UseWindowOnResize.ts +17 -0
  40. package/UI/Components/Charts/Line/LineChart.tsx +58 -225
  41. package/UI/Components/Charts/Types/ChartCurve.ts +7 -0
  42. package/UI/Components/Charts/Types/DataPoint.ts +7 -0
  43. package/UI/Components/Charts/Types/SeriesPoint.ts +7 -0
  44. package/UI/Components/Charts/Types/SeriesPoints.ts +6 -0
  45. package/UI/Components/Charts/Types/XAxis/XAxis.ts +21 -0
  46. package/UI/Components/Charts/Types/XAxis/XAxisMaxMin.ts +3 -0
  47. package/UI/Components/Charts/Types/XAxis/XAxisPrecision.ts +26 -0
  48. package/UI/Components/Charts/Types/XAxis/XAxisType.ts +6 -0
  49. package/UI/Components/Charts/Types/XValue.ts +3 -0
  50. package/UI/Components/Charts/Types/YAxis/YAxis.ts +22 -0
  51. package/UI/Components/Charts/Types/YAxis/YAxisMaxMin.ts +3 -0
  52. package/UI/Components/Charts/Types/YAxis/YAxisType.ts +5 -0
  53. package/UI/Components/Charts/Types/YValue.ts +3 -0
  54. package/UI/Components/Charts/Utils/DataPoint.ts +188 -0
  55. package/UI/Components/Charts/Utils/XAxis.ts +267 -0
  56. package/UI/Components/Detail/Detail.tsx +6 -1
  57. package/UI/Components/GanttChart/Row/Row.tsx +4 -2
  58. package/UI/Components/GanttChart/Row/RowLabel.tsx +7 -3
  59. package/UI/Components/Icon/Icon.tsx +16 -0
  60. package/UI/Components/LogsViewer/LogsViewer.tsx +1 -1
  61. package/UI/Components/Types/FieldType.ts +1 -0
  62. package/UI/Config.ts +2 -0
  63. package/UI/Utils/Telemetry.ts +7 -2
  64. package/Utils/Crypto.ts +11 -0
  65. package/build/dist/Models/AnalyticsModels/ExceptionInstance.js +445 -0
  66. package/build/dist/Models/AnalyticsModels/ExceptionInstance.js.map +1 -0
  67. package/build/dist/Models/AnalyticsModels/Index.js +2 -0
  68. package/build/dist/Models/AnalyticsModels/Index.js.map +1 -1
  69. package/build/dist/Models/AnalyticsModels/Span.js +2 -2
  70. package/build/dist/Models/DatabaseModels/Index.js +2 -0
  71. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  72. package/build/dist/Models/DatabaseModels/TelemetryException.js +1010 -0
  73. package/build/dist/Models/DatabaseModels/TelemetryException.js.map +1 -0
  74. package/build/dist/Server/API/StatusAPI.js +52 -44
  75. package/build/dist/Server/API/StatusAPI.js.map +1 -1
  76. package/build/dist/Server/EnvironmentConfig.js +1 -0
  77. package/build/dist/Server/EnvironmentConfig.js.map +1 -1
  78. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1724610006927-MigrationName.js +38 -0
  79. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1724610006927-MigrationName.js.map +1 -0
  80. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1724613666632-MigrationName.js +26 -0
  81. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1724613666632-MigrationName.js.map +1 -0
  82. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1724659071843-MigrationName.js +12 -0
  83. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1724659071843-MigrationName.js.map +1 -0
  84. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +6 -0
  85. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  86. package/build/dist/Server/Infrastructure/Queue.js +20 -1
  87. package/build/dist/Server/Infrastructure/Queue.js.map +1 -1
  88. package/build/dist/Server/Infrastructure/QueueWorker.js +2 -2
  89. package/build/dist/Server/Infrastructure/QueueWorker.js.map +1 -1
  90. package/build/dist/Server/Services/DatabaseService.js.map +1 -1
  91. package/build/dist/Server/Services/ExceptionInstanceService.js +9 -0
  92. package/build/dist/Server/Services/ExceptionInstanceService.js.map +1 -0
  93. package/build/dist/Server/Services/Index.js +4 -0
  94. package/build/dist/Server/Services/Index.js.map +1 -1
  95. package/build/dist/Server/Services/StatusPageDomainService.js +101 -53
  96. package/build/dist/Server/Services/StatusPageDomainService.js.map +1 -1
  97. package/build/dist/Server/Services/TelemetryExceptionService.js +9 -0
  98. package/build/dist/Server/Services/TelemetryExceptionService.js.map +1 -0
  99. package/build/dist/Server/Types/Database/Permissions/Index.js.map +1 -1
  100. package/build/dist/Server/Utils/Greenlock/Greenlock.js +234 -157
  101. package/build/dist/Server/Utils/Greenlock/Greenlock.js.map +1 -1
  102. package/build/dist/Server/Utils/Logger.js +5 -1
  103. package/build/dist/Server/Utils/Logger.js.map +1 -1
  104. package/build/dist/Server/Utils/Telemetry.js +63 -22
  105. package/build/dist/Server/Utils/Telemetry.js.map +1 -1
  106. package/build/dist/Types/Code/CodeType.js +1 -0
  107. package/build/dist/Types/Code/CodeType.js.map +1 -1
  108. package/build/dist/Types/Database/PartialEntity.js +3 -0
  109. package/build/dist/Types/Database/PartialEntity.js.map +1 -1
  110. package/build/dist/Types/Date.js +7 -1
  111. package/build/dist/Types/Date.js.map +1 -1
  112. package/build/dist/Types/Icon/IconProp.js +2 -0
  113. package/build/dist/Types/Icon/IconProp.js.map +1 -1
  114. package/build/dist/Types/Permission.js +33 -0
  115. package/build/dist/Types/Permission.js.map +1 -1
  116. package/build/dist/UI/Components/ActionCard/ActionCard.js +27 -0
  117. package/build/dist/UI/Components/ActionCard/ActionCard.js.map +1 -0
  118. package/build/dist/UI/Components/Alerts/Alert.js +36 -45
  119. package/build/dist/UI/Components/Alerts/Alert.js.map +1 -1
  120. package/build/dist/UI/Components/Card/Card.js +1 -1
  121. package/build/dist/UI/Components/Card/Card.js.map +1 -1
  122. package/build/dist/UI/Components/Charts/ChartGroup/ChartGroup.js +4 -9
  123. package/build/dist/UI/Components/Charts/ChartGroup/ChartGroup.js.map +1 -1
  124. package/build/dist/UI/Components/Charts/ChartLibrary/LineChart/LineChart.js +388 -0
  125. package/build/dist/UI/Components/Charts/ChartLibrary/LineChart/LineChart.js.map +1 -0
  126. package/build/dist/UI/Components/Charts/ChartLibrary/Types/ChartDataPoint.js +2 -0
  127. package/build/dist/UI/Components/Charts/ChartLibrary/Types/ChartDataPoint.js.map +1 -0
  128. package/build/dist/UI/Components/Charts/ChartLibrary/Utils/ChartColors.js +88 -0
  129. package/build/dist/UI/Components/Charts/ChartLibrary/Utils/ChartColors.js.map +1 -0
  130. package/build/dist/UI/Components/Charts/ChartLibrary/Utils/Cx.js +7 -0
  131. package/build/dist/UI/Components/Charts/ChartLibrary/Utils/Cx.js.map +1 -0
  132. package/build/dist/UI/Components/Charts/ChartLibrary/Utils/GetYAxisDomain.js +7 -0
  133. package/build/dist/UI/Components/Charts/ChartLibrary/Utils/GetYAxisDomain.js.map +1 -0
  134. package/build/dist/UI/Components/Charts/ChartLibrary/Utils/HasOnlyOneValueForKey.js +14 -0
  135. package/build/dist/UI/Components/Charts/ChartLibrary/Utils/HasOnlyOneValueForKey.js.map +1 -0
  136. package/build/dist/UI/Components/Charts/ChartLibrary/Utils/UseWindowOnResize.js +14 -0
  137. package/build/dist/UI/Components/Charts/ChartLibrary/Utils/UseWindowOnResize.js.map +1 -0
  138. package/build/dist/UI/Components/Charts/Line/LineChart.js +30 -136
  139. package/build/dist/UI/Components/Charts/Line/LineChart.js.map +1 -1
  140. package/build/dist/UI/Components/Charts/Types/ChartCurve.js +8 -0
  141. package/build/dist/UI/Components/Charts/Types/ChartCurve.js.map +1 -0
  142. package/build/dist/UI/Components/Charts/Types/DataPoint.js +2 -0
  143. package/build/dist/UI/Components/Charts/Types/DataPoint.js.map +1 -0
  144. package/build/dist/UI/Components/Charts/Types/SeriesPoint.js +2 -0
  145. package/build/dist/UI/Components/Charts/Types/SeriesPoint.js.map +1 -0
  146. package/build/dist/UI/Components/Charts/Types/SeriesPoints.js +2 -0
  147. package/build/dist/UI/Components/Charts/Types/SeriesPoints.js.map +1 -0
  148. package/build/dist/UI/Components/Charts/Types/XAxis/XAxis.js +8 -0
  149. package/build/dist/UI/Components/Charts/Types/XAxis/XAxis.js.map +1 -0
  150. package/build/dist/UI/Components/Charts/Types/XAxis/XAxisMaxMin.js +2 -0
  151. package/build/dist/UI/Components/Charts/Types/XAxis/XAxisMaxMin.js.map +1 -0
  152. package/build/dist/UI/Components/Charts/Types/XAxis/XAxisPrecision.js +27 -0
  153. package/build/dist/UI/Components/Charts/Types/XAxis/XAxisPrecision.js.map +1 -0
  154. package/build/dist/UI/Components/Charts/Types/XAxis/XAxisType.js +7 -0
  155. package/build/dist/UI/Components/Charts/Types/XAxis/XAxisType.js.map +1 -0
  156. package/build/dist/UI/Components/Charts/Types/XValue.js +2 -0
  157. package/build/dist/UI/Components/Charts/Types/XValue.js.map +1 -0
  158. package/build/dist/UI/Components/Charts/Types/YAxis/YAxis.js +8 -0
  159. package/build/dist/UI/Components/Charts/Types/YAxis/YAxis.js.map +1 -0
  160. package/build/dist/UI/Components/Charts/Types/YAxis/YAxisMaxMin.js +2 -0
  161. package/build/dist/UI/Components/Charts/Types/YAxis/YAxisMaxMin.js.map +1 -0
  162. package/build/dist/UI/Components/Charts/Types/YAxis/YAxisType.js +6 -0
  163. package/build/dist/UI/Components/Charts/Types/YAxis/YAxisType.js.map +1 -0
  164. package/build/dist/UI/Components/Charts/Types/YValue.js +2 -0
  165. package/build/dist/UI/Components/Charts/Types/YValue.js.map +1 -0
  166. package/build/dist/UI/Components/Charts/Utils/DataPoint.js +109 -0
  167. package/build/dist/UI/Components/Charts/Utils/DataPoint.js.map +1 -0
  168. package/build/dist/UI/Components/Charts/Utils/XAxis.js +241 -0
  169. package/build/dist/UI/Components/Charts/Utils/XAxis.js.map +1 -0
  170. package/build/dist/UI/Components/Detail/Detail.js +5 -1
  171. package/build/dist/UI/Components/Detail/Detail.js.map +1 -1
  172. package/build/dist/UI/Components/GanttChart/Row/Row.js +2 -2
  173. package/build/dist/UI/Components/GanttChart/Row/Row.js.map +1 -1
  174. package/build/dist/UI/Components/GanttChart/Row/RowLabel.js +3 -3
  175. package/build/dist/UI/Components/GanttChart/Row/RowLabel.js.map +1 -1
  176. package/build/dist/UI/Components/Icon/Icon.js +6 -0
  177. package/build/dist/UI/Components/Icon/Icon.js.map +1 -1
  178. package/build/dist/UI/Components/LogsViewer/LogsViewer.js +1 -1
  179. package/build/dist/UI/Components/LogsViewer/LogsViewer.js.map +1 -1
  180. package/build/dist/UI/Components/Types/FieldType.js +1 -0
  181. package/build/dist/UI/Components/Types/FieldType.js.map +1 -1
  182. package/build/dist/UI/Config.js +1 -0
  183. package/build/dist/UI/Config.js.map +1 -1
  184. package/build/dist/UI/Utils/Telemetry.js +6 -3
  185. package/build/dist/UI/Utils/Telemetry.js.map +1 -1
  186. package/build/dist/Utils/Crypto.js +10 -0
  187. package/build/dist/Utils/Crypto.js.map +1 -0
  188. package/package.json +15 -13
  189. package/UI/Components/Charts/Bar/Bar.tsx +0 -0
  190. package/UI/Components/Charts/Base/BaseChart.tsx +0 -0
  191. package/UI/Components/Charts/Tooltip/Tooltip.tsx +0 -84
  192. package/build/dist/UI/Components/Charts/Bar/Bar.js +0 -2
  193. package/build/dist/UI/Components/Charts/Bar/Bar.js.map +0 -1
  194. package/build/dist/UI/Components/Charts/Base/BaseChart.js +0 -2
  195. package/build/dist/UI/Components/Charts/Base/BaseChart.js.map +0 -1
  196. package/build/dist/UI/Components/Charts/Tooltip/Tooltip.js +0 -34
  197. package/build/dist/UI/Components/Charts/Tooltip/Tooltip.js.map +0 -1
@@ -0,0 +1,3 @@
1
+ export default interface ChartDataPoint {
2
+ [x: string]: number | string;
3
+ }
@@ -0,0 +1,117 @@
1
+ // Tremor Raw chartColors [v0.1.0]
2
+
3
+ export type ColorUtility = "bg" | "stroke" | "fill" | "text";
4
+
5
+ export const chartColors: {
6
+ [color: string]: {
7
+ [key in ColorUtility]: string;
8
+ };
9
+ } = {
10
+ blue: {
11
+ bg: "bg-blue-500",
12
+ stroke: "stroke-blue-500",
13
+ fill: "fill-blue-500",
14
+ text: "text-blue-500",
15
+ },
16
+ emerald: {
17
+ bg: "bg-emerald-500",
18
+ stroke: "stroke-emerald-500",
19
+ fill: "fill-emerald-500",
20
+ text: "text-emerald-500",
21
+ },
22
+ violet: {
23
+ bg: "bg-violet-500",
24
+ stroke: "stroke-violet-500",
25
+ fill: "fill-violet-500",
26
+ text: "text-violet-500",
27
+ },
28
+ amber: {
29
+ bg: "bg-amber-500",
30
+ stroke: "stroke-amber-500",
31
+ fill: "fill-amber-500",
32
+ text: "text-amber-500",
33
+ },
34
+ gray: {
35
+ bg: "bg-gray-500",
36
+ stroke: "stroke-gray-500",
37
+ fill: "fill-gray-500",
38
+ text: "text-gray-500",
39
+ },
40
+ cyan: {
41
+ bg: "bg-cyan-500",
42
+ stroke: "stroke-cyan-500",
43
+ fill: "fill-cyan-500",
44
+ text: "text-cyan-500",
45
+ },
46
+ pink: {
47
+ bg: "bg-pink-500",
48
+ stroke: "stroke-pink-500",
49
+ fill: "fill-pink-500",
50
+ text: "text-pink-500",
51
+ },
52
+ lime: {
53
+ bg: "bg-lime-500",
54
+ stroke: "stroke-lime-500",
55
+ fill: "fill-lime-500",
56
+ text: "text-lime-500",
57
+ },
58
+ fuchsia: {
59
+ bg: "bg-fuchsia-500",
60
+ stroke: "stroke-fuchsia-500",
61
+ fill: "fill-fuchsia-500",
62
+ text: "text-fuchsia-500",
63
+ },
64
+ indigo: {
65
+ bg: "bg-indigo-500",
66
+ stroke: "stroke-indigo-500",
67
+ fill: "fill-indigo-500",
68
+ text: "text-indigo-500",
69
+ },
70
+ rose: {
71
+ bg: "bg-rose-500",
72
+ stroke: "stroke-rose-500",
73
+ fill: "fill-rose-500",
74
+ text: "text-rose-500",
75
+ },
76
+ };
77
+
78
+ export type AvailableChartColorsKeys = keyof typeof chartColors;
79
+
80
+ export const AvailableChartColors: AvailableChartColorsKeys[] = Object.keys(
81
+ chartColors,
82
+ ) as Array<AvailableChartColorsKeys>;
83
+
84
+ export const constructCategoryColors: (
85
+ categories: string[],
86
+ colors: AvailableChartColorsKeys[],
87
+ ) => Map<string, AvailableChartColorsKeys> = (
88
+ categories: string[],
89
+ colors: AvailableChartColorsKeys[],
90
+ ): Map<string, AvailableChartColorsKeys> => {
91
+ const categoryColors: Map<string, AvailableChartColorsKeys> = new Map<
92
+ string,
93
+ AvailableChartColorsKeys
94
+ >();
95
+ categories.forEach((category: string, index: number) => {
96
+ categoryColors.set(category, colors[index % colors.length]!);
97
+ });
98
+ return categoryColors;
99
+ };
100
+
101
+ export const getColorClassName: (
102
+ color: AvailableChartColorsKeys,
103
+ type: ColorUtility,
104
+ ) => string = (color: AvailableChartColorsKeys, type: ColorUtility): string => {
105
+ const fallbackColor: {
106
+ bg: string;
107
+ stroke: string;
108
+ fill: string;
109
+ text: string;
110
+ } = {
111
+ bg: "bg-gray-500",
112
+ stroke: "stroke-gray-500",
113
+ fill: "fill-gray-500",
114
+ text: "text-gray-500",
115
+ };
116
+ return chartColors[color]?.[type] ?? fallbackColor[type];
117
+ };
@@ -0,0 +1,8 @@
1
+ // Tremor Raw cx [v0.0.0]
2
+
3
+ import clsx, { type ClassValue } from "clsx";
4
+ import { twMerge } from "tailwind-merge";
5
+
6
+ export function cx(...args: ClassValue[]): string {
7
+ return twMerge(clsx(...args));
8
+ }
@@ -0,0 +1,15 @@
1
+ // Tremor Raw getYAxisDomain [v0.0.0]
2
+
3
+ export const getYAxisDomain: (
4
+ autoMinValue: boolean,
5
+ minValue: number | undefined,
6
+ maxValue: number | undefined,
7
+ ) => (number | "auto")[] = (
8
+ autoMinValue: boolean,
9
+ minValue: number | undefined,
10
+ maxValue: number | undefined,
11
+ ): (number | "auto")[] => {
12
+ const minDomain: number | "auto" = autoMinValue ? "auto" : minValue ?? 0;
13
+ const maxDomain: number | "auto" = maxValue ?? "auto";
14
+ return [minDomain, maxDomain];
15
+ };
@@ -0,0 +1,19 @@
1
+ // Tremor Raw hasOnlyOneValueForKey [v0.1.0]
2
+
3
+ export function hasOnlyOneValueForKey(
4
+ array: any[],
5
+ keyToCheck: string,
6
+ ): boolean {
7
+ const val: any[] = [];
8
+
9
+ for (const obj of array) {
10
+ if (Object.prototype.hasOwnProperty.call(obj, keyToCheck)) {
11
+ val.push(obj[keyToCheck]);
12
+ if (val.length > 1) {
13
+ return false;
14
+ }
15
+ }
16
+ }
17
+
18
+ return true;
19
+ }
@@ -0,0 +1,17 @@
1
+ import * as React from "react";
2
+
3
+ export const useOnWindowResize: (handler: () => void) => void = (
4
+ handler: () => void,
5
+ ): void => {
6
+ React.useEffect(() => {
7
+ const handleResize: () => void = () => {
8
+ handler();
9
+ };
10
+ handleResize();
11
+ window.addEventListener("resize", handleResize);
12
+
13
+ return () => {
14
+ window.removeEventListener("resize", handleResize);
15
+ };
16
+ }, [handler]);
17
+ };
@@ -1,240 +1,73 @@
1
- import { Box, CartesianMarkerProps } from "@nivo/core";
2
- import { LegendProps } from "@nivo/legends";
3
- import { Point, ResponsiveLine } from "@nivo/line";
4
- import { ChartColors } from "Common/Types/BrandColors";
5
- import Color from "Common/Types/Color";
6
- import OneUptimeDate from "Common/Types/Date";
7
- import React, { FunctionComponent, ReactElement } from "react";
1
+ import { LineChart } from "../ChartLibrary/LineChart/LineChart";
2
+ import React, { FunctionComponent, ReactElement, useEffect } from "react";
3
+ import SeriesPoint from "../Types/SeriesPoints";
4
+ import { XAxis } from "../Types/XAxis/XAxis";
5
+ import YAxis from "../Types/YAxis/YAxis";
6
+ import ChartCurve from "../Types/ChartCurve";
7
+ import ChartDataPoint from "../ChartLibrary/Types/ChartDataPoint";
8
+ import DataPointUtil from "../Utils/DataPoint";
8
9
 
9
- export type XValue = string | number | Date;
10
- export type YValue = number;
11
-
12
- export interface LineChartDataItem {
13
- x: XValue;
14
- y: YValue;
15
- }
16
-
17
- export enum ChartCurve {
18
- LINEAR = "linear",
19
- MONOTONE_X = "monotoneX",
20
- STEP = "step",
21
- STEP_BEFORE = "stepBefore",
22
- STEP_AFTER = "stepAfter",
23
- }
24
-
25
- export enum XScaleType {
26
- TIME = "time",
27
- }
28
-
29
- export enum XScalePrecision {
30
- SECOND = "second",
31
- MINUTE = "minute",
32
- HOUR = "hour",
33
- DAY = "day",
34
- MONTH = "month",
35
- YEAR = "year",
36
- }
37
-
38
- export type XScaleMaxMin = "auto" | number | Date;
39
- export type YScaleMaxMin = "auto" | number;
40
-
41
- export interface XScale {
42
- type: XScaleType;
43
- min: XScaleMaxMin;
44
- max: XScaleMaxMin;
45
- precision: XScalePrecision;
46
- }
47
-
48
- export interface LineChartData {
49
- seriesName: string;
50
- data: Array<LineChartDataItem>;
51
- }
52
-
53
- export enum YScaleType {
54
- LINEAR = "linear",
55
- }
56
-
57
- export interface YScale {
58
- type: YScaleType;
59
- min: YScaleMaxMin;
60
- max: YScaleMaxMin;
61
- }
62
-
63
- export enum AxisType {
64
- Date = "date",
65
- Time = "time",
66
- Number = "number",
67
- }
68
-
69
- export interface AxisBottom {
70
- legend: string;
71
- type: AxisType;
72
- }
73
-
74
- export interface AxisLeft {
75
- legend: string;
76
- type: AxisType;
77
- }
78
-
79
- export interface LineChartPoint {
80
- x: XValue;
81
- y: YValue;
82
- seriesName: string;
83
- seriesColor: Color;
10
+ export interface ComponentProps {
11
+ data: Array<SeriesPoint>;
12
+ xAxis: XAxis;
13
+ yAxis: YAxis;
14
+ curve: ChartCurve;
15
+ sync: boolean;
84
16
  }
85
17
 
86
- export interface ComponentProps {
87
- data: Array<LineChartData>;
88
- curve?: ChartCurve;
89
- xScale: XScale;
90
- yScale: YScale;
91
- axisBottom: AxisBottom;
92
- axisLeft: AxisLeft;
93
- onHoverXAxis?: (x: XValue) => void;
94
- xAxisMarker?: {
95
- value: XValue | undefined;
96
- };
97
- getHoverTooltip?: (data: { points: Array<LineChartPoint> }) => ReactElement;
18
+ export interface LineInternalProps extends ComponentProps {
19
+ syncId: string;
98
20
  }
99
21
 
100
- const LineChart: FunctionComponent<ComponentProps> = (
101
- props: ComponentProps,
22
+ const LineChartElement: FunctionComponent<LineInternalProps> = (
23
+ props: LineInternalProps,
102
24
  ): ReactElement => {
103
- const markers: Array<CartesianMarkerProps> = [];
104
-
105
- if (props.xAxisMarker && props.xAxisMarker.value) {
106
- markers.push({
107
- axis: "x",
108
- legend: "",
109
- lineStyle: {
110
- stroke: "#cbd5e1",
111
- strokeWidth: 2,
112
- },
113
- value: props.xAxisMarker.value,
114
- });
115
- }
25
+ const [records, setRecords] = React.useState<Array<ChartDataPoint>>([]);
116
26
 
117
- let legends: Array<LegendProps> = [];
27
+ const categories: Array<string> = props.data.map((item: SeriesPoint) => {
28
+ return item.seriesName;
29
+ });
118
30
 
119
- const showLegends: boolean = props.data.length > 1;
31
+ useEffect(() => {
32
+ if (!props.data || props.data.length === 0) {
33
+ setRecords([]);
34
+ }
120
35
 
121
- const margin: Box = { bottom: 60, left: 60, top: 20 };
122
-
123
- if (showLegends) {
124
- margin.right = 200;
36
+ const records: Array<ChartDataPoint> = DataPointUtil.getChartDataPoints({
37
+ seriesPoints: props.data,
38
+ xAxis: props.xAxis,
39
+ yAxis: props.yAxis,
40
+ });
125
41
 
126
- legends = [
127
- {
128
- anchor: "bottom-right",
129
- direction: "column",
130
- justify: false,
131
- translateX: 100,
132
- translateY: 0,
133
- itemsSpacing: 0,
134
- itemDirection: "left-to-right",
135
- itemWidth: 80,
136
- itemHeight: 20,
137
- itemOpacity: 0.75,
138
- symbolSize: 12,
139
- symbolShape: "circle",
140
- symbolBorderColor: "rgba(0, 0, 0, .5)",
141
- effects: [
142
- {
143
- on: "hover",
144
- style: {
145
- itemBackground: "rgba(0, 0, 0, .03)",
146
- itemOpacity: 1,
147
- },
148
- },
149
- ],
150
- },
151
- ];
152
- }
42
+ setRecords(records);
43
+ }, [props.data]);
153
44
 
154
45
  return (
155
- <div className="h-96 w-full">
156
- <ResponsiveLine
157
- data={props.data.map((series: LineChartData) => {
158
- return {
159
- id: series.seriesName,
160
- data: series.data,
161
- };
162
- })}
163
- onMouseMove={(data: Point) => {
164
- if (props.onHoverXAxis) {
165
- const xValue: XValue = ((data as any).points as Array<any>)?.[0]
166
- ?.data?.x;
167
- props.onHoverXAxis(xValue);
168
- }
169
- }}
170
- margin={margin}
171
- curve={props.curve || ChartCurve.LINEAR}
172
- markers={markers}
173
- xScale={{
174
- type: props.xScale.type,
175
- max: props.xScale.max as any,
176
- min: props.xScale.min as any,
177
- precision: props.xScale.precision,
178
- }}
179
- yScale={{
180
- type: props.yScale.type,
181
- min: props.yScale.min,
182
- max: props.yScale.max,
183
- }}
184
- axisTop={null}
185
- axisRight={null}
186
- axisBottom={{
187
- legend: props.axisBottom.legend,
188
- format: (value: XValue) => {
189
- let strLabel: string = "";
190
- if (props.axisBottom.type === AxisType.Date) {
191
- strLabel = OneUptimeDate.getDateAsLocalFormattedString(
192
- value as Date,
193
- true,
194
- );
195
- } else if (props.axisBottom.type === AxisType.Time) {
196
- strLabel = OneUptimeDate.getLocalHourAndMinuteFromDate(
197
- value as Date,
198
- );
199
- } else {
200
- strLabel = value.toString();
201
- }
202
-
203
- return strLabel;
204
- },
205
- }}
206
- useMesh={true}
207
- axisLeft={{
208
- legend: props.axisLeft.legend,
209
- }}
210
- enableSlices="x"
211
- sliceTooltip={(data: {
212
- slice: {
213
- points: readonly Point[];
214
- };
215
- }) => {
216
- if (!props.getHoverTooltip) {
217
- return <></>;
218
- }
219
-
220
- return props.getHoverTooltip({
221
- points: data.slice.points.map((point: Point) => {
222
- return {
223
- x: point.data.x as XValue,
224
- y: point.data.y as YValue,
225
- seriesName: point.serieId.toString(),
226
- seriesColor: new Color(point.color),
227
- };
228
- }),
229
- });
230
- }}
231
- colors={ChartColors.map((item: Color) => {
232
- return item.toString();
233
- })}
234
- legends={legends}
235
- />
236
- </div>
46
+ <LineChart
47
+ className="h-80"
48
+ data={records}
49
+ tickGap={1}
50
+ index={"Time"}
51
+ categories={categories}
52
+ colors={[
53
+ "indigo",
54
+ "rose",
55
+ "emerald",
56
+ "amber",
57
+ "cyan",
58
+ "gray",
59
+ "pink",
60
+ "lime",
61
+ "fuchsia",
62
+ ]}
63
+ valueFormatter={props.yAxis.options.formatter || undefined}
64
+ showTooltip={true}
65
+ connectNulls={true}
66
+ curve={props.curve}
67
+ syncId={props.sync ? props.syncId : undefined}
68
+ yAxisWidth={60}
69
+ />
237
70
  );
238
71
  };
239
72
 
240
- export default LineChart;
73
+ export default LineChartElement;
@@ -0,0 +1,7 @@
1
+ enum ChartCurve {
2
+ LINEAR = "linear",
3
+ MONOTONE = "monotone",
4
+ STEP = "step",
5
+ }
6
+
7
+ export default ChartCurve;
@@ -0,0 +1,7 @@
1
+ import XValue from "./XValue";
2
+ import YValue from "./YValue";
3
+
4
+ export default interface DataPoint {
5
+ x: XValue;
6
+ y: YValue;
7
+ }
@@ -0,0 +1,7 @@
1
+ import Color from "../../../../Types/Color";
2
+ import DataPoint from "./DataPoint";
3
+
4
+ export interface SeriesPoint extends DataPoint {
5
+ seriesName: string;
6
+ seriesColor: Color;
7
+ }
@@ -0,0 +1,6 @@
1
+ import DataPoint from "./DataPoint";
2
+
3
+ export default interface SeriesPoints {
4
+ data: Array<DataPoint>;
5
+ seriesName: string;
6
+ }
@@ -0,0 +1,21 @@
1
+ import XAxisMaxMin from "./XAxisMaxMin";
2
+ import XAxisType from "./XAxisType";
3
+
4
+ export enum XAxisAggregateType {
5
+ Average = "Average",
6
+ Sum = "Sum",
7
+ Max = "Max",
8
+ Min = "Min",
9
+ }
10
+
11
+ export interface XAxisOptions {
12
+ type: XAxisType;
13
+ min: XAxisMaxMin;
14
+ max: XAxisMaxMin;
15
+ aggregateType: XAxisAggregateType;
16
+ }
17
+
18
+ export interface XAxis {
19
+ legend: string;
20
+ options: XAxisOptions;
21
+ }
@@ -0,0 +1,3 @@
1
+ type XAxisMaxMin = number | Date;
2
+
3
+ export default XAxisMaxMin;
@@ -0,0 +1,26 @@
1
+ enum XAxisPrecision {
2
+ EVERY_SECOND = "second",
3
+ EVERY_FIVE_SECONDS = "fiveSeconds",
4
+ EVERY_TEN_SECONDS = "tenSeconds",
5
+ EVERY_THIRTY_SECONDS = "thirtySeconds",
6
+ EVERY_MINUTE = "minute",
7
+ EVERY_FIVE_MINUTES = "fiveMinutes",
8
+ EVERY_TEN_MINUTES = "tenMinutes",
9
+ EVERY_THIRTY_MINUTES = "thirtyMinutes",
10
+ EVERY_HOUR = "hour",
11
+ EVERY_TWO_HOURS = "twoHours",
12
+ EVERY_THREE_HOURS = "threeHours",
13
+ EVERY_SIX_HOURS = "sixHours",
14
+ EVERY_TWELVE_HOURS = "twelveHours",
15
+ EVERY_DAY = "day",
16
+ EVERY_TWO_DAYS = "twoDays",
17
+ EVERY_WEEK = "week",
18
+ EVERY_TWO_WEEKS = "twoWeeks",
19
+ EVERY_MONTH = "month",
20
+ EVERY_TWO_MONTHS = "twoMonths",
21
+ EVERY_THREE_MONTHS = "threeMonths",
22
+ EVERY_SIX_MONTHS = "sixMonths",
23
+ EVERY_YEAR = "year",
24
+ }
25
+
26
+ export default XAxisPrecision;
@@ -0,0 +1,6 @@
1
+ enum XAxisType {
2
+ Time = "time",
3
+ Date = "date",
4
+ }
5
+
6
+ export default XAxisType;
@@ -0,0 +1,3 @@
1
+ type XValue = Date;
2
+
3
+ export default XValue;
@@ -0,0 +1,22 @@
1
+ import YAxisMaxMin from "./YAxisMaxMin";
2
+ import YAxisType from "./YAxisType";
3
+
4
+ export enum YAxisPrecision {
5
+ NoDecimals = "NoDecimals",
6
+ OneDecimal = "OneDecimal",
7
+ TwoDecimals = "TwoDecimals",
8
+ ThreeDecimals = "ThreeDecimals",
9
+ }
10
+
11
+ export interface YAxisOptions {
12
+ type: YAxisType;
13
+ min: YAxisMaxMin;
14
+ max: YAxisMaxMin;
15
+ formatter: (value: number) => string;
16
+ precision: YAxisPrecision;
17
+ }
18
+
19
+ export default interface YAxis {
20
+ legend: string;
21
+ options: YAxisOptions;
22
+ }
@@ -0,0 +1,3 @@
1
+ type YScaleMaxMin = "auto" | number;
2
+
3
+ export default YScaleMaxMin;
@@ -0,0 +1,5 @@
1
+ enum YAxisType {
2
+ Number = "number",
3
+ }
4
+
5
+ export default YAxisType;
@@ -0,0 +1,3 @@
1
+ type YValue = number;
2
+
3
+ export default YValue;