[gnome-weather] Range hourly chart's temperature values from the lowest to the highest



commit 54d6e0745659ff3d4b901cedd257c4186e681137
Author: Vitaly Dyachkov <obyknovenius me com>
Date:   Tue Aug 25 17:50:24 2020 +0200

    Range hourly chart's temperature values from the lowest to the highest
    
    Previously, hourly chart's temperature values were ranged from 0 to the
    highest. New ranging should make temperature changes easier to see and
    should improve responsiveness.

 src/app/hourlyForecast.js | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/src/app/hourlyForecast.js b/src/app/hourlyForecast.js
index ad9511b..9e05a1b 100644
--- a/src/app/hourlyForecast.js
+++ b/src/app/hourlyForecast.js
@@ -136,11 +136,12 @@ var HourlyForecastFrame = GObject.registerClass(class ForecastFrame extends Gtk.
     vfunc_draw(cr) {
         super.vfunc_draw(cr);
 
-        let hourlyInfo = this._hourlyInfo;
+        const temps = this._hourlyInfo.map(info => Util.getTemp(info));
 
-        let temps = hourlyInfo.map(info => Util.getTemp(info));
-        let maxTemp = Math.max(...temps);
-        temps = temps.map(t => t / maxTemp);
+        const maxTemp = Math.max(...temps);
+        const minTemp = Math.min(...temps);
+
+        const values = temps.map(t => (t - minTemp) / (maxTemp - minTemp));
 
         let width = this.get_allocated_width();
         let height = this.get_allocated_height();
@@ -160,17 +161,17 @@ var HourlyForecastFrame = GObject.registerClass(class ForecastFrame extends Gtk.
         Gdk.cairo_set_source_rgba(cr, backgroundColor);
 
         let x = 0;
-        cr.moveTo (x, top_padding + ((1 - temps[0]) * canvas_height));
+        cr.moveTo (x, top_padding + ((1 - values[0]) * canvas_height));
 
         x += entryWidth / 2;
-        cr.lineTo(x, top_padding + ((1 - temps[0]) * canvas_height));
+        cr.lineTo(x, top_padding + ((1 - values[0]) * canvas_height));
 
-        for (let i = 1; i < temps.length; i++) {
+        for (let i = 1; i < values.length; i++) {
             x += entryWidth + separatorWidth;
-            cr.lineTo(x, top_padding + ((1 - temps[i]) * canvas_height));
+            cr.lineTo(x, top_padding + ((1 - values[i]) * canvas_height));
         }
 
-        cr.lineTo(width, top_padding + ((1 - temps[temps.length - 1]) * canvas_height));
+        cr.lineTo(width, top_padding + ((1 - values[values.length - 1]) * canvas_height));
         cr.strokePreserve();
 
         cr.lineTo(width, height);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]