NLeSC / spot

Try the demo
http://www.idarksurvey.com/
Apache License 2.0
21 stars 11 forks source link

Colouring of bubbles in bubbleplot #205

Closed bstienen closed 4 years ago

bstienen commented 4 years ago

When creating a bubble plot, a colour for the bubbles can be configured. If the variable to use for this colouring has 0 as either its minimum or maximum value, there will be no colour difference between the bubbles. See images below for an example of this problem.

Screenshot from 2020-07-16 17-55-33 Screenshot from 2020-07-16 18-01-56

The truth_13tev parameter controlling the colour in these widgets is binary, being either 0 or 1 for each individual data point and the average of this variable changes from bubble to bubble. This behaviour is the result of line 38 to line 43 in src/widgets/views/chartjs2d.js, that control the normalisation of the data for both the bubble colouring and the bubble radius. These lines state

  } else if ((max > 0 && min > 0) || (max < 0 && min < 0)) {
    // linear map v from [min, max] to [0,1]
    norm = function (v) {
      return (v - min) / (max - min);
    };
  }

Changing this to

  } else if ((max > 0 && min >= 0) || (max <= 0 && min < 0)) {
    // linear map v from [min, max] to [0,1]
    norm = function (v) {
      return (v - min) / (max - min);
    };
  }

solves the problem and produces the following (correct) bubble plot in my locally running (and altered) version of spot (data was not identical, hence there are some missing bubbles):

Screenshot from 2020-07-16 18-06-18

I've tested whether this ruins other functionality of the bubble plots and this seems not to be the case. If okay with you, I would like to make a pull request that fixes this error.

bstienen commented 4 years ago

I have taken the liberty to create a pull request (#206) that implements the proposed solution, so that if everyone is okay, nobody has to dive into the code to make the proposed change :-)

bstienen commented 4 years ago

Fixed in PR #206