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

fix: undo multiple y [PT-187833677] #1380

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {scaleQuantile, ScaleQuantile, schemeBlues} from "d3"
import {comparer, reaction} from "mobx"
import {comparer, observable, reaction} from "mobx"
import {
addDisposer, getEnv, getSnapshot, hasEnv, IAnyStateTreeNode, Instance, ISerializedActionCall,
resolveIdentifier, SnapshotIn, types
Expand Down Expand Up @@ -89,7 +89,7 @@ export const DataConfigurationModel = types
})
.volatile(() => ({
actionHandlerDisposer: undefined as (() => void) | undefined,
filteredCases: [] as FilteredCases[],
filteredCases: observable.array<FilteredCases>([], { deep: false }),
handlers: new Map<string, (actionCall: ISerializedActionCall) => void>(),
pointsNeedUpdating: false,
casesChangeCount: 0
Expand Down Expand Up @@ -163,7 +163,7 @@ export const DataConfigurationModel = types
.actions(self => ({
clearFilteredCases() {
self.filteredCases.forEach(aFilteredCases => aFilteredCases.destroy())
self.filteredCases = []
self.filteredCases.clear()
},
beforeDestroy() {
this.clearFilteredCases()
Expand Down
3 changes: 2 additions & 1 deletion v3/src/components/graph/components/graph.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {comparer} from "mobx"
import {observer} from "mobx-react-lite"
import {addDisposer, isAlive} from "mobx-state-tree"
import React, {MutableRefObject, useCallback, useEffect, useMemo, useRef} from "react"
Expand Down Expand Up @@ -84,7 +85,7 @@ export const Graph = observer(function Graph({graphController, graphRef, pixiPoi
} else {
graphController.callMatchCirclesToData()
}
}, {name: "Graph.handleFilteredCasesChange"}, graphModel
}, {name: "Graph.handleFilteredCasesChange", equals: comparer.structural}, graphModel
)
}, [graphController, graphModel])

Expand Down
60 changes: 30 additions & 30 deletions v3/src/components/graph/models/graph-data-configuration-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,17 @@
if (caseArrayNumber === 0 || caseArrayNumber === undefined) {
return self._filterCase(data, caseID)
}
// Note that this excludes `rightNumeric` (see `attributeDescriptions` above)
const descriptions = {...self.attributeDescriptions}
// If a 'rightNumeric' attribute exists and caseArrayNumber is >= the length of _yAttributeDescriptions, then
// we are looking at the rightNumeric attribute. Delete the y attribute description and add the rightNumeric one.
// Otherwise, replace the y attribute description with the one at the given index.
if (caseArrayNumber >= self._yAttributeDescriptions.length) {
delete descriptions.y
descriptions.rightNumeric = self.attributeDescriptionForRole('rightNumeric')
const rightNumeric = self.attributeDescriptionForRole('rightNumeric')
if (rightNumeric) {
descriptions.rightNumeric = rightNumeric

Check warning on line 173 in v3/src/components/graph/models/graph-data-configuration-model.ts

View check run for this annotation

Codecov / codecov/patch

v3/src/components/graph/models/graph-data-configuration-model.ts#L173

Added line #L173 was not covered by tests
}
} else {
descriptions.y = self._yAttributeDescriptions[caseArrayNumber]
}
Expand Down Expand Up @@ -568,24 +572,6 @@
}
}
})
.actions(self => {
const baseHandleDataSetChange = self.handleDataSetChange
return {
handleDataSetChange(data?: IDataSet) {
baseHandleDataSetChange(data)
if (data) {
// make sure there are enough filteredCases to hold all the y attributes
while (self.filteredCases.length < self._yAttributeDescriptions.length) {
self._addNewFilteredCases()
}
// A y2 attribute is optional, so only add a new filteredCases if there is one.
if (self.hasY2Attribute) {
self._addNewFilteredCases()
}
}
}
}
})
.actions(self => ({
setPrimaryRole(role: GraphAttrRole) {
if (role === 'x' || role === 'y') {
Expand Down Expand Up @@ -618,16 +604,10 @@
},
addYAttribute(desc: IAttributeDescriptionSnapshot) {
self._yAttributeDescriptions.push(desc)
self._addNewFilteredCases()
},
setY2Attribute(desc?: IAttributeDescriptionSnapshot) {
const isNewAttribute = !self._attributeDescriptions.get('rightNumeric'),
isEmpty = !desc?.attributeID
self._setAttributeDescription('rightNumeric', desc)
if (isNewAttribute) {
self._addNewFilteredCases()
} else if (isEmpty) {
self.filteredCases?.pop()?.destroy() // remove and destroy the one for the y2 plot
if (!desc?.attributeID) {
self.setPointsNeedUpdating(true)
} else {
const existingFilteredCases = self.filteredCases?.[self.numberOfPlots - 1]
Expand Down Expand Up @@ -679,13 +659,33 @@
const baseRemoveAttributeFromRole = self.removeAttributeFromRole
return {
afterCreate() {
// synchronize filteredCases with attribute configuration
addDisposer(self, reaction(
() => {
const yAttributeDescriptions = getSnapshot(self._yAttributeDescriptions)
const _y2AttributeDescription = self._attributeDescriptions.get("rightNumeric")
const y2AttributeDescription = _y2AttributeDescription
? { y2AttributeDescription: getSnapshot(_y2AttributeDescription) }
: undefined
return { yAttributeDescriptions, ...y2AttributeDescription }
},
({ yAttributeDescriptions, y2AttributeDescription }) => {
const yAttrCount = yAttributeDescriptions.length + (y2AttributeDescription ? 1 : 0)
const filteredCasesRequired = Math.max(1, yAttrCount)
// remove any extraneous filteredCases
while (self.filteredCases.length > filteredCasesRequired) {
self.filteredCases.pop()?.destroy()
}
// add any required filteredCases
while (self.filteredCases.length < filteredCasesRequired) {
self._addNewFilteredCases()
}
}, { name: "GraphDataConfigurationModel yAttrDescriptions reaction", equals: comparer.structural }
))
addDisposer(self, reaction(
() => self.getAllCellKeys(),
() => self.clearGraphSpecificCasesCache(),
{
name: "GraphDataConfigurationModel.afterCreate.reaction [getAllCellKeys]",
equals: comparer.structural
}
{ name: "GraphDataConfigurationModel getCellKeys reaction", equals: comparer.structural }
))
baseAfterCreate()
},
Expand Down