Skip to content

Commit

Permalink
feat: Support percentage unit for standard error column
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne committed Feb 16, 2022
1 parent 01e8644 commit 1e34744
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions app/charts/column/columns-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,23 @@ const useColumnsState = ({
const getX = useStringVariable(fields.x.componentIri);
const getXAsDate = useTemporalVariable(fields.x.componentIri);
const getY = useOptionalNumericVariable(fields.y.componentIri);
const errorIri = useMemo(() => {
const yMeasure = measures.find((m) => m.iri === fields.y.componentIri);
return yMeasure?.related?.errorIri;
}, [fields.y.componentIri, measures]);
const errorMeasure = useMemo(() => {
return [...measures, ...dimensions].find((m) => {
return m.related?.some(
(r) => r.type === "StandardError" && r.iri === fields.y.componentIri
);
});
}, [dimensions, fields.y.componentIri, measures]);
const getSegment = useSegment(fields.segment?.componentIri);
const getYError = errorIri
const getYError = errorMeasure
? (d: Observation) => {
const y = getY(d) as number;
const error =
const errorIri = errorMeasure.iri;
let error =
d[errorIri] !== null ? parseFloat(d[errorIri] as string) : null;
if (errorMeasure.unit === "%" && error !== null) {
error = (error * y) / 100;
}
return (error === null ? [y, y] : [y - error, y + error]) as [
number,
number
Expand Down

0 comments on commit 1e34744

Please sign in to comment.