-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
284 additions
and
239 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
plugins/wiggle/src/MultiLinearWiggleDisplay/components/ColorLegend.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React from 'react' | ||
import { observer } from 'mobx-react' | ||
|
||
// locals | ||
import { WiggleDisplayModel } from '../models/model' | ||
import RectBg from './RectBg' | ||
|
||
const ColorLegend = observer(function ({ | ||
model, | ||
rowHeight, | ||
labelWidth, | ||
exportSVG, | ||
}: { | ||
model: WiggleDisplayModel | ||
rowHeight: number | ||
labelWidth: number | ||
exportSVG?: boolean | ||
}) { | ||
const { | ||
needsCustomLegend, | ||
needsScalebar, | ||
needsFullHeightScalebar, | ||
rowHeightTooSmallForScalebar, | ||
renderColorBoxes, | ||
sources, | ||
} = model | ||
const svgFontSize = Math.min(rowHeight, 12) | ||
const canDisplayLabel = rowHeight > 11 | ||
const colorBoxWidth = renderColorBoxes ? 15 : 0 | ||
const legendWidth = labelWidth + colorBoxWidth + 5 | ||
const svgOffset = exportSVG ? 10 : 0 | ||
const extraOffset = | ||
svgOffset || (needsScalebar && !rowHeightTooSmallForScalebar ? 50 : 0) | ||
|
||
return sources ? ( | ||
<> | ||
{ | ||
/* 0.25 for hanging letters like g */ | ||
needsFullHeightScalebar ? ( | ||
<RectBg | ||
y={0} | ||
x={extraOffset} | ||
width={legendWidth} | ||
height={(sources.length + 0.25) * rowHeight} | ||
/> | ||
) : null | ||
} | ||
{sources.map((source, idx) => { | ||
const boxHeight = Math.min(20, rowHeight) | ||
return ( | ||
<React.Fragment key={`${source.name}-${idx}`}> | ||
{needsFullHeightScalebar ? null : ( | ||
<RectBg | ||
y={idx * rowHeight + 1} | ||
x={extraOffset} | ||
width={legendWidth} | ||
height={boxHeight} | ||
/> | ||
)} | ||
{source.color ? ( | ||
<RectBg | ||
y={idx * rowHeight + 1} | ||
x={extraOffset} | ||
width={colorBoxWidth} | ||
height={needsCustomLegend ? rowHeight : boxHeight} | ||
color={source.color} | ||
/> | ||
) : null} | ||
{canDisplayLabel ? ( | ||
<text | ||
y={idx * rowHeight + 13} | ||
x={extraOffset + colorBoxWidth + 2} | ||
fontSize={svgFontSize} | ||
> | ||
{source.name} | ||
</text> | ||
) : null} | ||
</React.Fragment> | ||
) | ||
})} | ||
</> | ||
) : null | ||
}) | ||
|
||
export default ColorLegend |
14 changes: 14 additions & 0 deletions
14
plugins/wiggle/src/MultiLinearWiggleDisplay/components/RectBg.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react' | ||
|
||
const RectBg = (props: { | ||
x: number | ||
y: number | ||
width: number | ||
height: number | ||
color?: string | ||
}) => { | ||
const { color = 'rgb(255,255,255,0.8)' } = props | ||
return <rect {...props} fill={color} /> | ||
} | ||
|
||
export default RectBg |
31 changes: 31 additions & 0 deletions
31
plugins/wiggle/src/MultiLinearWiggleDisplay/components/ScoreLegend.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react' | ||
import { measureText, getContainingView } from '@jbrowse/core/util' | ||
import { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view' | ||
import { observer } from 'mobx-react' | ||
|
||
// locals | ||
import { WiggleDisplayModel } from '../models/model' | ||
import RectBg from './RectBg' | ||
|
||
type LGV = LinearGenomeViewModel | ||
|
||
const ScoreLegend = observer(({ model }: { model: WiggleDisplayModel }) => { | ||
const { ticks, scaleType } = model | ||
const { width } = getContainingView(model) as LGV | ||
const legend = | ||
`[${ticks?.values[0]}-${ticks?.values[1]}]` + | ||
(scaleType === 'log' ? ' (log scale)' : '') | ||
const len = measureText(legend, 14) | ||
const padding = 25 | ||
const xpos = width - len - padding | ||
return ( | ||
<> | ||
<RectBg y={0} x={xpos} width={len + 6} height={16} /> | ||
<text y={13} x={xpos}> | ||
{legend} | ||
</text> | ||
</> | ||
) | ||
}) | ||
|
||
export default ScoreLegend |
240 changes: 3 additions & 237 deletions
240
plugins/wiggle/src/MultiLinearWiggleDisplay/components/WiggleDisplayComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.