-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [#186948671] Feature: The user can cause a normal curve to be drawn on top of a dot plot This is the first portion of work on a normal curve. It covers display of normal curve on dot plots. Remaining is display of normal curve on histograms and gaussian fit curves on histograms when there exists a URL parameter for gaussianFit and code for fitting to histograms brought in from V2. * Start by modifying standard error adornment * The normal-curve-adornment-component.tsx file contains code that is redundant with the standard-error-adornment-component.tsx file. Presumably there is a way to decrease the redundancy, perhaps by making `useAdornmentAttributes` or some similar hook. But we're not making that attempt now. * The `NormalCurveAdornmentModel` has no real state of its own. Its purpose is to compute mean, standard deviation and standard error for each cell in which we draw the curve. I decided to put `getCaseCount` in `UnivariateMeasureAdornmentModel` even though it's only so far used for the normal curve. * It proved necessary to store the point overlap in `GraphContentModel` so that the normal curve adornment could access it and use it for computing coordinates. * `en-US.json5` was out of date compared to the most recent V2 counterpart * Comment out portions of code that refer to standard error since we won't be displaying that until we have histograms that display a Gaussian Fit curve instead of a normal curve * In cleaning up existing elements of measure adornments, test for undefined * Modified `v2-adornment-importer.test.ts` to expect 10 adornments * chore: code review tweaks * * Code review changes --------- Co-authored-by: Kirk Swenson <[email protected]>
- Loading branch information
Showing
21 changed files
with
932 additions
and
355 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
358 changes: 358 additions & 0 deletions
358
...ts/graph/adornments/univariate-measures/normal-curve/normal-curve-adornment-component.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
...ts/graph/adornments/univariate-measures/normal-curve/normal-curve-adornment-model.test.ts
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,30 @@ | ||
import { NormalCurveAdornmentModel } from "./normal-curve-adornment-model" | ||
import { kNormalCurveType } from "./normal-curve-adornment-types" | ||
|
||
describe("NormalCurveModel", () => { | ||
it("can be created", () => { | ||
const mean = NormalCurveAdornmentModel.create() | ||
expect(mean).toBeDefined() | ||
expect(mean.type).toEqual(kNormalCurveType) | ||
}) | ||
it("can have its showLabels property set", () => { | ||
const mean = NormalCurveAdornmentModel.create() | ||
expect(mean.showMeasureLabels).toBe(false) | ||
mean.setShowMeasureLabels(true) | ||
expect(mean.showMeasureLabels).toBe(true) | ||
}) | ||
it("can have a new normal curve added to its measures map", () => { | ||
const adornment = NormalCurveAdornmentModel.create() | ||
expect(adornment.measures.size).toBe(0) | ||
adornment.addMeasure(10) | ||
expect(adornment.measures.size).toBe(1) | ||
}) | ||
it("can have an existing normal curve removed from its measures map", () => { | ||
const adornment = NormalCurveAdornmentModel.create() | ||
expect(adornment.measures.size).toBe(0) | ||
adornment.addMeasure(10) | ||
expect(adornment.measures.size).toBe(1) | ||
adornment.removeMeasure("{}") | ||
expect(adornment.measures.size).toBe(0) | ||
}) | ||
}) |
36 changes: 36 additions & 0 deletions
36
...ponents/graph/adornments/univariate-measures/normal-curve/normal-curve-adornment-model.ts
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,36 @@ | ||
import { Instance, types } from "mobx-state-tree" | ||
import { mean, std } from "mathjs" | ||
import {IGraphDataConfigurationModel} from "../../../models/graph-data-configuration-model" | ||
import { UnivariateMeasureAdornmentModel, IUnivariateMeasureAdornmentModel } | ||
from "../univariate-measure-adornment-model" | ||
import { kNormalCurveValueTitleKey, kNormalCurveType } from "./normal-curve-adornment-types" | ||
|
||
export const NormalCurveAdornmentModel = UnivariateMeasureAdornmentModel | ||
.named("NormalCurveAdornmentModel") | ||
.props({ | ||
type: types.optional(types.literal(kNormalCurveType), kNormalCurveType), | ||
labelTitle: types.optional(types.literal(kNormalCurveValueTitleKey), kNormalCurveValueTitleKey), | ||
}) | ||
.views(self => ({ | ||
computeMean(attrId: string, cellKey: Record<string, string>, dataConfig: IGraphDataConfigurationModel) { | ||
return mean(self.getCaseValues(attrId, cellKey, dataConfig)) | ||
}, | ||
computeStandardDeviation(attrId: string, cellKey: Record<string, string>, | ||
dataConfig: IGraphDataConfigurationModel) { | ||
// Cast to Number should not be necessary, but there appears to be an issue with the mathjs type signature. | ||
// See https://github.com/josdejong/mathjs/issues/2429 for some history, although that bug is supposedly | ||
// fixed, but a variant of it seems to be re-occurring. | ||
return Number(std(self.getCaseValues(attrId, cellKey, dataConfig))) | ||
}, | ||
computeStandardError(attrId: string, cellKey: Record<string, string>, | ||
dataConfig: IGraphDataConfigurationModel) { | ||
return this.computeStandardDeviation(attrId, cellKey, dataConfig) / | ||
Math.sqrt(self.getCaseCount(attrId, cellKey, dataConfig)) | ||
}, | ||
})) | ||
|
||
export interface INormalCurveAdornmentModel extends Instance<typeof NormalCurveAdornmentModel> {} | ||
export function isNormalCurveAdornment(adornment: IUnivariateMeasureAdornmentModel): | ||
adornment is INormalCurveAdornmentModel { | ||
return adornment.type === kNormalCurveType | ||
} |
20 changes: 20 additions & 0 deletions
20
...h/adornments/univariate-measures/normal-curve/normal-curve-adornment-registration.test.ts
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,20 @@ | ||
import { getAdornmentComponentInfo } from "../../adornment-component-info" | ||
import { getAdornmentContentInfo } from "../../adornment-content-info" | ||
import { kNormalCurveClass, kNormalCurvePrefix, | ||
kNormalCurveType } from "./normal-curve-adornment-types" | ||
import "./normal-curve-adornment-registration" | ||
|
||
describe("NormalCurveRegistration", () => { | ||
it("registers content and component info", () => { | ||
const standardErrorInfo = getAdornmentContentInfo(kNormalCurveType) | ||
expect(standardErrorInfo).toBeDefined() | ||
expect(standardErrorInfo?.type).toBe(kNormalCurveType) | ||
expect(standardErrorInfo?.modelClass).toBeDefined() | ||
expect(standardErrorInfo?.prefix).toBe(kNormalCurvePrefix) | ||
const standardErrorComponentInfo = getAdornmentComponentInfo(kNormalCurveType) | ||
expect(standardErrorComponentInfo).toBeDefined() | ||
expect(standardErrorComponentInfo?.adornmentEltClass).toBe(kNormalCurveClass) | ||
expect(standardErrorComponentInfo?.Component).toBeDefined() | ||
expect(standardErrorComponentInfo?.type).toBe(kNormalCurveType) | ||
}) | ||
}) |
44 changes: 44 additions & 0 deletions
44
...graph/adornments/univariate-measures/normal-curve/normal-curve-adornment-registration.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,44 @@ | ||
import React from "react" | ||
import { AdornmentCheckbox } from "../../adornment-checkbox" | ||
import { registerAdornmentComponentInfo } from "../../adornment-component-info" | ||
import { registerAdornmentContentInfo } from "../../adornment-content-info" | ||
import { | ||
kNormalCurveClass, kNormalCurveLabelKey, kNormalCurveType, kNormalCurvePrefix, | ||
kNormalCurveUndoAddKey, kNormalCurveRedoAddKey, kNormalCurveRedoRemoveKey, | ||
kNormalCurveUndoRemoveKey | ||
} from "./normal-curve-adornment-types" | ||
import { NormalCurveAdornmentModel } from "./normal-curve-adornment-model" | ||
import { NormalCurveAdornmentComponent } from "./normal-curve-adornment-component" | ||
|
||
const Controls = () => { | ||
return ( | ||
<AdornmentCheckbox | ||
classNameValue={kNormalCurveClass} | ||
labelKey={kNormalCurveLabelKey} | ||
type={kNormalCurveType} | ||
/> | ||
) | ||
} | ||
|
||
registerAdornmentContentInfo({ | ||
type: kNormalCurveType, | ||
parentType: "Univariate Measure", | ||
plots: ["dotPlot"], | ||
prefix: kNormalCurvePrefix, | ||
modelClass: NormalCurveAdornmentModel, | ||
undoRedoKeys: { | ||
undoAdd: kNormalCurveUndoAddKey, | ||
redoAdd: kNormalCurveRedoAddKey, | ||
undoRemove: kNormalCurveUndoRemoveKey, | ||
redoRemove: kNormalCurveRedoRemoveKey, | ||
} | ||
}) | ||
|
||
registerAdornmentComponentInfo({ | ||
adornmentEltClass: kNormalCurveClass, | ||
Component: NormalCurveAdornmentComponent, | ||
Controls, | ||
labelKey: kNormalCurveLabelKey, | ||
order: 10, | ||
type: kNormalCurveType | ||
}) |
11 changes: 11 additions & 0 deletions
11
...ponents/graph/adornments/univariate-measures/normal-curve/normal-curve-adornment-types.ts
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,11 @@ | ||
export const kNormalCurveClass = "normal-curve" | ||
export const kNormalCurveType = "Normal Curve" | ||
export const kNormalCurvePrefix = "ADRN" | ||
export const kNormalCurveLabelKey = "DG.Inspector.graphPlottedNormal" | ||
export const kNormalCurveUndoAddKey = "DG.Undo.graph.showPlottedNormal" | ||
export const kNormalCurveRedoAddKey = "DG.Redo.graph.showPlottedNormal" | ||
export const kNormalCurveUndoRemoveKey = "DG.Undo.graph.hidePlottedNormal" | ||
export const kNormalCurveRedoRemoveKey = "DG.Redo.graph.hidePlottedNormal" | ||
export const kNormalCurveValueTitleKey = "" // We don't have a single value title because we display mean and sd | ||
export const kNormalCurveMeanValueTitleKey = "DG.PlottedAverageAdornment.meanValueTitle" | ||
export const kNormalCurveStdDevValueTitleKey = "DG.PlottedAverageAdornment.stDevValueTitle" |
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
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
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
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