-
Notifications
You must be signed in to change notification settings - Fork 5
Fixes to the session captures timeline data #499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
532d0c6
8e24081
5a1f3ff
d0eb070
e2a1694
1595dc4
4742b48
c99dbc8
4407f93
3453ec5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ const lineColorDetections = '#5f8ac6' | |
const textColor = '#222426' | ||
const tooltipBgColor = '#ffffff' | ||
const tooltipBorderColor = '#222426' | ||
const gridLineColor = '#f36399' | ||
|
||
export const ActivityPlot = ({ | ||
session, | ||
|
@@ -22,14 +23,30 @@ export const ActivityPlot = ({ | |
}) => { | ||
const containerRef = useRef(null) | ||
const width = useDynamicPlotWidth(containerRef) | ||
|
||
// Calculate the average number of captures | ||
const avgCaptures = | ||
timeline.reduce((sum, tick) => sum + tick.numCaptures, 0) / timeline.length | ||
|
||
// Calculate the maximum deviation from the average | ||
const maxDeviation = Math.max( | ||
...timeline.map((tick) => Math.abs(tick.numCaptures - avgCaptures)) | ||
) | ||
|
||
// Set the y-axis range to be centered around the average | ||
const yAxisMin = Math.max(0, avgCaptures - maxDeviation) | ||
const yAxisMax = avgCaptures + maxDeviation | ||
|
||
return ( | ||
<div style={{ margin: '0 14px -10px' }}> | ||
<div ref={containerRef}> | ||
<Plot | ||
style={{ display: 'block' }} | ||
data={[ | ||
{ | ||
x: timeline.map((timelineTick) => timelineTick.startDate), | ||
x: timeline.map( | ||
(timelineTick) => new Date(timelineTick.startDate) | ||
), | ||
y: timeline.map((timelineTick) => timelineTick.numCaptures), | ||
text: timeline.map((timelineTick) => timelineTick.tooltip), | ||
hovertemplate: '%{text}<extra></extra>', | ||
|
@@ -38,17 +55,21 @@ export const ActivityPlot = ({ | |
mode: 'lines', | ||
line: { color: lineColorCaptures, width: 1 }, | ||
name: 'Captures', | ||
yaxis: 'y', | ||
}, | ||
{ | ||
x: timeline.map((timelineTick) => timelineTick.startDate), | ||
y: timeline.map((timelineTick) => timelineTick.numDetections), | ||
x: timeline.map( | ||
(timelineTick) => new Date(timelineTick.startDate) | ||
), | ||
y: timeline.map((timelineTick) => timelineTick.avgDetections), | ||
text: timeline.map((timelineTick) => timelineTick.tooltip), | ||
hovertemplate: '%{text}<extra></extra>', | ||
fill: 'tozeroy', | ||
type: 'scatter', | ||
mode: 'lines', | ||
line: { color: lineColorDetections, width: 1 }, | ||
name: 'Detections', | ||
name: 'Avg. Detections', | ||
yaxis: 'y2', | ||
}, | ||
]} | ||
layout={{ | ||
|
@@ -69,14 +90,30 @@ export const ActivityPlot = ({ | |
zeroline: false, | ||
rangemode: 'nonnegative', | ||
fixedrange: true, | ||
range: [yAxisMin, yAxisMax], | ||
side: 'left', | ||
}, | ||
xaxis: { | ||
showline: true, | ||
yaxis2: { | ||
showgrid: false, | ||
showticklabels: false, | ||
zeroline: false, | ||
rangemode: 'nonnegative', | ||
fixedrange: true, | ||
range: [0, session.detectionsMaxCount], | ||
mihow marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
side: 'right', | ||
overlaying: 'y', | ||
}, | ||
xaxis: { | ||
showline: false, | ||
showgrid: true, | ||
griddash: 'dot', | ||
gridwidth: 1, | ||
gridcolor: gridLineColor, | ||
showticklabels: false, | ||
zeroline: false, | ||
fixedrange: true, | ||
range: [session.startDate, session.endDate], | ||
range: [new Date(session.startDate), new Date(session.endDate)], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, I was experimenting with date formats was trying different approaches. Reverting! |
||
dtick: 3600000, // milliseconds in an hour | ||
}, | ||
hoverlabel: { | ||
bgcolor: tooltipBgColor, | ||
|
@@ -95,8 +132,8 @@ export const ActivityPlot = ({ | |
onClick={(data) => { | ||
const timelineTickIndex = data.points[0].pointIndex | ||
const timelineTick = timeline[timelineTickIndex] | ||
if (timelineTick?.firstCaptureId) { | ||
setActiveCaptureId(timelineTick.firstCaptureId) | ||
if (timelineTick?.representativeCaptureId) { | ||
setActiveCaptureId(timelineTick.representativeCaptureId) | ||
} | ||
}} | ||
/> | ||
|
Uh oh!
There was an error while loading. Please reload this page.