From 41a4604777d9575d1502d2496d583fcef9645d72 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 25 Feb 2021 01:03:11 -0700 Subject: [PATCH] Add a color picker --- plugins/wiggle/package.json | 1 + .../components/SetColorDialog.tsx | 94 +++++++++++++++++++ .../src/LinearWiggleDisplay/models/model.ts | 33 +++++++ 3 files changed, 128 insertions(+) create mode 100644 plugins/wiggle/src/LinearWiggleDisplay/components/SetColorDialog.tsx diff --git a/plugins/wiggle/package.json b/plugins/wiggle/package.json index 0a63d9016c8..2559437ebc1 100644 --- a/plugins/wiggle/package.json +++ b/plugins/wiggle/package.json @@ -41,6 +41,7 @@ "color": "^3.1.1", "d3-scale": "^3.2.3", "json-stable-stringify": "^1.0.1", + "react-color": "^2.19.3", "react-d3-axis": "^0.1.2" }, "peerDependencies": { diff --git a/plugins/wiggle/src/LinearWiggleDisplay/components/SetColorDialog.tsx b/plugins/wiggle/src/LinearWiggleDisplay/components/SetColorDialog.tsx new file mode 100644 index 00000000000..cebbb1d4b81 --- /dev/null +++ b/plugins/wiggle/src/LinearWiggleDisplay/components/SetColorDialog.tsx @@ -0,0 +1,94 @@ +import React from 'react' +import { makeStyles } from '@material-ui/core/styles' +import { + Dialog, + DialogContent, + DialogTitle, + IconButton, + Typography, + Button, +} from '@material-ui/core' +import CloseIcon from '@material-ui/icons/Close' +import { CompactPicker, Color, RGBColor } from 'react-color' + +const useStyles = makeStyles(theme => ({ + root: {}, + closeButton: { + position: 'absolute', + right: theme.spacing(1), + top: theme.spacing(1), + color: theme.palette.grey[500], + }, +})) + +// this is needed because passing a entire color object into the react-color +// for alpha, can't pass in an rgba string for example +function serializeColor(color: Color) { + if (color instanceof Object) { + const { r, g, b, a } = color as RGBColor + return `rgb(${r},${g},${b},${a})` + } + return color +} + +export default function SetColorDialog(props: { + display: { + color: number + setColor: Function + } + handleClose: () => void +}) { + const classes = useStyles() + const { display, handleClose } = props + + return ( + + + Select a color + + + + + +
+ { + display.setColor(serializeColor(event.rgb)) + }} + /> +
+
+ + +
+
+
+
+ ) +} diff --git a/plugins/wiggle/src/LinearWiggleDisplay/models/model.ts b/plugins/wiggle/src/LinearWiggleDisplay/models/model.ts index 8555dc54b33..6d5c0bff0e7 100644 --- a/plugins/wiggle/src/LinearWiggleDisplay/models/model.ts +++ b/plugins/wiggle/src/LinearWiggleDisplay/models/model.ts @@ -32,6 +32,7 @@ import { getNiceDomain, getScale } from '../../util' import Tooltip from '../components/Tooltip' import SetMinMaxDlg from '../components/SetMinMaxDialog' +import SetColorDlg from '../components/SetColorDialog' // fudge factor for making all labels on the YScalebar visible export const YSCALEBAR_LABEL_OFFSET = 5 @@ -66,6 +67,8 @@ const stateModelFactory = ( selectedRendering: types.optional(types.string, ''), resolution: types.optional(types.number, 1), fill: types.maybe(types.boolean), + color: types.maybe(types.string), + summaryScoreMode: types.maybe(types.string), rendererTypeNameState: types.maybe(types.string), scale: types.maybe(types.string), autoscale: types.maybe(types.string), @@ -91,6 +94,9 @@ const stateModelFactory = ( self.stats.scoreMax = stats.scoreMax self.ready = true }, + setColor(color: string) { + self.color = color + }, setLoading(aborter: AbortController) { const { statsFetchInProgress: statsFetch } = self @@ -125,6 +131,10 @@ const stateModelFactory = ( } }, + setSummaryScoreMode(val: string) { + self.summaryScoreMode = val + }, + setAutoscale(val: string) { self.autoscale = val }, @@ -197,12 +207,20 @@ const stateModelFactory = ( filled: self.fill, scaleType: this.scaleType, displayCrossHatches: self.displayCrossHatches, + summaryScoreMode: self.summaryScoreMode, + color: self.color, }) }, })) .views(self => { let oldDomain: [number, number] = [0, 0] return { + get summaryScoreModeSetting() { + return ( + self.summaryScoreMode || + readConfObject(self.rendererConfig, 'summaryScoreMode') + ) + }, get domain() { const { stats, scaleType, minScore, maxScore } = self @@ -366,6 +384,15 @@ const stateModelFactory = ( self.toggleCrossHatches() }, }, + { + label: 'Summary score mode', + subMenu: ['min', 'max', 'avg', 'whiskers'].map(elt => { + return { + label: elt, + onClick: () => self.setSummaryScoreMode(elt), + } + }), + }, { label: 'Renderer type', subMenu: [...rendererTypes.keys()].map(key => ({ @@ -399,6 +426,12 @@ const stateModelFactory = ( getContainingTrack(self).setDialogComponent(SetMinMaxDlg, self) }, }, + { + label: 'Set color', + onClick: () => { + getContainingTrack(self).setDialogComponent(SetColorDlg, self) + }, + }, ] },