Skip to content

Commit

Permalink
chore: code review tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kswenson committed Oct 28, 2024
1 parent 9ed34ed commit 3cf0f7a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {observer} from "mobx-react-lite"
import {mstReaction} from "../../../../utilities/mst-reaction"
import {comparer, reaction} from "mobx"
import {drag, range, select} from "d3"
import React, {useCallback, useEffect, useMemo, useRef, useState} from "react"
import React, {useCallback, useEffect, useMemo, useRef} from "react"
import { logMessageWithReplacement } from "../../../../lib/log-message"
// import { setOrExtendSelection } from "../../../../models/data/data-set-utils"
import {isSelectionAction} from "../../../../models/data/data-set-actions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const DisplayItemFormatControl = observer(function PointFormatControl(pro
return (

Check warning on line 136 in v3/src/components/data-display/inspector/display-item-format-control.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/data-display/inspector/display-item-format-control.tsx#L136

Added line #L136 was not covered by tests
<Flex direction="row" key={category} className="palette-row color-picker-row cat-color-picker">
<FormLabel className="form-label color-picker">{category}</FormLabel>
<PointColorSetting key={category} attrType={"categorical"} propertyLabel={category}
<PointColorSetting key={category} propertyLabel={category}
onColorChange={(color) => handleCatPointColorChange(color, category)}

Check warning on line 140 in v3/src/components/data-display/inspector/display-item-format-control.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/data-display/inspector/display-item-format-control.tsx#L140

Added line #L140 was not covered by tests
swatchBackgroundColor={dataConfiguration.getLegendColorForCategory(category)}/>
</Flex>
Expand All @@ -149,10 +149,10 @@ export const DisplayItemFormatControl = observer(function PointFormatControl(pro
<FormLabel className="form-label color-picker">{t("DG.Inspector.legendColor")}</FormLabel>
{/* Sets the min and max colors for numeric legend. Currently not implemented so
this sets the same color for all the points*/}
<PointColorSetting propertyLabel={t("DG.Inspector.legendColor")} attrType={"numeric"}
<PointColorSetting propertyLabel={t("DG.Inspector.legendColor")}
onColorChange={(color) => handlePointColorChange(color)}

Check warning on line 153 in v3/src/components/data-display/inspector/display-item-format-control.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/data-display/inspector/display-item-format-control.tsx#L153

Added line #L153 was not covered by tests
swatchBackgroundColor={displayItemDescription.pointColor}/>
<PointColorSetting propertyLabel={t("DG.Inspector.legendColor")} attrType={"numeric"}
<PointColorSetting propertyLabel={t("DG.Inspector.legendColor")}
onColorChange={(color) => handlePointColorChange(color)}

Check warning on line 156 in v3/src/components/data-display/inspector/display-item-format-control.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/data-display/inspector/display-item-format-control.tsx#L156

Added line #L156 was not covered by tests
swatchBackgroundColor={displayItemDescription.pointColor}/>
</Flex>
Expand Down
18 changes: 4 additions & 14 deletions v3/src/components/data-display/inspector/point-color-setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ import styles from "./point-color-setting-shared.scss"
import "./point-color-setting.scss"

interface ColorPickerIProps {
onColorChange: (color: string) => void | ((color: string, cat: string) => void) |
((color: string, quantile: number) => void)
onColorChange: (color: string) => void
propertyLabel: string
swatchBackgroundColor: string
attrType?: string
quantile?: number
}

export const PointColorSetting = observer(function PointColorSetting({onColorChange,
propertyLabel, swatchBackgroundColor, attrType, quantile=0}: ColorPickerIProps) {
propertyLabel, swatchBackgroundColor}: ColorPickerIProps) {
const [showColorPicker, setShowColorPicker] = useState(false)
const [inputValue, setInputValue] = useState(missingColor)
const popoverRef = useRef<HTMLDivElement>(null)
Expand All @@ -34,7 +31,6 @@ export const PointColorSetting = observer(function PointColorSetting({onColorCha
const paletteColors = ["#000000", "#a9a9a9", "#d3d3d3", "#FFFFFF", "#ad2323", "#ff9632", "#ffee33", "#1d6914",

Check warning on line 31 in v3/src/components/data-display/inspector/point-color-setting.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/data-display/inspector/point-color-setting.tsx#L22-L31

Added lines #L22 - L31 were not covered by tests
"#2a4bd7", "#814a19", "#8126c0", "#29d0d0", "#e9debb", "#ffcdf3", "#9dafff", "#81c57a"]


useOutsidePointerDown({ref: popoverContainerRef, handler: () => setOpenPopover?.(null)})

const handleSwatchClick = (cat: string) => {

Check warning on line 36 in v3/src/components/data-display/inspector/point-color-setting.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/data-display/inspector/point-color-setting.tsx#L36

Added line #L36 was not covered by tests
Expand All @@ -44,14 +40,8 @@ export const PointColorSetting = observer(function PointColorSetting({onColorCha
const updateValue = useCallback((value: string) => {
setInputValue(value)
setNonStandardColorSelected(true)
if (attrType === "categorical") {
(onColorChange as (color: string, cat: string) => void)(value, propertyLabel)
} else if (attrType === "numeric") {
(onColorChange as (color: string, quantile: number) => void)(value, quantile)
} else {
(onColorChange as (color: string) => void)(value)
}
}, [attrType, propertyLabel])
onColorChange(value)

Check warning on line 43 in v3/src/components/data-display/inspector/point-color-setting.tsx

View check run for this annotation

Codecov / codecov/patch

v3/src/components/data-display/inspector/point-color-setting.tsx#L40-L43

Added lines #L40 - L43 were not covered by tests
}, [onColorChange])

const rejectValue = useCallback(() => {
setShowColorPicker(false)
Expand Down
2 changes: 1 addition & 1 deletion v3/src/models/shared/shared-case-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { observable } from "mobx"
import { getSnapshot, getType, Instance, ISerializedActionCall, onAction, types } from "mobx-state-tree"
import { getSnapshot, getType, Instance, ISerializedActionCall, types } from "mobx-state-tree"
import { onAnyAction } from "../../utilities/mst-utils"
import { CategorySet, createProvisionalCategorySet, ICategorySet } from "../data/category-set"
import { DataSet, IDataSet } from "../data/data-set"
Expand Down

0 comments on commit 3cf0f7a

Please sign in to comment.