File tree Expand file tree Collapse file tree 5 files changed +95
-16
lines changed
plugins/wiggle/src/MultiLinearWiggleDisplay/components Expand file tree Collapse file tree 5 files changed +95
-16
lines changed Original file line number Diff line number Diff line change 11import { observer } from 'mobx-react'
22
33import LegendItem from './LegendItem'
4+ import LegendItemText from './LegendItemText'
45import RectBg from './RectBg'
56
67import type { WiggleDisplayModel } from '../model'
@@ -41,6 +42,7 @@ const ColorLegend = observer(function ({
4142 />
4243 ) : null
4344 }
45+ { /* Render all background rectangles first */ }
4446 { sources . map ( ( source , idx ) => (
4547 < LegendItem
4648 key = { `${ source . name } -${ idx } ` }
@@ -52,6 +54,17 @@ const ColorLegend = observer(function ({
5254 labelWidth = { labelWidth }
5355 />
5456 ) ) }
57+ { /* Then render all text elements on top */ }
58+ { sources . map ( ( source , idx ) => (
59+ < LegendItemText
60+ key = { `${ source . name } -text-${ idx } ` }
61+ source = { source }
62+ idx = { idx }
63+ model = { model }
64+ rowHeight = { rowHeight }
65+ exportSVG = { exportSVG }
66+ />
67+ ) ) }
5568 </ >
5669 ) : null
5770} )
Original file line number Diff line number Diff line change @@ -26,23 +26,29 @@ const LegendItem = function ({
2626 rowHeightTooSmallForScalebar,
2727 renderColorBoxes,
2828 } = model
29- const svgFontSize = Math . min ( rowHeight , 12 )
30- const canDisplayLabel = rowHeight >= 6
3129 const colorBoxWidth = renderColorBoxes ? 15 : 0
3230 const legendWidth = labelWidth + colorBoxWidth + 5
3331 const svgOffset = exportSVG ? 10 : 0
3432 const extraOffset =
3533 svgOffset || ( graphType && ! rowHeightTooSmallForScalebar ? 50 : 0 )
3634 return (
3735 < >
38- { canDisplayLabel ? (
39- < text
40- y = { idx * rowHeight + 13 }
41- x = { extraOffset + colorBoxWidth + 2 }
42- fontSize = { svgFontSize }
43- >
44- { source . name }
45- </ text >
36+ { needsFullHeightScalebar ? null : (
37+ < RectBg
38+ y = { idx * rowHeight + 1 }
39+ x = { extraOffset }
40+ width = { legendWidth }
41+ height = { boxHeight }
42+ />
43+ ) }
44+ { source . color ? (
45+ < RectBg
46+ y = { idx * rowHeight + 1 }
47+ x = { extraOffset }
48+ width = { colorBoxWidth }
49+ height = { needsCustomLegend ? rowHeight : boxHeight }
50+ color = { source . color }
51+ />
4652 ) : null }
4753 </ >
4854 )
Original file line number Diff line number Diff line change 1+ import type { Source } from '../../util'
2+ import type { WiggleDisplayModel } from '../model'
3+
4+ const LegendItemText = function ( {
5+ source,
6+ idx,
7+ rowHeight,
8+ model,
9+ exportSVG,
10+ } : {
11+ source : Source
12+ idx : number
13+ rowHeight : number
14+ model : WiggleDisplayModel
15+ exportSVG ?: boolean
16+ } ) {
17+ const {
18+ graphType,
19+ rowHeightTooSmallForScalebar,
20+ renderColorBoxes,
21+ } = model
22+ const svgFontSize = Math . min ( rowHeight , 12 )
23+ const canDisplayLabel = rowHeight >= 6
24+ const colorBoxWidth = renderColorBoxes ? 15 : 0
25+ const svgOffset = exportSVG ? 10 : 0
26+ const extraOffset =
27+ svgOffset || ( graphType && ! rowHeightTooSmallForScalebar ? 50 : 0 )
28+
29+ return canDisplayLabel ? (
30+ < text
31+ y = { idx * rowHeight + 13 }
32+ x = { extraOffset + colorBoxWidth + 2 }
33+ fontSize = { svgFontSize }
34+ >
35+ { source . name }
36+ </ text >
37+ ) : null
38+ }
39+
40+ export default LegendItemText
Original file line number Diff line number Diff line change @@ -123,13 +123,23 @@ const WiggleClusterDialogAuto = observer(function ({
123123 } ,
124124 ) ) as { order : number [ ] }
125125
126+ // Preserve color and other layout customizations
127+ const currentLayout = model . layout . length ? model . layout : sourcesWithoutLayout
128+ const sourcesByName = Object . fromEntries (
129+ currentLayout . map ( s => [ s . name , s ] ) ,
130+ )
131+
126132 model . setLayout (
127133 ret . order . map ( idx => {
128- const ret = sourcesWithoutLayout [ idx ]
129- if ( ! ret ) {
134+ const sourceItem = sourcesWithoutLayout [ idx ]
135+ if ( ! sourceItem ) {
130136 throw new Error ( `out of bounds at ${ idx } ` )
131137 }
132- return ret
138+ // Preserve customizations from current layout
139+ return {
140+ ...sourceItem ,
141+ ...sourcesByName [ sourceItem . name ] ,
142+ }
133143 } ) ,
134144 )
135145 }
Original file line number Diff line number Diff line change @@ -261,18 +261,28 @@ cat(resultClusters$order,sep='\n')`
261261 const { sourcesWithoutLayout } = model
262262 if ( sourcesWithoutLayout ) {
263263 try {
264+ // Preserve color and other layout customizations
265+ const currentLayout = model . layout . length ? model . layout : sourcesWithoutLayout
266+ const sourcesByName = Object . fromEntries (
267+ currentLayout . map ( s => [ s . name , s ] ) ,
268+ )
269+
264270 model . setLayout (
265271 paste
266272 . split ( '\n' )
267273 . map ( t => t . trim ( ) )
268274 . filter ( f => ! ! f )
269275 . map ( r => + r )
270276 . map ( idx => {
271- const ret = sourcesWithoutLayout [ idx - 1 ]
272- if ( ! ret ) {
277+ const sourceItem = sourcesWithoutLayout [ idx - 1 ]
278+ if ( ! sourceItem ) {
273279 throw new Error ( `out of bounds at ${ idx } ` )
274280 }
275- return ret
281+ // Preserve customizations from current layout
282+ return {
283+ ...sourceItem ,
284+ ...sourcesByName [ sourceItem . name ] ,
285+ }
276286 } ) ,
277287 )
278288 } catch ( e ) {
You can’t perform that action at this time.
0 commit comments