I played around a bit with this code for wind colors in the Belchertown 
skin.  I too had some difficulty with the colors and made a few changes.  
Please see snippet below.  I basically had to reverse order the if/else if 
code to put the higher wind speed first because the else if would always 
stop a the first >= and not go any further.  Your windSpeeds/windGusts and 
colors may not match mine so adjust to taste.

// Change the color of the Windspeed variable according to US-EPA standards
// (adjusted to match skin colors better)
function get_windSpeed_color(windSpeed, returnColor = false) {
    windSpeed = parseFloat(windSpeed).toFixed(1); // Convert back to 
decimal lit
    if (windSpeed <= 1.1) {
        var windSpeed_color = "rgba(18,120,200,1)";
    } else if (windSpeed >= 24.0) {
        var windSpeed_color = "rgba(159,0,197,1)";
    } else if (windSpeed >= 18.0) {
        var windSpeed_color = "rgba(255,69,0,1)";
    } else if (windSpeed >= 12.4) {
        var windSpeed_color = "rgba(255,127,0,1)";
    } else if (windSpeed >= 7.5) {
        var windSpeed_color = "rgba(255,174,0,1)";
    } else if (windSpeed >= 3.7) {
        var windSpeed_color = "rgba(113,188,60,1)";
    } else if (windSpeed >= 1.2) {
        var windSpeed_color = "rgba(31,175,221,1)";
    }
    // Return the color value if requested, otherwise just set the div color
    if (returnColor) {
        return windSpeed_color;
    } else {
        jQuery(".curwindspeed").css("color", windSpeed_color);
    }

}

// Change the color of the aqi variable according to US-EPA standards
// (adjusted to match skin colors better)
function get_windGust_color(windGust, returnColor = false) {
    windGust = parseFloat(windGust).toFixed(1); // Convert back to decimal 
liter
    if (windGust <= 1.1) {
        var windGust_color = "rgba(18,120,200,1)";
    } else if (windGust >= 24.0) {
        var windGust_color = "rgba(159,0,197,1)";
    } else if (windGust >= 18.0) {
        var windGust_color = "rgba(255,69,0,1)";
    } else if (windGust >= 12.4) {
        var windGust_color = "rgba(255,127,0,1)";
    } else if (windGust >= 7.5) {
        var windGust_color = "rgba(255,174,0,1)";
    } else if (windGust >= 3.7) {
        var windGust_color = "rgba(113,188,60,1)";
    } else if (windGust >= 1.2) {
        var windGust_color = "rgba(31,175,221,1)";
    }
    // Return the color value if requested, otherwise just set the div color
    if (returnColor) {
        return windGust_color;
    } else {
        jQuery(".curwindgust").css("color", windGust_color);
    }
}

cheers Jim
On Tuesday, May 17, 2022 at 7:54:26 a.m. UTC-4 [email protected] wrote:

> Why are you formatting the windspeed as string and then (multiple times) 
> converting it to float? 
>
> This may be unrelated to your problem.
>
> I do notice that the outTemp coloring is done with the string value and 
> converted to the real value in the coloration function itself. Could the 
> windspeed float variable be going out of scope? I don't usually write 
> Javascript so, sorry I'm not much help.
>
> On Sun, May 15, 2022 at 3:24 AM Meteo Oberwallis <[email protected]> 
> wrote:
>
>> Hi Guys
>> I have a problem with the wind color in Belchertown. I managed to display 
>> the wind in color as well. Only it doesn't always do so after visiting or 
>> refreshing the Belchertown page. I've attached my changes. What could it 
>> be? I have 2 pictures attached. At view a is at page load and also a few 
>> seconds later. At some point the color will change (see appendix b). But 
>> that is always different.
>>
>> This is my Code:
>>
>> // Change the color of the Windspeed variable according to US-EPA 
>> standards
>> // (adjusted to match skin colors better)
>> function get_windSpeed_color(windSpeed, returnColor = false) {
>>     if (windSpeed <= 0) {
>>         var windSpeed_color = "rgba(0,255,0,1)";
>>     } else if (windSpeed >= 19.9) {
>>         var windSpeed_color = "rgba(126,255,0,1)";
>>     } else if (windSpeed >= 39.9) {
>>         var windSpeed_color = "rgba(0,255,0,1)";
>>     } else if (windSpeed >= 59.9) {
>>         var windSpeed_color = "rgba(255,128,0,1)";
>>     } else if (windSpeed >= 79.9) {
>>         var windSpeed_color = "rgba(255,0,0,1)";
>>     } else if (windSpeed >= 99.9) {
>>         var windSpeed_color = "rgba(255,0,120,1)";
>>     } else if (windSpeed >= 118.0) {
>>         var windSpeed_color = "rgba(255,1,113,1)";
>>     }
>>
>>     // Return the color value if requested, otherwise just set the div 
>> color
>>     if (returnColor) {
>>         return windSpeed_color;
>>     } else {
>>         jQuery(".curwindspeed").css("color", windSpeed_color);
>>     }
>> }
>>
>> and
>> // Windspeed Metric
>> if (data.hasOwnProperty("windSpeed_kph")) {
>>         windSpeed = 
>> parseFloat(parseFloat(data["windSpeed_kph"])).toLocaleString("$system_locale_js",
>>  
>> {minimumFractionDigits: unit_rounding_array["windSpeed"], 
>> maximumFractionDigits: unit_rounding_array["windSpeed"]});
>>         get_windSpeed_color(windSpeed);
>>         jQuery(".curwindspeed").html(windSpeed);
>>
>> I have the complete text as Attachment new_belchertown_js
>>
>> Thx for you help
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "weewx-user" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/weewx-user/1a07d243-7268-48d9-8bdf-a9649df4ac95n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/weewx-user/1a07d243-7268-48d9-8bdf-a9649df4ac95n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Peter Quinn
> (415)794-2264 <(415)%20794-2264>
>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/e1b2e2e2-0f6b-4e0f-9e23-4dba676c3565n%40googlegroups.com.

Reply via email to