Skip to content

Commit 6659385

Browse files
committed
Hook up random colors to Bars visualizer
1 parent 22ae9d9 commit 6659385

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"chroma-js": "^2.0.2",
2323
"gradient-color": "^2.0.1",
2424
"lodash": "^4.17.11",
25+
"randomcolor": "^0.5.3",
2526
"react": "^16.7.0",
2627
"react-dom": "^16.7.0",
2728
"react-redux": "^6.0.0",

src/components/Visualizer/Bars/Bars.component.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,20 @@ class Bars extends Base {
7474
var sampleAvgs = sampleArray(waveform, numOfBars, 1);
7575
var bars = this.bars;
7676

77-
78-
7977
for (var j = 0; j < numOfBars; j++) {
80-
var magnitude = (Math.floor(sampleAvgs[j]*1000)/1000);
81-
bars[j].parentNode.style[prefix.css + 'transform'] = ["scaleY(", magnitude, ") translate3d(0,0,0)"].join("");
78+
const magnitude = Math.floor(sampleAvgs[j]*1000)/1000
79+
80+
const bar = bars[j]
81+
82+
if (bar) {
83+
bar.parentNode
84+
.style[prefix.css + 'transform'] =
85+
[
86+
"scaleY(",
87+
magnitude,
88+
") translate3d(0,0,0)"
89+
].join("")
90+
}
8291
}
8392
}
8493

src/components/Visualizer/Visualizer.component.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import React, { Component } from 'react'
2+
import randomColor from 'randomcolor'
23

34
import Bars from './Bars'
45

6+
const color1 = randomColor()
7+
const color2 = randomColor()
8+
59
class Visualizer extends Component {
610

711
constructor(props) {
812
super(props)
913
}
1014

1115
render() {
12-
return <Bars color1={'rgb(255,0,0)'} color2={'rgb(255,255,0)'}/>
16+
return <Bars color1={color1} color2={color2}/>
1317
}
1418
}
1519

0 commit comments

Comments
 (0)