Last active
July 11, 2017 17:08
-
-
Save ahmedam55/a41adb67a6fbf7538a2d995e36891dea to your computer and use it in GitHub Desktop.
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
import { h, render, Component } from 'preact'; | |
class App extends Component { | |
state = { | |
data: [99, 44, 11, 55, 33, 115, 4] | |
} | |
_shuffuleArray(array) { | |
var j, temp, i; | |
for (i = array.length; i; i--) { | |
j = Math.floor(Math.random() * i); | |
temp = array[i - 1]; | |
array[i - 1] = array[j]; | |
array[j] = temp; | |
} | |
return array; | |
} | |
shuffule = () => this.setState({ data: this._shuffuleArray(this.state.data) }) | |
render(props, { data }) { | |
return ( | |
<main> | |
<Chart data={data}/> | |
<button onClick={this.shuffule}>Suffule</button> | |
</main> | |
) | |
} | |
} | |
class Chart extends Component { | |
render({ data }) { | |
return ( | |
<svg width="420" height="120"> | |
{data.map((item ,i)=> | |
<rect | |
width="40" | |
y={120 - item} | |
x="50" | |
height={item} | |
transform={`translate(${43 * i},0)`} | |
/> | |
)} | |
</svg> | |
) | |
} | |
} | |
render(<App/>, document.body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment