-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat(experiments): add delta timeseries chart UI #27960
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f7e77e4
init
jurajmajerik 220de8d
Update UI snapshots for `chromium` (2)
github-actions[bot] 62fab3a
fix
jurajmajerik 4837bdf
Merge branch 'experiments-timeseries-chart-ui' of https://github.com/…
jurajmajerik ecbc48a
Update UI snapshots for `chromium` (2)
github-actions[bot] 886f367
Update UI snapshots for `chromium` (2)
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
151 changes: 151 additions & 0 deletions
151
frontend/src/scenes/experiments/MetricsView/VariantDeltaTimeseries.tsx
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 |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import { Chart, ChartConfiguration } from 'chart.js/auto' | ||
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. It would be nice to have a storybook for this (at some point in the future) that includes the various permutations of data (zero days, one day, 100 days) |
||
import { useActions, useValues } from 'kea' | ||
import { LemonButton } from 'lib/lemon-ui/LemonButton' | ||
import { LemonModal } from 'lib/lemon-ui/LemonModal' | ||
import { useEffect } from 'react' | ||
|
||
import { experimentLogic } from '../experimentLogic' | ||
|
||
const DELTA = [0.16, 0.17, 0.15, 0.16, 0.14, 0.15, 0.145, 0.15, 0.155, 0.148, 0.15, 0.147, 0.152, 0.15] | ||
const UPPER_BOUND = [0.26, 0.27, 0.24, 0.24, 0.21, 0.21, 0.2, 0.2, 0.195, 0.183, 0.182, 0.177, 0.182, 0.18] | ||
const LOWER_BOUND = [0.06, 0.07, 0.06, 0.08, 0.07, 0.09, 0.09, 0.1, 0.115, 0.113, 0.118, 0.117, 0.122, 0.12] | ||
|
||
export const VariantDeltaTimeseries = (): JSX.Element => { | ||
const { closeVariantDeltaTimeseriesModal } = useActions(experimentLogic) | ||
const { isVariantDeltaTimeseriesModalOpen } = useValues(experimentLogic) | ||
|
||
useEffect(() => { | ||
if (isVariantDeltaTimeseriesModalOpen) { | ||
setTimeout(() => { | ||
const ctx = document.getElementById('variantDeltaChart') as HTMLCanvasElement | ||
if (!ctx) { | ||
console.error('Canvas element not found') | ||
return | ||
} | ||
|
||
const existingChart = Chart.getChart(ctx) | ||
if (existingChart) { | ||
existingChart.destroy() | ||
} | ||
|
||
ctx.style.width = '100%' | ||
ctx.style.height = '100%' | ||
|
||
const data = { | ||
labels: [ | ||
'Day 1', | ||
'Day 2', | ||
'Day 3', | ||
'Day 4', | ||
'Day 5', | ||
'Day 6', | ||
'Day 7', | ||
'Day 8', | ||
'Day 9', | ||
'Day 10', | ||
'Day 11', | ||
'Day 12', | ||
'Day 13', | ||
'Day 14', | ||
], | ||
datasets: [ | ||
{ | ||
label: 'Upper Bound', | ||
data: UPPER_BOUND, | ||
borderColor: 'rgba(200, 200, 200, 1)', | ||
fill: false, | ||
tension: 0, | ||
pointRadius: 0, | ||
}, | ||
{ | ||
label: 'Lower Bound', | ||
data: LOWER_BOUND, | ||
borderColor: 'rgba(200, 200, 200, 1)', | ||
fill: '-1', | ||
backgroundColor: 'rgba(200, 200, 200, 0.2)', | ||
tension: 0, | ||
pointRadius: 0, | ||
}, | ||
{ | ||
label: 'Delta', | ||
data: DELTA, | ||
borderColor: 'rgba(0, 100, 255, 1)', | ||
borderWidth: 2, | ||
fill: false, | ||
tension: 0, | ||
pointRadius: 0, | ||
}, | ||
], | ||
} | ||
|
||
const config: ChartConfiguration = { | ||
type: 'line', | ||
data: data, | ||
options: { | ||
responsive: true, | ||
maintainAspectRatio: false, | ||
interaction: { | ||
intersect: false, | ||
mode: 'nearest', | ||
axis: 'x', | ||
}, | ||
scales: { | ||
y: { | ||
beginAtZero: true, | ||
grid: { | ||
display: false, | ||
}, | ||
ticks: { | ||
count: 6, | ||
callback: (value) => `${(Number(value) * 100).toFixed(1)}%`, | ||
}, | ||
}, | ||
}, | ||
plugins: { | ||
legend: { | ||
display: false, | ||
}, | ||
tooltip: { | ||
callbacks: { | ||
labelPointStyle: function () { | ||
return { | ||
pointStyle: 'circle', | ||
rotation: 0, | ||
} | ||
}, | ||
}, | ||
usePointStyle: true, | ||
boxWidth: 16, | ||
boxHeight: 1, | ||
}, | ||
// @ts-expect-error Types of library are out of date | ||
crosshair: false, | ||
}, | ||
}, | ||
} | ||
|
||
new Chart(ctx, config) | ||
}, 0) | ||
} | ||
}, [isVariantDeltaTimeseriesModalOpen]) | ||
|
||
return ( | ||
<LemonModal | ||
isOpen={isVariantDeltaTimeseriesModalOpen} | ||
onClose={() => { | ||
closeVariantDeltaTimeseriesModal() | ||
}} | ||
width={800} | ||
title="Variant performance over time" | ||
footer={ | ||
<LemonButton form="secondary-metric-modal-form" type="secondary" onClick={() => {}}> | ||
Close | ||
</LemonButton> | ||
} | ||
> | ||
<div className="relative h-[400px]"> | ||
<canvas id="variantDeltaChart" /> | ||
</div> | ||
</LemonModal> | ||
) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not intuitive to me that hovering produces one UI and clicking produces another UI. Not a blocker, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, can adjust later 👍