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 { graphType, rowHeightTooSmallForScalebar, renderColorBoxes } = model
18+ const svgFontSize = Math . min ( rowHeight , 12 )
19+ const canDisplayLabel = rowHeight >= 6
20+ const colorBoxWidth = renderColorBoxes ? 15 : 0
21+ const svgOffset = exportSVG ? 10 : 0
22+ const extraOffset =
23+ svgOffset || ( graphType && ! rowHeightTooSmallForScalebar ? 50 : 0 )
24+
25+ return canDisplayLabel ? (
26+ < text
27+ y = { idx * rowHeight + 13 }
28+ x = { extraOffset + colorBoxWidth + 2 }
29+ fontSize = { svgFontSize }
30+ >
31+ { source . name }
32+ </ text >
33+ ) : null
34+ }
35+
36+ export default LegendItemText
Original file line number Diff line number Diff line change @@ -123,13 +123,25 @@ const WiggleClusterDialogAuto = observer(function ({
123123 } ,
124124 ) ) as { order : number [ ] }
125125
126+ // Preserve color and other layout customizations
127+ const currentLayout = model . layout . length
128+ ? model . layout
129+ : sourcesWithoutLayout
130+ const sourcesByName = Object . fromEntries (
131+ currentLayout . map ( s => [ s . name , s ] ) ,
132+ )
133+
126134 model . setLayout (
127135 ret . order . map ( idx => {
128- const ret = sourcesWithoutLayout [ idx ]
129- if ( ! ret ) {
136+ const sourceItem = sourcesWithoutLayout [ idx ]
137+ if ( ! sourceItem ) {
130138 throw new Error ( `out of bounds at ${ idx } ` )
131139 }
132- return ret
140+ // Preserve customizations from current layout
141+ return {
142+ ...sourceItem ,
143+ ...sourcesByName [ sourceItem . name ] ,
144+ }
133145 } ) ,
134146 )
135147 }
Original file line number Diff line number Diff line change @@ -261,18 +261,30 @@ 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
266+ ? model . layout
267+ : sourcesWithoutLayout
268+ const sourcesByName = Object . fromEntries (
269+ currentLayout . map ( s => [ s . name , s ] ) ,
270+ )
271+
264272 model . setLayout (
265273 paste
266274 . split ( '\n' )
267275 . map ( t => t . trim ( ) )
268276 . filter ( f => ! ! f )
269277 . map ( r => + r )
270278 . map ( idx => {
271- const ret = sourcesWithoutLayout [ idx - 1 ]
272- if ( ! ret ) {
279+ const sourceItem = sourcesWithoutLayout [ idx - 1 ]
280+ if ( ! sourceItem ) {
273281 throw new Error ( `out of bounds at ${ idx } ` )
274282 }
275- return ret
283+ // Preserve customizations from current layout
284+ return {
285+ ...sourceItem ,
286+ ...sourcesByName [ sourceItem . name ] ,
287+ }
276288 } ) ,
277289 )
278290 } catch ( e ) {
You can’t perform that action at this time.
0 commit comments