Skip to content

Commit

Permalink
feat(components): gs-prevalence-over-time: don't show confidence inte…
Browse files Browse the repository at this point in the history
…rval by default, explicitly require 'none' as `confidenceIntervalMethods` to show it (#542)

BREAKING CHANGE: pass `['wilson', 'none']` instead of `['wilson']` to `confidenceIntervalMethods` of `gs-prevalence-over-time` to achieve the same behavior as before

resolves #537
  • Loading branch information
fengelniederhammer authored Nov 25, 2024
1 parent 08d0be3 commit b68dfb3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const ConfidenceIntervalSelector: FunctionComponent<ConfidenceIntervalSel

const items = [
{ label: 'Confidence interval method', value: 'none', disabled: true },
...confidenceIntervalMethods.concat('none').map((method) => {
...confidenceIntervalMethods.map((method) => {
switch (method) {
case 'wilson':
return { label: 'Wilson, 95% CI', value: 'wilson' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default {
control: { type: 'check' },
},
confidenceIntervalMethods: {
options: ['wilson'],
options: ['none', 'wilson'],
control: { type: 'check' },
},
width: { control: 'text' },
Expand Down Expand Up @@ -73,7 +73,7 @@ export const TwoVariants: StoryObj<PrevalenceOverTimeProps> = {
granularity: 'month',
smoothingWindow: 0,
views: ['bar', 'line', 'bubble', 'table'],
confidenceIntervalMethods: ['wilson'],
confidenceIntervalMethods: ['none', 'wilson'],
width: '100%',
height: '700px',
lapisDateField: 'date',
Expand Down Expand Up @@ -147,7 +147,7 @@ export const OneVariant: StoryObj<PrevalenceOverTimeProps> = {
granularity: 'day',
smoothingWindow: 7,
views: ['bar', 'line', 'bubble', 'table'],
confidenceIntervalMethods: ['wilson'],
confidenceIntervalMethods: ['none', 'wilson'],
width: '100%',
height: '700px',
lapisDateField: 'date',
Expand Down Expand Up @@ -205,7 +205,7 @@ export const ShowsNoDataBanner: StoryObj<PrevalenceOverTimeProps> = {
granularity: 'day',
smoothingWindow: 7,
views: ['bar', 'line', 'bubble', 'table'],
confidenceIntervalMethods: ['wilson'],
confidenceIntervalMethods: ['none', 'wilson'],
width: '100%',
height: '700px',
lapisDateField: 'date',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type FunctionComponent } from 'preact';
import { useContext, useState } from 'preact/hooks';
import { useContext, useEffect, useState } from 'preact/hooks';

import { getPrevalenceOverTimeTableData } from './getPrevalenceOverTimeTableData';
import PrevalenceOverTimeBarChart from './prevalence-over-time-bar-chart';
Expand Down Expand Up @@ -97,6 +97,16 @@ const PrevalenceOverTimeTabs: FunctionComponent<PrevalenceOverTimeTabsProps> = (
const [confidenceIntervalMethod, setConfidenceIntervalMethod] = useState<ConfidenceIntervalMethod>(
confidenceIntervalMethods.length > 0 ? confidenceIntervalMethods[0] : 'none',
);

useEffect(() => {
setConfidenceIntervalMethod((confidenceIntervalMethod) => {
if (!confidenceIntervalMethods.includes(confidenceIntervalMethod)) {
return confidenceIntervalMethods.length > 0 ? confidenceIntervalMethods[0] : 'none';
}
return confidenceIntervalMethod;
});
}, [confidenceIntervalMethods]);

const yAxisMaxConfig = { linear: yAxisMaxLinear, logarithmic: yAxisMaxLogarithmic };

const getTab = (view: View) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const meta: Meta<Required<PrevalenceOverTimeProps>> = {
control: { type: 'check' },
},
confidenceIntervalMethods: {
options: ['wilson'],
options: ['none', 'wilson'],
control: { type: 'check' },
},
width: { control: 'text' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ export class PrevalenceOverTimeComponent extends PreactLitAdapterWithGridJsStyle

/**
* A list of methods to calculate the confidence interval.
* The option `none` is always available and disables confidence intervals.
* Pass an empty array to disable the confidence interval selector.
* The first entry will be selected by default.
*/
@property({ type: Array })
confidenceIntervalMethods: ('wilson' | 'none')[] = ['wilson'];
confidenceIntervalMethods: ('wilson' | 'none')[] = ['none', 'wilson'];

/**
* The width of the component.
Expand Down

0 comments on commit b68dfb3

Please sign in to comment.