Skip to content

Commit

Permalink
Dense Hourly weather with graphic
Browse files Browse the repository at this point in the history
  • Loading branch information
Gr3q committed Mar 31, 2023
1 parent 2dc3b9f commit c57b274
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 53 deletions.
18 changes: 18 additions & 0 deletions .typescript-declarations/manual-overrides/cairo-1.0.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ declare namespace imports.gi.cairo {
*/
lineTo(x: number, y: number): void

/**
* Begin a new sub-path. After this call the current point will be (x, y). Since 1.0
* @param x the X coordinate of the new position
* @param y the Y coordinate of the new position
*/
moveTo(x: number, y: number): void;

/**
* Adds a cubic Bézier spline to the path from the current point to position (x3, y3) in user-space coordinates, using (x1, y1) and (x2, y2) as the control points. After this call the current point will be (x3, y3). If there is no current point before the call to cairo_curve_to() this function will behave as if preceded by a call to cairo_move_to(cr, x1, y1). Since 1.0
* @param x1 the X coordinate of the first control point
* @param y1 the Y coordinate of the first control point
* @param x2 the X coordinate of the second control point
* @param y2 the Y coordinate of the second control point
* @param x3 the X coordinate of the end of the curve
* @param y3 the Y coordinate of the end of the curve
*/
curveTo(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): void;


/**
* Sets the current line width within the Context. The line width value specifies the diameter of a pen that is circular in user space, (though device-space pen may be an ellipse in general due to scaling/shear/rotation of the CTM).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
},
"forecastHours": {
"type": "spinbutton",
"default": 48,
"default": 24,
"min": 3,
"max": 168,
"units": "hours",
Expand Down
4 changes: 2 additions & 2 deletions weather@mockturtl/files/weather@mockturtl/3.8/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@

.hourly-data {
text-align: center;
/* padding: 0px 5px; */
padding: 0px 5px;
}

.hourly-box {
margin: 10px 10px 5px 10px;
}

.hourly-icon {
padding: 5px 20px 5px 20px;
/* padding: 5px 20px 5px 20px; */
}

.location-selector {
Expand Down
74 changes: 65 additions & 9 deletions weather@mockturtl/files/weather@mockturtl/3.8/weather-applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -16481,6 +16481,7 @@ class UIHourlyForecasts {
}
constructor(app, menu) {
this.hourlyForecasts = [];
this.hourlyForecastData = [];
this.hourlyContainers = [];
this.hourlyToggled = false;
this.availableWidth = null;
Expand Down Expand Up @@ -16554,22 +16555,32 @@ class UIHourlyForecasts {
}
}
Display(forecasts, config, tz) {
var _a;
var _a, _b, _c;
if (!forecasts || !this.hourlyForecasts)
return true;
if (this.hourlyForecasts.length > forecasts.length) {
this.Rebuild(this.app.config, this.app.config.textColorStyle, forecasts.length);
}
this.hourlyForecastDates = [];
this.hourlyForecastData = [];
const max = Math.min(forecasts.length, this.hourlyForecasts.length);
for (let index = 0; index < max; index++) {
const hour = forecasts[index];
const ui = this.hourlyForecasts[index];
this.hourlyForecastDates.push(hour.date);
this.hourlyForecastData.push(hour);
const temp = TempToUserConfig(hour.temp, config, false);
ui.Hour.text = GetHoursMinutes(hour.date, config.currentLocale, config._show24Hours, tz, config._shortHourlyTime);
ui.Temperature.text = (_a = TempToUserConfig(hour.temp, config)) !== null && _a !== void 0 ? _a : "";
ui.Temperature.text = temp ? `${temp}°` : "";
ui.Icon.icon_name = (config._useCustomMenuIcons) ? hour.condition.customIcon : WeatherIconSafely(hour.condition.icons, config.IconType);
ui.Summary.text = hour.condition.main;
global.log((_a = hour.precipitation) === null || _a === void 0 ? void 0 : _a.chance);
if (((_c = (_b = hour.precipitation) === null || _b === void 0 ? void 0 : _b.chance) !== null && _c !== void 0 ? _c : 0) >= 40) {
ui.Icon.style = "color: #0055ff";
}
else {
ui.Icon.style = "";
}
ui.PrecipPercent.text = this.GeneratePrecipitationChance(hour.precipitation, config);
ui.PrecipVolume.text = this.GeneratePrecipitationVolume(hour.precipitation, config);
}
Expand Down Expand Up @@ -16679,8 +16690,6 @@ class UIHourlyForecasts {
requiredWidth = hourWidth;
if (requiredWidth < iconWidth)
requiredWidth = iconWidth;
if (requiredWidth < summaryWidth)
requiredWidth = summaryWidth;
if (requiredWidth < temperatureWidth)
requiredWidth = temperatureWidth;
if (requiredWidth < precipitationWidth)
Expand All @@ -16697,6 +16706,13 @@ class UIHourlyForecasts {
const hours = availableHours !== null && availableHours !== void 0 ? availableHours : this.app.GetMaxHourlyForecasts();
this.hourlyForecasts = [];
this.hourlyContainers = [];
const canvas = new imports.gi.St.DrawingArea();
const grid = new imports.gi.Clutter.GridLayout();
const actor = new imports.gi.Clutter.Actor({ layout_manager: grid });
grid.attach(canvas, 1, 1, 1, 1);
const parent = new uiHourlyForecasts_BoxLayout();
grid.attach(parent, 1, 1, 1, 1);
this.container.add(actor, { expand: true, x_fill: true, y_fill: true });
for (let index = 0; index < hours; index++) {
const box = new uiHourlyForecasts_BoxLayout({ vertical: true, style_class: "hourly-box-item" });
this.hourlyContainers.push(box);
Expand All @@ -16716,27 +16732,67 @@ class UIHourlyForecasts {
this.hourlyForecasts[index].PrecipVolume.clutter_text.set_line_wrap(true);
box.add_child(this.hourlyForecasts[index].Hour);
box.add_child(this.hourlyForecasts[index].Icon);
box.add(this.hourlyForecasts[index].Summary, { expand: true, x_fill: true });
box.add_child(this.hourlyForecasts[index].Temperature);
if ((_a = this.app.Provider) === null || _a === void 0 ? void 0 : _a.supportHourlyPrecipChance)
box.add_child(this.hourlyForecasts[index].PrecipPercent);
if ((_b = this.app.Provider) === null || _b === void 0 ? void 0 : _b.supportHourlyPrecipVolume)
box.add_child(this.hourlyForecasts[index].PrecipVolume);
this.container.add(box, {
parent.add(box, {
x_fill: true,
x_align: uiHourlyForecasts_Align.MIDDLE,
y_align: uiHourlyForecasts_Align.MIDDLE,
y_fill: true,
expand: true
});
}
canvas.connect("repaint", (owner) => {
var _a, _b;
if (this.availableWidth == null)
return;
const ctx = owner.get_context();
const maxTemp = this.hourlyForecastData.map(x => x.temp).reduce((p, c) => Math.max(p !== null && p !== void 0 ? p : 0, c !== null && c !== void 0 ? c : 0));
const minTemp = this.hourlyForecastData.map(x => x.temp).reduce((p, c) => Math.min(p !== null && p !== void 0 ? p : 0, c !== null && c !== void 0 ? c : 0));
const totalHeight = this.hourlyContainers[0].height;
const itemWidth = this.hourlyContainers[0].width;
const totalWidth = this.hourlyContainers.length * itemWidth;
ctx.setLineWidth(3);
ctx.setSourceRGBA(1, 0, 0, 0.5);
const tension = 0.5;
let points = [];
let precipitation = [];
for (let i = 0; i < this.hourlyContainers.length; i++) {
const data = this.hourlyForecastData[i];
if (data.temp == null)
continue;
const ratio = ((data.temp - minTemp) / (maxTemp - minTemp)) * (totalHeight / 2);
const height = (totalHeight / 2) - ratio;
const midX = itemWidth * i + (itemWidth / 2);
const midY = (totalHeight / 2);
points.push({ x: midX, y: height });
precipitation.push(((_b = (_a = data.precipitation) === null || _a === void 0 ? void 0 : _a.volume) !== null && _b !== void 0 ? _b : 0) * 20);
}
ctx.moveTo(points[0].x, points[0].y);
for (let i = 0; i < points.length; i++) {
const p = points[i];
ctx.lineTo(p.x, p.y + 2);
}
ctx.stroke();
ctx.setSourceRGBA(0, 0.5, 1, 0.5);
for (let i = 0; i < precipitation.length; i++) {
const element = precipitation[i];
const point = points[i];
ctx.rectangle(point.x - 5, totalHeight - element, 10, element);
ctx.fill();
}
return true;
});
}
GeneratePrecipitationVolume(precip, config) {
if (!precip)
return "";
let precipitationText = "";
if (!!precip.volume && precip.volume > 0) {
precipitationText = `${MillimeterToUserUnits(precip.volume, config.DistanceUnit)}${config.DistanceUnit == "metric" ? _("mm") : _("in")}`;
if (!!precip.volume && precip.volume >= 0.1) {
precipitationText = `${MillimeterToUserUnits(precip.volume, config.DistanceUnit)}`;
}
return precipitationText;
}
Expand All @@ -16746,7 +16802,7 @@ class UIHourlyForecasts {
let precipitationText = "";
if (!!precip.chance) {
precipitationText = (NotEmpty(precipitationText)) ? (precipitationText + ", ") : "";
precipitationText += (Math.round(precip.chance).toString() + "%");
precipitationText += ((Math.round(precip.chance / 10) * 10).toString() + "%");
}
return precipitationText;
}
Expand Down
68 changes: 34 additions & 34 deletions weather@mockturtl/files/weather@mockturtl/po/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-03-29 19:42+0100\n"
"POT-Creation-Date: 2023-03-31 09:19+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -18,65 +18,65 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"

#: 3.0/applet.js:166 3.0/applet.js:426 3.0/applet.js:2131
#: 3.8/weather-applet.js:17427
#: 3.8/weather-applet.js:17483
msgid "Error"
msgstr ""

#: 3.0/applet.js:167 3.0/applet.js:169 3.0/applet.js:171 3.0/applet.js:174
#: 3.0/applet.js:177 3.0/applet.js:178 3.0/applet.js:179 3.0/applet.js:180
#: 3.8/weather-applet.js:17428 3.8/weather-applet.js:17430
#: 3.8/weather-applet.js:17432 3.8/weather-applet.js:17435
#: 3.8/weather-applet.js:17438 3.8/weather-applet.js:17439
#: 3.8/weather-applet.js:17440 3.8/weather-applet.js:17441
#: 3.8/weather-applet.js:17484 3.8/weather-applet.js:17486
#: 3.8/weather-applet.js:17488 3.8/weather-applet.js:17491
#: 3.8/weather-applet.js:17494 3.8/weather-applet.js:17495
#: 3.8/weather-applet.js:17496 3.8/weather-applet.js:17497
msgid "Service Error"
msgstr ""

#: 3.0/applet.js:168 3.8/weather-applet.js:17429
#: 3.0/applet.js:168 3.8/weather-applet.js:17485
msgid "Incorrect API Key"
msgstr ""

#: 3.0/applet.js:170 3.8/weather-applet.js:17431
#: 3.0/applet.js:170 3.8/weather-applet.js:17487
msgid "Incorrect Location Format"
msgstr ""

#: 3.0/applet.js:172 3.8/weather-applet.js:17433
#: 3.0/applet.js:172 3.8/weather-applet.js:17489
msgid "Key Blocked"
msgstr ""

#: 3.0/applet.js:173 3.8/weather-applet.js:17434
#: 3.0/applet.js:173 3.8/weather-applet.js:17490
msgid "Can't find location"
msgstr ""

#: 3.0/applet.js:175 3.8/weather-applet.js:17436
#: 3.0/applet.js:175 3.8/weather-applet.js:17492
msgid "No Api Key"
msgstr ""

#: 3.0/applet.js:176 3.8/weather-applet.js:17437
#: 3.0/applet.js:176 3.8/weather-applet.js:17493
msgid "No Location"
msgstr ""

#: 3.0/applet.js:181 3.8/weather-applet.js:17442
#: 3.0/applet.js:181 3.8/weather-applet.js:17498
msgid "Missing Packages"
msgstr ""

#: 3.0/applet.js:182 3.8/weather-applet.js:17443
#: 3.0/applet.js:182 3.8/weather-applet.js:17499
msgid "Location not covered"
msgstr ""

#: 3.0/applet.js:193 3.0/applet.js:378 3.8/weather-applet.js:9706
msgid "Weather Applet"
msgstr ""

#: 3.0/applet.js:217 3.8/weather-applet.js:17738
#: 3.0/applet.js:217 3.8/weather-applet.js:17794
msgid "..."
msgstr ""

#: 3.0/applet.js:218 3.8/weather-applet.js:17739
#: 3.0/applet.js:218 3.8/weather-applet.js:17795
msgid "Click to open"
msgstr ""

#: 3.0/applet.js:232 3.0/applet.js:1244 3.8/weather-applet.js:16112
#: 3.8/weather-applet.js:17742
#: 3.8/weather-applet.js:17798
msgid "Refresh"
msgstr ""

Expand All @@ -99,12 +99,12 @@ msgstr ""
msgid "Could not get weather information"
msgstr ""

#: 3.0/applet.js:624 3.8/weather-applet.js:17577
#: 3.0/applet.js:624 3.8/weather-applet.js:17633
msgid ""
"Unexpected Error While Refreshing Weather, please see log in Looking Glass"
msgstr ""

#: 3.0/applet.js:670 3.8/weather-applet.js:17820
#: 3.0/applet.js:670 3.8/weather-applet.js:17876
msgid ""
"Could not update weather for a while...\n"
"are you connected to the internet?"
Expand All @@ -118,37 +118,37 @@ msgstr ""
msgid "As of"
msgstr ""

#: 3.0/applet.js:1108 3.8/weather-applet.js:16826
#: 3.0/applet.js:1108 3.8/weather-applet.js:16882
msgid "Powered by"
msgstr ""

#: 3.0/applet.js:1113
msgid "from you"
msgstr ""

#: 3.0/applet.js:1132 3.8/weather-applet.js:16739
#: 3.0/applet.js:1132
msgid "mm"
msgstr ""

#: 3.0/applet.js:1132 3.0/darkSky.js:71 3.8/weather-applet.js:16739
#: 3.0/applet.js:1132 3.0/darkSky.js:71
msgid "in"
msgstr ""

#: 3.0/applet.js:1205 3.0/met_uk.js:421 3.8/weather-applet.js:10307
#: 3.8/weather-applet.js:16904
#: 3.8/weather-applet.js:16960
msgid "mi"
msgstr ""

#: 3.0/applet.js:1206 3.0/met_uk.js:422 3.8/weather-applet.js:10308
#: 3.8/weather-applet.js:16905
#: 3.8/weather-applet.js:16961
msgid "km"
msgstr ""

#: 3.0/applet.js:1227 3.8/weather-applet.js:17084
#: 3.0/applet.js:1227 3.8/weather-applet.js:17140
msgid "Loading current weather ..."
msgstr ""

#: 3.0/applet.js:1230 3.8/weather-applet.js:17087
#: 3.0/applet.js:1230 3.8/weather-applet.js:17143
msgid "Loading future weather ..."
msgstr ""

Expand Down Expand Up @@ -1721,35 +1721,35 @@ msgstr ""
msgid "Forecast parsing failed, see logs for more details."
msgstr ""

#: 3.8/weather-applet.js:16833 3.8/weather-applet.js:17619
#: 3.8/weather-applet.js:16889 3.8/weather-applet.js:17675
msgid "As of {lastUpdatedTime}"
msgstr ""

#: 3.8/weather-applet.js:16839
#: 3.8/weather-applet.js:16895
msgid "{distance} {distanceUnit} from you"
msgstr ""

#: 3.8/weather-applet.js:16843
#: 3.8/weather-applet.js:16899
msgid "Station Name: {stationName}"
msgstr ""

#: 3.8/weather-applet.js:16846
#: 3.8/weather-applet.js:16902
msgid "Area: {stationArea}"
msgstr ""

#: 3.8/weather-applet.js:17393 3.8/weather-applet.js:17403
#: 3.8/weather-applet.js:17449 3.8/weather-applet.js:17459
msgid "Error Saving Debug Information"
msgstr ""

#: 3.8/weather-applet.js:17415
#: 3.8/weather-applet.js:17471
msgid "Debug Information saved successfully"
msgstr ""

#: 3.8/weather-applet.js:17415
#: 3.8/weather-applet.js:17471
msgid "Saved to {filePath}"
msgstr ""

#: 3.8/weather-applet.js:17544
#: 3.8/weather-applet.js:17600
msgid "This provider requires an API key to operate"
msgstr ""

Expand Down
Loading

0 comments on commit c57b274

Please sign in to comment.