-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,399 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import { Span } from "../connection/monitor"; | ||
|
||
export function flattenChildren(objects: Span[]): Span[] { | ||
let result: Span[] = []; | ||
let result: Span[] = []; | ||
|
||
objects.forEach(obj => { | ||
const children = obj.children ?? []; | ||
const currentObj = { ...obj } | ||
currentObj.children = []; | ||
result.push(currentObj); | ||
objects.forEach((obj) => { | ||
const children = obj.children ?? []; | ||
const currentObj = { ...obj }; | ||
currentObj.children = []; | ||
result.push(currentObj); | ||
|
||
if (children) { | ||
result = result.concat(flattenChildren(children)); | ||
} | ||
}); | ||
if (children) { | ||
result = result.concat(flattenChildren(children)); | ||
} | ||
}); | ||
|
||
return result; | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import type { SortDirection, SortableColumn, ColumnSort } from "~/views/dashboard/span-waterfall"; | ||
import type { | ||
SortDirection, | ||
SortableColumn, | ||
ColumnSort, | ||
} from "~/views/dashboard/span-waterfall"; | ||
|
||
export function getColumnDirection(columnSort: ColumnSort, name: SortableColumn): SortDirection { | ||
if (columnSort.name === name) { | ||
if (columnSort.direction === "asc") return "desc" | ||
return "asc" | ||
} | ||
export function getColumnDirection( | ||
columnSort: ColumnSort, | ||
name: SortableColumn | ||
): SortDirection { | ||
if (columnSort.name === name) { | ||
if (columnSort.direction === "asc") return "desc"; | ||
return "asc"; | ||
} | ||
|
||
return "asc" | ||
} | ||
return "asc"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,44 @@ | ||
import { Span } from "../connection/monitor"; | ||
|
||
function scaleNumbers(numbers: number[], min: number, max: number): number[] { | ||
const range = max - min; | ||
return numbers.map(num => ((num - min) / range) * 100).map(num => Math.max(0, Math.min(num, 100))); | ||
const range = max - min; | ||
return numbers | ||
.map((num) => ((num - min) / range) * 100) | ||
.map((num) => Math.max(0, Math.min(num, 100))); | ||
} | ||
|
||
function scaleToMax(numbers: number[], max: number): number[] { | ||
return numbers.map(num => (num / max) * 100); | ||
return numbers.map((num) => (num / max) * 100); | ||
} | ||
|
||
export function normalizeSpans(spans: Span[]) { | ||
const start = Math.min(...spans.map(span => span.createdAt)); | ||
const end = Math.max(...spans.filter(s => s.closedAt > 0).map(span => span.closedAt)); | ||
const totalDuration = end - start; | ||
const start = Math.min(...spans.map((span) => span.createdAt)); | ||
const end = Math.max( | ||
...spans.filter((s) => s.closedAt > 0).map((span) => span.closedAt) | ||
); | ||
const totalDuration = end - start; | ||
|
||
const result = spans.map(span => { | ||
const allExits = span.exits.reduce((acc, e) => acc + e, 0); | ||
const allEnters = span.enters.reduce((acc, e) => acc + e, 0); | ||
const result = spans.map((span) => { | ||
const allExits = span.exits.reduce((acc, e) => acc + e, 0); | ||
const allEnters = span.enters.reduce((acc, e) => acc + e, 0); | ||
return { | ||
width: scaleToMax([span.duration], totalDuration)[0], | ||
marginLeft: scaleNumbers([span.createdAt], start, end)[0], | ||
slices: span.enters.map((enter, i) => { | ||
const width = scaleToMax( | ||
[span.exits[i] - enter], | ||
allExits - allEnters | ||
)[0]; | ||
const offset = scaleNumbers([enter], span.createdAt, span.closedAt)[0]; | ||
const marginLeft = offset - (offset * width) / 100; | ||
return { | ||
width: scaleToMax([span.duration], totalDuration)[0], | ||
marginLeft: scaleNumbers([span.createdAt], start, end)[0], | ||
slices: span.enters.map((enter, i) => { | ||
const width = scaleToMax([span.exits[i] - enter], allExits - allEnters)[0]; | ||
const offset = scaleNumbers([enter], span.createdAt, span.closedAt)[0]; | ||
const marginLeft = offset - (offset * width / 100); | ||
return { | ||
width, | ||
marginLeft | ||
} | ||
}) | ||
} | ||
}) | ||
width, | ||
marginLeft, | ||
}; | ||
}), | ||
}; | ||
}); | ||
|
||
const newSpans = spans.map((s, i) => ({ ...s, ...result[i] })) | ||
return newSpans; | ||
const newSpans = spans.map((s, i) => ({ ...s, ...result[i] })); | ||
return newSpans; | ||
} |
Oops, something went wrong.