EqualizerState represents a set of feature list where each feature can vary in intensity and a color/scalar can be associated with. This state is used within the React/Widgets/EqualizerWidget.
The class can be imported with the following command:
The size is used to determine how many features should be used.
The color array will be used by the widget to color each column. If the array of colors is smaller than the size, then the widget will loop through them indefinitely. So that array can contain a single color without issue.
In case a lookupTable is provided, scalars should be provided as well so the colors of each feature can be defined based on those scalars and lookuptable.
getOpacities(): [0…1]
Return an array of the size given at construction time with values between 0 and 1.
getColors(): [‘#fff’]
Return the color table which can be smaller than the actual size of the equalizer. Unless a lookupTable with scalars are used.
onChange(callback):subscription
Register a callback to any possible change of the model. The callback method profile is as follow.
// Fill opacity this.opacities = []; while (this.opacities.length < this.size) { this.opacities.push(-1); }
// Make the updateOpacities a closure to prevent any this issue // when using it as a callback this.updateOpacities = (values) => { let changeDetected = false; for (let i = 0; i < this.size; i++) { changeDetected = changeDetected || this.opacities[i] !== values[i]; this.opacities[i] = values[i]; } if (changeDetected) { this.emit(CHANGE_TOPIC, this); } };
// Make the resetOpacities a closure to prevent any this issue // when using it as a callback this.resetOpacities = () => { const opacityStep = 1.0 / this.size; let opacity = 0.0; let changeDetected = false;
for (let i = 0; i < this.size; i++) { opacity += opacityStep; changeDetected = changeDetected || this.opacities[i] !== opacity; this.opacities[i] = opacity; } if (changeDetected) { this.emit(CHANGE_TOPIC, this); } }; this.resetOpacities(); }