Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Legend To Potential Pools Diagram using new "DiagramLegends" component - Fixes Issue #38 #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions components/DiagramLegend.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as d3 from 'd3';
import React from 'react';

class DiagramLegend extends React.Component {

componentDidMount() {
this.root = d3.select(`svg#${this.props.id}`)

let groupYCoord = 0
this.props.legendData.forEach((legendData)=>{
let group = this.root.append('g');
group.attr('transform', `translate(0, ${groupYCoord})`)
.append('rect')
.attr('style', `fontSize: 15px; stroke-width: 1; stroke: #808080; fill: ${legendData.fillColor}; `)
.attr('width', 15)
.attr('height', 15)
.attr('x', 0)
.attr('y', 0)
.attr('r', 6)

group.append('text')
.text(legendData.label)
.attr('alignment-baseline', 'middle')
.attr('x', 25)
.attr('y', 8.5)
if(legendData.marker){
group.append('text')
.text(legendData.marker)
.attr('style', `fontSize: 15px; fill: ${legendData.markerFillColor}; `)
.attr('x', 2.5)
.attr('y', 12.5)
// console.log("Marker exists for ", legendData.label );
}

groupYCoord+=25;
})

}

render() {
return (
<svg style={{...this.props.style}} id={this.props.id}></svg>
)
}
}


export default DiagramLegend;
32 changes: 32 additions & 0 deletions pages/spatial-pooling.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@ import CompetitionStackRank from '../components/diagrams/CompetitionStackRank'
import StreamingScalarDiagram from '../components/diagrams/StreamingScalarDiagram'
// import DiagramStub from '../components/diagrams/DiagramStub'

//Legends
import PotentialPoolsLegend from '../components/DiagramLegend';
let legendData = [
{
fillColor: '#FFF0A6',
label: 'Potential Pool',
marker: ''
},
{
fillColor: '#fff',
label: 'Feed Forward Input',
marker: ''
},
{
fillColor: '#BFBFBF',
label: 'Ignored Input',
marker: '✘',
markerFillColor: 'white'

},
{
fillColor: '#FFF0A6',
label: 'Observed Input',
marker: '✓',
markerFillColor: 'green'
},
]

var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

const { BoundedScalarEncoder, CyclicEncoder, DayOfWeekCategoryEncoder, WeekendEncoder } = simplehtm.encoders
Expand Down Expand Up @@ -430,6 +458,10 @@ class SpatialPooling extends React.Component {
selectedMinicolumn={this.state.selectedMinicolumn}
onUpdate={selectedMinicolumn => this.setState({ selectedMinicolumn })}
/>
<PotentialPoolsLegend
style={{marginLeft: diagramWidth / 2}}
legendData={legendData}
id="potentialPoolLegend"/>
<figcaption className="figure-caption">
<span><a href="#potentialPools">¶</a>Figure 2:</span> Potential Pools.
</figcaption>
Expand Down