Last active
December 4, 2017 23:06
-
-
Save mathisonian/2e0a300b1ca58e7ff71c23140209be7e to your computer and use it in GitHub Desktop.
Example stepper / play / pause
This file contains hidden or 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
const React = require('react'); | |
const D3Component = require('idyll-d3-component'); | |
const d3 = require('d3'); | |
const size = 600; | |
class CustomD3Component extends D3Component { | |
initialize(node, props) { | |
const svg = this.svg = d3.select(node).append('svg').attr('width', 500).attr('height', 500); | |
this.text = svg.append('text').style('font-size', 30).style('fill', 'blue').attr('dx', 100).attr('dy', 100).text(props.index); | |
} | |
update(props) { | |
if (props.playing) { | |
setTimeout(() => { | |
this.props.updateProps({ index: props.index + 1 }) | |
}, 250); | |
} else { | |
} | |
this.text.text(props.index); | |
} | |
} | |
module.exports = CustomD3Component; |
This file contains hidden or 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
[var name:"isPlaying" value:false /] | |
[var name:"index" value:0 /] | |
[button onClick:` isPlaying = !isPlaying ` ][display value:` isPlaying ? "Pause" :"Play" ` /][/button] | |
[button onClick:` index = index - 1 ` ]previous[/button] | |
[button onClick:` index = index + 1 ` ]next[/button] | |
[Range value:index min:0 max:10 /] | |
[display var:index /] | |
[br /] | |
[display var:isPlaying /] | |
[CustomD3Component index:index playing:isPlaying /] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment