Skip to content

Commit b7926e0

Browse files
committed
Init add legend
1 parent 0dddd83 commit b7926e0

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

src/index.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,60 @@ class LollipopPlot extends React.Component {
193193
return (this.props.lollipops.find(lollipop => (lollipop.count > this.yMax())) ? '>= ' : '') + this.yMax()
194194
}
195195

196+
renderDomainLegendItems = (uniqueDomains) => {
197+
return uniqueDomains.map((d, idx) => {
198+
return (
199+
<React.Fragment>
200+
<rect
201+
fill={d.color}
202+
x={770}
203+
y={32 + (15 * idx) + 'px'}
204+
width={10}
205+
height={10}
206+
/>
207+
<text
208+
x={785}
209+
y={40 + (15 * idx) + 'px'}
210+
style={{
211+
fontSize: '11px',
212+
fontFamily: 'arial'
213+
}}
214+
>
215+
{d.label}
216+
</text>
217+
</React.Fragment>)
218+
})
219+
}
220+
221+
pfamDomainsLegend = () => {
222+
const {domains} = this.props
223+
const uniqueDomains = Array.from(new Set(domains.map(d => d.label)))
224+
.map(label => ({
225+
label: label,
226+
color: domains.find(d => d.label === label).color
227+
}))
228+
return (
229+
<g>
230+
<text x='770'
231+
y='20'
232+
style={{
233+
fontSize: '12px',
234+
fontWeight: 'bold',
235+
fontFamily: 'arial',
236+
fill: '#333'
237+
}}
238+
>
239+
Pfam domains:
240+
</text>
241+
{this.renderDomainLegendItems(uniqueDomains)}
242+
</g>
243+
)
244+
}
245+
196246
render() {
197247
return (
198248
<React.Fragment>
199-
<svg xmlns='http://www.w3.org/2000/svg' width={this.svgWidth()} height={this.svgHeight()}
249+
<svg xmlns='http://www.w3.org/2000/svg' width={this.svgWidth() + 200} height={this.svgHeight()}
200250
className='lollipop-svgnode'>
201251
<rect
202252
fill='#FFFFFF'
@@ -217,6 +267,7 @@ class LollipopPlot extends React.Component {
217267
/>
218268
{this.lollipops()}
219269
{this.domains()}
270+
{this.pfamDomainsLegend()}
220271
<SVGAxis
221272
key='horz'
222273
x={this.geneX()}

0 commit comments

Comments
 (0)