Skip to content

Commit

Permalink
fix: cease autoplay when maidr is deactivated (outside the plot) (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnanand5 authored Aug 27, 2024
1 parent e88f8cd commit dd564ec
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/js/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class Audio {
panning = 0;
}
} else if (constants.chartType == 'heat') {
if (!plot.data || !plot.data[position.y]) return;
rawFreq = plot.data[position.y][position.x];
rawPanning = position.x;
frequency = this.SlideBetween(
Expand Down
13 changes: 13 additions & 0 deletions src/js/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ class Control {

constants.autoplayId = setInterval(function () {
position.x += step;
if (!plot || !plot.plotData) {
constants.KillAutoplay();
return;
}
if (position.x < 0 || plot.plotData.length - 1 < position.x) {
constants.KillAutoplay();
lockPosition();
Expand Down Expand Up @@ -1724,6 +1728,7 @@ class Control {
}

constants.autoplayId = setInterval(function () {
if (!plot) return;
if (
dir == 'left' ||
dir == 'right' ||
Expand Down Expand Up @@ -2499,6 +2504,10 @@ class Control {

constants.autoplayId = setInterval(function () {
position.x += step;
if (!plot || !plot.plotData) {
constants.KillAutoplay();
return;
}
if (position.x < 0 || plot.plotData.length - 1 < position.x) {
constants.KillAutoplay();
lockPosition();
Expand Down Expand Up @@ -2872,6 +2881,10 @@ class Control {
dir == 'reverse-right'
) {
position.x += step;
if (!plot || !plot.plotData) {
constants.KillAutoplay();
return;
}
if (position.x < 0 || plot.plotData.length - 1 < position.x) {
constants.KillAutoplay();
lockPosition();
Expand Down
2 changes: 1 addition & 1 deletion src/js/heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class HeatMapRect {
var rect = document.createElementNS(svgns, 'rect');
rect.setAttribute('id', 'highlight_rect');
rect.setAttribute('x', this.x);
rect.setAttribute('y', this.y);
rect.setAttribute('y', this.y === undefined ? 0 : this.y);
rect.setAttribute('width', this.width);
rect.setAttribute('height', this.height);
rect.setAttribute('stroke', constants.colorSelected);
Expand Down
14 changes: 12 additions & 2 deletions src/js/scatterplot.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ class ScatterPlot {
constants.sepPlayId = setInterval(
function () {
// play this tone
if (!audio || !audio.playTone) {
clearInterval(constants.sepPlayId);
return;
}
audio.playTone();

// and then set up for the next one
Expand All @@ -477,6 +481,10 @@ class ScatterPlot {
); // play all tones at the same time
} else if (constants.chartType == 'smooth') {
// best fit smooth layer
if (!audio || !audio.playTone) {
clearInterval(constants.sepPlayId);
return;
}
audio.playTone();
}
}
Expand Down Expand Up @@ -520,7 +528,7 @@ class ScatterPlot {
if (elIndex > -1) {
data = singleMaidr.data[elIndex];
} else {
data = singleMaidr.data
data = singleMaidr.data;
}
if (xyFormat == 'object') {
for (let i = 0; i < data.length; i++) {
Expand Down Expand Up @@ -714,7 +722,9 @@ class Layer0Point {
plot.plotPoints[this.circleIndex[i]] instanceof SVGUseElement ||
plot.plotPoints[this.circleIndex[i]] instanceof SVGCircleElement
) {
y = plot.plotPoints[this.circleIndex[i]].getAttribute(plot.prefix + 'y');
y = plot.plotPoints[this.circleIndex[i]].getAttribute(
plot.prefix + 'y'
);
}

point.setAttribute('cy', y);
Expand Down

0 comments on commit dd564ec

Please sign in to comment.