-
Notifications
You must be signed in to change notification settings - Fork 162
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
Color tree by measurements #1924
Changes from 1 commit
d90c503
6c2e53b
15dabdf
14a5650
1391b9b
acf11a4
a4b4d9c
69853e2
8b2773e
74eac4a
c0b7e91
e1c74a4
9a5a183
3c35ed5
c2db2bb
17d411c
ade2c20
440cddd
ff28517
795efc7
9a4c328
5d51e9c
0dbc4e3
fb3eba0
a2cfe54
bb44c2a
82e6f6d
9f6b032
27cdbb0
e52f48d
972ed91
e586a6c
921161c
aead1cf
daccd78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { batch } from "react-redux"; | ||
import { quantile } from "d3-array"; | ||
import { cloneDeep } from "lodash"; | ||
import { AppDispatch, ThunkFunction } from "../store"; | ||
|
@@ -611,14 +612,23 @@ export const applyMeasurementsColorBy = ( | |
} | ||
} | ||
|
||
if (controls.measurementsColorGrouping !== undefined) { | ||
dispatch({type: REMOVE_METADATA, nodeAttrsToRemove: [encodeMeasurementColorBy(controls.measurementsColorGrouping)]}); | ||
} | ||
if (controls.measurementsColorGrouping !== groupingValue) { | ||
dispatch({type: CHANGE_MEASUREMENTS_COLOR_GROUPING, controls:{measurementsColorGrouping: groupingValue}}); | ||
} | ||
dispatch({type: ADD_EXTRA_METADATA, newNodeAttrs, newColorings}); | ||
dispatch(changeColorBy(measurementColorBy)); | ||
/** | ||
* Batching all dispatch actions together to prevent multiple renders | ||
* This is also _required_ to prevent error in calcColorScale during extra renders: | ||
* 1. REMOVE_METADATA removes current measurements coloring from metadata.colorings | ||
* 2. This triggers the componentDidUpdate in controls/color-by, which dispatches changeColorBy. | ||
* 3. calcColorScale throws error because the current coloring is no longer valid as it was removed by REMOVE_METADATA in step 1. | ||
*/ | ||
batch(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's worth changing what you've done (which includes a good docstring) but an alternative approach to consider for patterns like this if we use them again is to make "remove metadata" a thunk which checks that the attr being removed isn't currently used as a coloring, and if it is then thee thunk can do something about it. |
||
if (controls.measurementsColorGrouping !== undefined) { | ||
dispatch({type: REMOVE_METADATA, nodeAttrsToRemove: [encodeMeasurementColorBy(controls.measurementsColorGrouping)]}); | ||
} | ||
if (controls.measurementsColorGrouping !== groupingValue) { | ||
dispatch({type: CHANGE_MEASUREMENTS_COLOR_GROUPING, controls:{measurementsColorGrouping: groupingValue}}); | ||
} | ||
dispatch({type: ADD_EXTRA_METADATA, newNodeAttrs, newColorings}); | ||
dispatch(changeColorBy(measurementColorBy)); | ||
}) | ||
} | ||
|
||
const controlToQueryParamMap = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about
batch
- was a good opportunity to catch up with some of the many changes in the redux/react world. It seems that React 18 will do this automatically (react 18 upgrade PR: #1659). I wondered why you didn't just add the new node info, change colour, then delete the old data... however since thenode.attrs
key names are reused I can imagine this causes some undesirable side-effects?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, things can get complicated if the node.attrs key names are the same but the underlying values changed. A concrete example is changing measurements collections. They might have the same reference strain (which means they have the same node.attrs key), but completely different measurements so the data needs to be completely updated. It's cleaner to remove old data then apply the new data instead of trying to keep track of which nodes needs to be updated.