Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG?] Inconsistent Behavior of Slider's _ratingToPos in PsychoJS vs PsychoPy #603

Open
const7 opened this issue Oct 8, 2024 · 0 comments

Comments

@const7
Copy link

const7 commented Oct 8, 2024

I've encountered inconsistent/incorrect behavior with the _ratingToPos function in PsychoJS compared to PsychoPy.

Possible Bug

In PsychoJS, _ratingToPos only returns the correct x or y position, with the other coordinate always being 0. If the slider's position is offset from the center (not at [0,0]), the resulting position returned by _ratingToPos will be incorrect.

psychojs/src/visual/Slider.js

Lines 1354 to 1403 in 9265fd8

_ratingToPos(ratings)
{
const range = this._ticks[this._ticks.length - 1] - this._ticks[0];
if (this._isHorizontal())
{
// in compact mode the circular markers of RADIO sliders must fit within the width:
if (this._compact && this._style.indexOf(Slider.Style.RADIO) > -1)
{
return ratings.map((v) => [
((v - this._ticks[0]) / range) * (this._size[0] - this._tickSize[1] * 2)
- (this._size[0] / 2) + this._tickSize[1],
0,
]);
}
else if (this._style.indexOf(Slider.Style.SLIDER) > -1)
{
return ratings.map((v) => [
((v - this._ticks[0]) / range - 0.5) * (this._size[0] - this._markerSize[0]),
0,
]);
}
else
{
return ratings.map((v) => [((v - this._ticks[0]) / range - 0.5) * this._size[0], 0]);
}
}
else
{
// in compact mode the circular markers of RADIO sliders must fit within the height:
if (this._compact && this._style.indexOf(Slider.Style.RADIO) > -1)
{
return ratings.map((v) => [
0,
((v - this._ticks[0]) / range) * (this._size[1] - this._tickSize[0] * 2)
- (this._size[1] / 2) + this._tickSize[0],
]);
}
else if (this._style.indexOf(Slider.Style.SLIDER) > -1)
{
return ratings.map((v) => [
0,
((v - this._ticks[0]) / range - 0.5) * (this._size[1] - this._markerSize[1]),
]);
}
else
{
return ratings.map((v) => [0, (1.0 - (v - this._ticks[0]) / range - 0.5) * this._size[1]]);
}
}
}

This issue does not occur in PsychoPy, where both x and y coordinates are correctly computed based on the slider's position.
https://github.com/psychopy/psychopy/blob/fa753ec368764989a557e57660adb5c8486c49da/psychopy/visual/slider.py#L586-L610

Feature vs Bug

In PsychoPy, _ratingToPos accepts both single numeric values and array-like inputs for ratings. However, in PsychoJS, the function only accepts arrays. I'm not sure if it's intentional or some other reason.

I would be happy to submit a PR to fix the first issue if you're open to that. As for the second point, perhaps it could be discussed further to determine whether this difference in input handling should be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant