These are the different categories I have:
var BMICategories = [
{color:'#F43E3E',min:40,max:200,name:'morbid or massive obesity'},
{color:'#F4B4B4',min:35,max:40,name:'severe obesity'},
{color:'#FAE9CA',min:30,max:35,name:'moderate obesity'},
{color:'#FFFFD4',min:25,max:30,name:'overweight'},
{color:'#E9FFDA',min:18.5,max:25,name:'healthy weight'},
{color:'#FFFFD4',min:16.5,max:18.5,name:'underweight'},
{color:'#F43E3E',min:0,max:16.5,name:'famine'}
];
(These represent Body Mass Index (BMI), but in French (IMC))
The BMI range goes from 0 to 200, with each category having a different width.
I am trying to define a scale using d3 where the domain is BMI and the range is color. The colors are discrete values, while the domain is continuous.
I want to input the weight into the scale and retrieve the corresponding color. Ideally, I would like to get the object containing color, name, min, and max based on the weight provided.
If you're interested in trying it out, here is the BMI function:
function calculateBMI(weight) {
return weight / (height * height);
}
Given that ranges overlap, how can I set the minimum to be either excluded or included, and the maximum to be the opposite?
Thank you for your help!
If the scale receives BMI instead of weight, I can wrap my scale in a function to handle the conversion.