Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add measurements types #1910

Merged
merged 22 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d1e5bc1
Fix whitespace
joverlee521 Nov 15, 2024
4eb9c3c
Move type ThunkFunction to `src/store.ts`
joverlee521 Nov 15, 2024
975b754
Add @types/lodash
joverlee521 Nov 16, 2024
07ba5e1
Rename for TypeScript
joverlee521 Nov 16, 2024
8219fa3
Add types to measurements
joverlee521 Nov 16, 2024
2361e67
Update default measurements state to `undefined` values
joverlee521 Dec 7, 2024
1b59263
CHANGE_MEASUREMENTS_COLLECTION: only update if `loaded`
joverlee521 Dec 7, 2024
21ef2b4
measurementsD3: Fix JSDoc for type error
joverlee521 Nov 16, 2024
c9a309e
Add proper type checking in handleHover
joverlee521 Nov 18, 2024
a932abb
Replace `lodash.pick` for proper type assignment
joverlee521 Nov 18, 2024
78e4761
Build parsed collection instead of directly editing object
joverlee521 Nov 18, 2024
adec1ae
Update `GroupingValues` type to use Map objects
joverlee521 Nov 18, 2024
728682d
Add proper type check of `queryValue`
joverlee521 Nov 18, 2024
de428f1
Update `Query` type
joverlee521 Nov 18, 2024
7a3cc10
Convert all measurements metadata to string during parsing of JSON
joverlee521 Nov 19, 2024
e451963
Consolidate query boolean checks in `isQueryBoolean`
joverlee521 Nov 19, 2024
a34a604
Consolidate measurements display values with MeasurementsDisplay type
joverlee521 Nov 19, 2024
600078f
Fix lint errors
joverlee521 Nov 19, 2024
ec8a313
Add return types for various `map`
joverlee521 Nov 22, 2024
49ee53c
Update MeasurementsDisplay and QueryBoolean types to be more readable
joverlee521 Nov 22, 2024
91a77de
Use more robust type narrowing for `Measurement` and `Collection`
joverlee521 Nov 22, 2024
6dfb02a
Update `handleHover` data type check to be more readable
joverlee521 Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"@types/d3-transition": "^1.2.0",
"@types/d3-zoom": "^1.1.3",
"@types/leaflet": "^1.9.3",
"@types/lodash": "^4.17.13",
"@types/node": "^18.15.11",
"@types/webpack-env": "^1.18.2",
"@typescript-eslint/eslint-plugin": "^5.57.0",
Expand Down
278 changes: 193 additions & 85 deletions src/actions/measurements.js → src/actions/measurements.ts

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions src/actions/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ import { warningNotification } from "./notifications";
import { calcFullTipCounts, calcTipCounts } from "../util/treeCountingHelpers";
import { PhyloNode } from "../components/tree/phyloTree/types";
import { Metadata } from "../metadata";
import { AppDispatch, RootState } from "../store";
import { ThunkFunction } from "../store";
import { ReduxNode, TreeState } from "../reducers/tree/types";

type RootIndex = number | undefined

/** [root idx tree1, root idx tree2] */
export type Root = [RootIndex, RootIndex]

/** A function to be handled by redux (thunk) */
type ThunkFunction = (dispatch: AppDispatch, getState: () => RootState) => void

/**
* Updates the `inView` property of nodes which depends on the currently selected
* root index (i.e. what node the tree is zoomed into).
Expand Down Expand Up @@ -277,7 +274,7 @@ export const applyFilter = (
* - "set" -> set the values of the filter to be those provided. All disabled filters will be removed. XXX TODO.
*/
mode: "add" | "inactivate" | "remove" | "set",

/** the trait name of the filter ("authors", "country" etcetera) */
trait: string | symbol,

Expand Down
4 changes: 2 additions & 2 deletions src/components/controls/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const DEBOUNCE_TIME = 200;
nodes: state.tree.nodes,
nodesSecondTree: state.treeToo?.nodes,
totalStateCountsSecondTree: state.treeToo?.totalStateCounts,
measurementsFieldsMap: state.measurements.collectionToDisplay.fields,
measurementsFiltersMap: state.measurements.collectionToDisplay.filters,
measurementsFieldsMap: state.measurements.collectionToDisplay?.fields,
measurementsFiltersMap: state.measurements.collectionToDisplay?.filters,
measurementsFilters: state.controls.measurementsFilters
};
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ import { controlsWidth } from "../../util/globals";
import { SidebarSubtitle, SidebarButton } from "./styles";
import Toggle from "./toggle";
import CustomSelect from "./customSelect";
import { Collection } from "../../reducers/measurements/types";
import { RootState } from "../../store";

interface SelectOption {
value: string
label: string
}

/**
* React Redux selector function that takes the key and title for the
* available collections to create the object expected for the Select library.
* The label defaults to the key if a collection does not have a set title.
* @param {Array<Object>} collections
* @returns {Array<Object>}
*/
const collectionOptionsSelector = (collections) => {
const collectionOptionsSelector = (
collections: Collection[]
): SelectOption[] => {
return collections.map((collection) => {
return {
value: collection.key,
Expand All @@ -32,15 +39,15 @@ const collectionOptionsSelector = (collections) => {

const MeasurementsOptions = () => {
const dispatch = useAppDispatch();
const collection = useSelector((state) => state.measurements.collectionToDisplay);
const collectionOptions = useSelector((state) => collectionOptionsSelector(state.measurements.collections), isEqual);
const groupBy = useSelector((state) => state.controls.measurementsGroupBy);
const display = useSelector((state) => state.controls.measurementsDisplay);
const showOverallMean = useSelector((state) => state.controls.measurementsShowOverallMean);
const showThreshold = useSelector((state) => state.controls.measurementsShowThreshold);
const collection = useSelector((state: RootState) => state.measurements.collectionToDisplay);
const collectionOptions = useSelector((state: RootState) => collectionOptionsSelector(state.measurements.collections), isEqual);
const groupBy = useSelector((state: RootState) => state.controls.measurementsGroupBy);
const display = useSelector((state: RootState) => state.controls.measurementsDisplay);
const showOverallMean = useSelector((state: RootState) => state.controls.measurementsShowOverallMean);
const showThreshold = useSelector((state: RootState) => state.controls.measurementsShowThreshold);

// Create grouping options for the Select library
let groupingOptions = [];
let groupingOptions: SelectOption[] = [];
if (collection.groupings) {
groupingOptions = [...collection.groupings.keys()].map((grouping) => {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/components/info/filtersSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const closeBracketSmall = <span style={{fontSize: "1.8rem", fontWeight: 300, pad
absoluteDateMax: state.controls.absoluteDateMax,
branchLengthsToDisplay: state.controls.branchLengthsToDisplay,
measurementsFilters: state.controls.measurementsFilters,
measurementsFields: state.measurements.collectionToDisplay.fields
measurementsFields: state.measurements.collectionToDisplay?.fields
};
})
class FiltersSummary extends React.Component {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import React from "react";
import React, { CSSProperties } from "react";
import { infoPanelStyles } from "../../globalStyles";
import { InfoLine } from "../tree/infoPanels/hover";

const HoverPanel = ({hoverData}) => {
export interface HoverData {
hoverTitle: string
mouseX: number
mouseY: number
containerId: string
data: Map<string, unknown>
}

const HoverPanel = ({
hoverData
}: {
hoverData: HoverData
}) => {
if (hoverData === null) return null;
const { hoverTitle, mouseX, mouseY, containerId, data } = hoverData;
const panelStyle = {
const panelStyle: CSSProperties = {
position: "absolute",
minWidth: 200,
padding: "5px",
Expand Down
Loading
Loading