Skip to content

Commit

Permalink
feat: Add checkbox to show standard error
Browse files Browse the repository at this point in the history
defaultChecked on Checkbox was not used
  • Loading branch information
ptbrowne committed Feb 17, 2022
1 parent bc3a1b8 commit 3a48824
Show file tree
Hide file tree
Showing 11 changed files with 467 additions and 391 deletions.
16 changes: 13 additions & 3 deletions app/charts/chart-config-ui-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ export type EncodingOption =
| "chartSubType"
| "sorting"
| "color"
| "imputationType";
| "imputationType"
| "showStandardError";

export type EncodingOptions =
| undefined
| {
field: EncodingOption;
values: string[] | { field: string; values?: string | string[] }[];
values:
| string[]
| boolean[]
| { field: string; values?: string | string[] }[];
}[];
export type EncodingSortingOption = {
sortingType: "byDimensionLabel" | "byTotalSize" | "byMeasure";
Expand Down Expand Up @@ -70,7 +74,13 @@ export const chartConfigOptionsUISpec: ChartSpecs = {
column: {
chartType: "column",
encodings: [
{ field: "y", optional: false, values: ["Measure"], filters: false },
{
field: "y",
optional: false,
values: ["Measure"],
filters: false,
options: [{ field: "showStandardError", values: [true, false] }],
},
{
field: "x",
optional: false,
Expand Down
6 changes: 5 additions & 1 deletion app/charts/column/columns-grouped-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ScaleTime,
sum,
} from "d3";
import { sortBy } from "lodash";
import { get, sortBy } from "lodash";
import React, { ReactNode, useMemo } from "react";
import { ColumnFields, SortingOrder, SortingType } from "../../configurator";
import {
Expand Down Expand Up @@ -73,6 +73,7 @@ export interface GroupedColumnsState {
yAxisLabel: string;
grouped: [string, Observation[]][];
getAnnotationInfo: (d: Observation) => TooltipInfo;
showStandardError: boolean;
}

const useGroupedColumnsState = (
Expand Down Expand Up @@ -113,6 +114,8 @@ const useGroupedColumnsState = (
const getYErrorRange = useErrorRange(errorMeasure, getY);
const getSegment = useSegment(fields.segment?.componentIri);

const showStandardError = get(fields, ["y", "showStandardError"], true);

// Sort
const xSortingType = fields.x.sorting?.sortingType;
const xSortingOrder = fields.x.sorting?.sortingOrder;
Expand Down Expand Up @@ -417,6 +420,7 @@ const useGroupedColumnsState = (
grouped,
getAnnotationInfo,
xIsTime,
showStandardError,
};
};

Expand Down
3 changes: 2 additions & 1 deletion app/charts/column/columns-grouped.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ export const ErrorWhiskers = () => {
yScale,
getSegment,
grouped,
showStandardError,
} = useChartState() as GroupedColumnsState;
const { margins } = bounds;
if (!getYErrorRange) {
if (!getYErrorRange || !showStandardError) {
return null;
}

Expand Down
12 changes: 9 additions & 3 deletions app/charts/column/columns-simple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import { Column } from "./rendering-utils";

export const ErrorWhiskers = () => {
const state = useChartState() as ColumnsState;

const { getX, getYErrorRange, preparedData, yScale, xScale } = state;
const {
getX,
getYErrorRange,
preparedData,
yScale,
xScale,
showStandardError,
} = state;
const { margins } = state.bounds;

if (!getYErrorRange) {
if (!getYErrorRange || !showStandardError) {
return null;
}

Expand Down
5 changes: 4 additions & 1 deletion app/charts/column/columns-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
scaleTime,
ScaleTime,
} from "d3";
import { sortBy } from "lodash";
import { get, sortBy } from "lodash";
import { ReactNode, useMemo } from "react";
import { ColumnFields, SortingOrder, SortingType } from "../../configurator";
import {
Expand Down Expand Up @@ -70,6 +70,7 @@ export interface ColumnsState {
colors: ScaleOrdinal<string, string>;
yAxisLabel: string;
getAnnotationInfo: (d: Observation) => TooltipInfo;
showStandardError: boolean;
}

const useColumnsState = (
Expand Down Expand Up @@ -114,6 +115,7 @@ const useColumnsState = (
const getYErrorRange = useErrorRange(errorMeasure, getY);
const getYError = useErrorVariable(errorMeasure);
const getSegment = useSegment(fields.segment?.componentIri);
const showStandardError = get(fields, ["y", "showStandardError"], true);

const sortingType = fields.x.sorting?.sortingType;
const sortingOrder = fields.x.sorting?.sortingOrder;
Expand Down Expand Up @@ -302,6 +304,7 @@ const useColumnsState = (
segments,
colors,
getAnnotationInfo,
showStandardError,
};
};

Expand Down
23 changes: 22 additions & 1 deletion app/configurator/components/chart-options-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ import {
SectionTitle,
} from "./chart-controls/section";
import { EmptyRightPanel } from "./empty-right-panel";
import { ChartFieldField, ChartOptionRadioField } from "./field";
import {
ChartFieldField,
ChartOptionRadioField,
ChartOptionCheckboxField,
} from "./field";
import { DimensionValuesMultiFilter, TimeFilter } from "./filters";
import { getFieldLabel, getIconName } from "./ui-helpers";

Expand Down Expand Up @@ -266,6 +270,23 @@ const EncodingOptionsPanel = ({
// chartType={chartType}
/>
)}
{optionsByField["showStandardError"] && (
<ControlSection>
<SectionTitle iconName="eye">
<Trans id="controls.section.additional-information">
Show additional information
</Trans>
</SectionTitle>
<ControlSectionContent side="right" as="fieldset">
<ChartOptionCheckboxField
path="showStandardError"
field={encoding.field}
defaultValue={true}
label={t({ id: "controls.section.show-standard-error" })}
/>
</ControlSectionContent>
</ControlSection>
)}
{optionsByField["imputationType"] && isAreaConfig(state.chartConfig) && (
<ChartImputationType state={state} disabled={!imputationNeeded} />
)}
Expand Down
7 changes: 4 additions & 3 deletions app/configurator/components/field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -736,26 +736,27 @@ export const ChartOptionCheckboxField = ({
label,
field,
path,
defaultChecked,
defaultValue = false,
disabled = false,
}: {
label: string;
field: string | null;
path: string;
defaultChecked?: boolean;
defaultValue?: boolean;
disabled?: boolean;
}) => {
const fieldProps = useChartOptionBooleanField({
field,
path,
defaultValue,
});

return (
<Checkbox
disabled={disabled}
label={label}
{...fieldProps}
checked={fieldProps.checked ?? defaultChecked}
checked={fieldProps.checked ?? defaultValue}
></Checkbox>
);
};
Expand Down
Loading

0 comments on commit 3a48824

Please sign in to comment.