Skip to content

Commit a3fc6e5

Browse files
committed
feat: Add a way to enable confidence intervals
1 parent 9089fd0 commit a3fc6e5

File tree

7 files changed

+93
-2
lines changed

7 files changed

+93
-2
lines changed

app/charts/chart-config-ui-options.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ type EncodingOption<T extends ChartConfig = ChartConfig> =
111111
| {
112112
field: "showStandardError";
113113
}
114+
| {
115+
field: "showConfidenceInterval";
116+
}
114117
| {
115118
field: "sorting";
116119
}
@@ -643,6 +646,7 @@ const chartConfigOptionsUISpec: ChartSpecs = {
643646
},
644647
options: {
645648
showStandardError: {},
649+
showConfidenceInterval: {},
646650
},
647651
},
648652
{
@@ -776,6 +780,7 @@ const chartConfigOptionsUISpec: ChartSpecs = {
776780
filters: false,
777781
options: {
778782
showStandardError: {},
783+
showConfidenceInterval: {},
779784
},
780785
},
781786
{

app/config-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ export type ColumnSegmentField = t.TypeOf<typeof ColumnSegmentField>;
287287

288288
const UncertaintyFieldExtension = t.partial({
289289
showStandardError: t.boolean,
290+
showConfidenceInterval: t.boolean,
290291
});
291292
export type UncertaintyFieldExtension = t.TypeOf<
292293
typeof UncertaintyFieldExtension

app/configurator/components/chart-options-selector.tsx

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,28 @@ const EncodingOptionsPanel = ({
389389
}, [components, fields, encoding.field]);
390390

391391
const hasStandardError = useMemo(() => {
392-
return components.find((d) =>
392+
return !!components.find((d) =>
393393
d.related?.some(
394394
(r) => r.type === "StandardError" && r.id === component?.id
395395
)
396396
);
397397
}, [components, component]);
398398

399+
const hasConfidenceInterval = useMemo(() => {
400+
const upperBoundComponent = components.find((d) =>
401+
d.related?.some(
402+
(r) => r.type === "ConfidenceUpperBound" && r.id === component?.id
403+
)
404+
);
405+
const lowerBoundComponent = components.find((d) =>
406+
d.related?.some(
407+
(r) => r.type === "ConfidenceLowerBound" && r.id === component?.id
408+
)
409+
);
410+
411+
return !!upperBoundComponent && !!lowerBoundComponent;
412+
}, [components, component]);
413+
399414
const hasColorPalette = !!encoding.options?.colorPalette;
400415

401416
const hasSubOptions =
@@ -436,7 +451,7 @@ const EncodingOptionsPanel = ({
436451
<ChartOptionSwitchField
437452
path="showStandardError"
438453
field={encoding.field}
439-
defaultValue={true}
454+
defaultValue
440455
label={t({ id: "controls.section.show-standard-error" })}
441456
sx={{ marginRight: 0 }}
442457
/>
@@ -456,6 +471,41 @@ const EncodingOptionsPanel = ({
456471
/>
457472
</Box>
458473
)}
474+
{encoding.options?.showConfidenceInterval &&
475+
hasConfidenceInterval && (
476+
<Box
477+
sx={{
478+
display: "flex",
479+
gap: 1,
480+
alignItems: "center",
481+
mt: 3,
482+
}}
483+
>
484+
<ChartOptionSwitchField
485+
path="showConfidenceInterval"
486+
field={encoding.field}
487+
defaultValue
488+
label={t({
489+
id: "controls.section.show-confidence-interval",
490+
})}
491+
sx={{ marginRight: 0 }}
492+
/>
493+
<InfoIconTooltip
494+
enterDelay={600}
495+
PopperProps={{ sx: { maxWidth: 160 } }}
496+
title={
497+
<TooltipTitle
498+
text={
499+
<Trans id="controls.section.show-confidence-interval.explanation">
500+
Show uncertainties extending from data points to
501+
represent confidence intervals
502+
</Trans>
503+
}
504+
/>
505+
}
506+
/>
507+
</Box>
508+
)}
459509
{encoding.options?.useAbbreviations && (
460510
<ControlSectionContent
461511
component="fieldset"

app/locales/de/messages.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ msgstr "Es ist mindestens eine numerische Massnahme erforderlich."
411411
msgid "controls.chart.disabled.same-unit"
412412
msgstr "Es sind mindestens zwei Zahlenwerte mit gleicher Einheit erforderlich."
413413

414+
#: app/charts/index.ts
414415
#: app/charts/index.ts
415416
msgid "controls.chart.disabled.temporal"
416417
msgstr "Es ist mindestens eine zeitliche Dimension erforderlich."
@@ -888,6 +889,14 @@ msgstr "Geteilte Filter"
888889
msgid "controls.section.shared-filters.date"
889890
msgstr "Datum"
890891

892+
#: app/configurator/components/chart-options-selector.tsx
893+
msgid "controls.section.show-confidence-interval"
894+
msgstr "Konfidenzintervall anzeigen"
895+
896+
#: app/configurator/components/chart-options-selector.tsx
897+
msgid "controls.section.show-confidence-interval.explanation"
898+
msgstr "Zeigen Sie Unsicherheiten an, die sich aus Datenpunkten ergeben, um Konfidenzintervalle darzustellen"
899+
891900
#: app/configurator/components/chart-options-selector.tsx
892901
msgid "controls.section.show-standard-error"
893902
msgstr "Standardfehler anzeigen"

app/locales/en/messages.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ msgstr "At least one numerical measure is required."
411411
msgid "controls.chart.disabled.same-unit"
412412
msgstr "At least two numerical measures with the same unit are required."
413413

414+
#: app/charts/index.ts
414415
#: app/charts/index.ts
415416
msgid "controls.chart.disabled.temporal"
416417
msgstr "At least one temporal dimension is required."
@@ -888,6 +889,14 @@ msgstr "Shared filters"
888889
msgid "controls.section.shared-filters.date"
889890
msgstr "Date"
890891

892+
#: app/configurator/components/chart-options-selector.tsx
893+
msgid "controls.section.show-confidence-interval"
894+
msgstr "Show confidence interval"
895+
896+
#: app/configurator/components/chart-options-selector.tsx
897+
msgid "controls.section.show-confidence-interval.explanation"
898+
msgstr "Show uncertainties extending from data points to represent confidence intervals"
899+
891900
#: app/configurator/components/chart-options-selector.tsx
892901
msgid "controls.section.show-standard-error"
893902
msgstr "Show standard error"

app/locales/fr/messages.po

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,14 @@ msgstr "Filtres partagés"
889889
msgid "controls.section.shared-filters.date"
890890
msgstr "Date"
891891

892+
#: app/configurator/components/chart-options-selector.tsx
893+
msgid "controls.section.show-confidence-interval"
894+
msgstr "Afficher l'intervalle de confiance"
895+
896+
#: app/configurator/components/chart-options-selector.tsx
897+
msgid "controls.section.show-confidence-interval.explanation"
898+
msgstr "Afficher les incertitudes s'étendant des points de données pour représenter les intervalles de confiance"
899+
892900
#: app/configurator/components/chart-options-selector.tsx
893901
msgid "controls.section.show-standard-error"
894902
msgstr "Afficher l'erreur type"

app/locales/it/messages.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ msgstr "È richiesta almeno una misura numerica."
411411
msgid "controls.chart.disabled.same-unit"
412412
msgstr "Sono necessarie almeno due misure numeriche con la stessa unità."
413413

414+
#: app/charts/index.ts
414415
#: app/charts/index.ts
415416
msgid "controls.chart.disabled.temporal"
416417
msgstr "È richiesta almeno una dimensione temporale."
@@ -888,6 +889,14 @@ msgstr "Filtri condivisi"
888889
msgid "controls.section.shared-filters.date"
889890
msgstr "Data"
890891

892+
#: app/configurator/components/chart-options-selector.tsx
893+
msgid "controls.section.show-confidence-interval"
894+
msgstr "Mostra intervallo di confidenza"
895+
896+
#: app/configurator/components/chart-options-selector.tsx
897+
msgid "controls.section.show-confidence-interval.explanation"
898+
msgstr "Mostra le incertezze che si estendono dai punti dati per rappresentare gli intervalli di confidenza"
899+
891900
#: app/configurator/components/chart-options-selector.tsx
892901
msgid "controls.section.show-standard-error"
893902
msgstr "Mostra l'errore standard"

0 commit comments

Comments
 (0)