Skip to content

Instantly share code, notes, and snippets.

@jackparmer
Created August 27, 2018 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackparmer/80238aee1b8585619f33e73f426880f1 to your computer and use it in GitHub Desktop.
Save jackparmer/80238aee1b8585619f33e73f426880f1 to your computer and use it in GitHub Desktop.
import React, { ReactDOM, Component } from 'react';
import logo from './logo.svg';
import './App.css';
import Ideogram from 'ideogram';
import ReactIdeogram from './react-ideogram.js'
class App extends Component {
constructor() {
super();
this.state = {
organism: 'mouse',
showBandLabels: false,
orientation: 'vertical',
container: '#ideogram-container',
// dataDir: './ideogram/data/bands/native/'
dataDir: 'https://unpkg.com/ideogram@1.3.0/dist/data/bands/native/'
};
}
clearDiv = () => {
let container = document.getElementById('ideogram-container');
while (container.hasChildNodes()) {
container.removeChild(container.lastChild);
}
console.log('cleared container', container, container.hasChildNodes());
}
drawIdeo = (organismType) => {
this.clearDiv();
var config = {
organism: 'mouse',
// orientation: 'horizontal',
showBandLabels: true,
container: '#ideogram-container'
};
if (organismType === 'human') {
config = {
container: '#ideogram-container',
organism: 'human'
};
}
setTimeout(function() {
new Ideogram(config);
}, 100);
}
render() {
return (
<div className="App">
<h4>state: {JSON.stringify(this.state)}</h4>
<p>Change component state (React way)</p>
<button onClick={e => this.setState({organism: 'mouse'})}>Mouse</button>
<button onClick={e => this.setState({organism: 'human'})}>Human</button>
<button onClick={e => this.setState({orientation: 'vertical'})}>Vert</button>
<button onClick={e => this.setState({orientation: 'horizontal'})}>Horiz</button>
<button onClick={e => this.setState({showBandLabels: true})}>Bands</button>
<button onClick={e => this.setState({showBandLabels: false})}>No Bands</button>
<p>Redraw without state change (vanilla JS way)</p>
<button onClick={e => this.clearDiv()}>Clear</button>
<button onClick={e => this.drawIdeo('mouse')}>Draw Mouse</button>
<button onClick={e => this.drawIdeo('human')}>Draw Human</button>
<ReactIdeogram config={this.state} />
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment