Skip to content

Commit

Permalink
fix: drag of dot with zero value in dot plot (#1632)
Browse files Browse the repository at this point in the history
  • Loading branch information
kswenson authored Nov 19, 2024
1 parent 7ea57a1 commit 82a9bc1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
17 changes: 9 additions & 8 deletions v3/src/components/graph/hooks/use-dot-plot-drag-drop.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { ScaleLinear } from "d3"
import * as PIXI from "pixi.js"
import { useGraphLayoutContext } from "./use-graph-layout-context"
import { useDataDisplayAnimation } from "../../data-display/hooks/use-data-display-animation"
import { useGraphDataConfigurationContext } from "./use-graph-data-configuration-context"
import { useRef, useState } from "react"
import { useDataSetContext } from "../../../hooks/use-data-set-context"
import { ScaleLinear } from "d3"
import { IPixiPointMetadata } from "../../data-display/pixi/pixi-points"
import { appState } from "../../../models/app-state"
import { ICase } from "../../../models/data/data-set-types"
import { toNonEmptyValue } from "../../../utilities/math-utils"
import { handleClickOnCase } from "../../data-display/data-display-utils"
import { dataDisplayGetNumericValue } from "../../data-display/data-display-value-utils"
import { useRef, useState } from "react"
import { ICase } from "../../../models/data/data-set-types"
import { useDataDisplayAnimation } from "../../data-display/hooks/use-data-display-animation"
import { IPixiPointMetadata } from "../../data-display/pixi/pixi-points"
import { useGraphDataConfigurationContext } from "./use-graph-data-configuration-context"
import { useGraphLayoutContext } from "./use-graph-layout-context"

export const useDotPlotDragDrop = () => {
const layout = useGraphLayoutContext()
Expand Down Expand Up @@ -43,7 +44,7 @@ export const useDotPlotDragDrop = () => {
// Record the current values, so we can change them during the drag and restore them when done
const {selection} = dataConfig || {}
selection?.forEach((anID: string) => {
const itsValue = dataDisplayGetNumericValue(dataset, anID, primaryAttrID) || undefined
const itsValue = toNonEmptyValue(dataDisplayGetNumericValue(dataset, anID, primaryAttrID))
if (itsValue != null) {
selectedDataObjects.current[anID] = itsValue
}
Expand Down
3 changes: 3 additions & 0 deletions v3/src/utilities/math-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ export const isValueEmpty = (value: any) => value == null || value === ""

export const isValueNonEmpty = (value: any) => !isValueEmpty(value)

// returns undefined for empty values, and the value itself for non-empty values
export const toNonEmptyValue = (value: any) => isValueEmpty(value) ? undefined : value

// Similar to isFiniteNumber, but looser.
// It allows for strings that can be converted to numbers and treats Infinity and -Infinity as valid numbers.
export const isNumber = (v: any) => isValueNonEmpty(v) && !isNaN(Number(v))
Expand Down

0 comments on commit 82a9bc1

Please sign in to comment.