From 433b712dbac34fd84010efc0df7d30d1942eb903 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 25 Feb 2021 01:03:11 -0700 Subject: [PATCH 1/2] Add a color picker --- plugins/wiggle/package.json | 1 + .../components/SetColorDialog.tsx | 93 +++++++++++++++++++ .../src/LinearWiggleDisplay/models/model.ts | 33 +++++++ 3 files changed, 127 insertions(+) create mode 100644 plugins/wiggle/src/LinearWiggleDisplay/components/SetColorDialog.tsx diff --git a/plugins/wiggle/package.json b/plugins/wiggle/package.json index 0a63d9016c..2559437ebc 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 0000000000..db4135a4f7 --- /dev/null +++ b/plugins/wiggle/src/LinearWiggleDisplay/components/SetColorDialog.tsx @@ -0,0 +1,93 @@ +import React from 'react' +import { makeStyles } from '@material-ui/core/styles' +import { + Dialog, + DialogContent, + DialogTitle, + IconButton, + 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 af849e5e3b..0c3b4bf1df 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 @@ -367,6 +385,15 @@ const stateModelFactory = ( self.toggleCrossHatches() }, }, + { + label: 'Summary score mode', + subMenu: ['min', 'max', 'avg', 'whiskers'].map(elt => { + return { + label: elt, + onClick: () => self.setSummaryScoreMode(elt), + } + }), + }, ...(getConf(self, 'renderers').length > 1 ? [ { @@ -404,6 +431,12 @@ const stateModelFactory = ( getContainingTrack(self).setDialogComponent(SetMinMaxDlg, self) }, }, + { + label: 'Set color', + onClick: () => { + getContainingTrack(self).setDialogComponent(SetColorDlg, self) + }, + }, ] }, From 0829b59283d7d8779fda5b2fc558140ac5e6afa9 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 4 Mar 2021 13:51:59 -0700 Subject: [PATCH 2/2] Only use summary score mode if hasResolution capability is enabled on adapter --- .../src/LinearWiggleDisplay/models/model.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/wiggle/src/LinearWiggleDisplay/models/model.ts b/plugins/wiggle/src/LinearWiggleDisplay/models/model.ts index 0c3b4bf1df..b772acaa72 100644 --- a/plugins/wiggle/src/LinearWiggleDisplay/models/model.ts +++ b/plugins/wiggle/src/LinearWiggleDisplay/models/model.ts @@ -356,6 +356,15 @@ const stateModelFactory = ( }, ], }, + { + label: 'Summary score mode', + subMenu: ['min', 'max', 'avg', 'whiskers'].map(elt => { + return { + label: elt, + onClick: () => self.setSummaryScoreMode(elt), + } + }), + }, ] : []), ...(self.canHaveFill @@ -385,15 +394,7 @@ const stateModelFactory = ( self.toggleCrossHatches() }, }, - { - label: 'Summary score mode', - subMenu: ['min', 'max', 'avg', 'whiskers'].map(elt => { - return { - label: elt, - onClick: () => self.setSummaryScoreMode(elt), - } - }), - }, + ...(getConf(self, 'renderers').length > 1 ? [ {