Skip to content

Commit fcf186d

Browse files
niccokunzmannclaude
andcommitted
Map: cities as circles, a box below the map, black to green countries; make messages in Docker
The map of the page Countries draws 1 px white lines around each country; countries without contributors are black, with contributors dark to light green (logarithmic), with a legend. Cities of contributors are green circles with a white border whose area grows with their contributors; they can be pointed at. A box of a fixed size below the map names the country pointed at, the city below it, the country chosen, or how to use the map. The border of the country pointed at is three times as wide. A click on a country chose nothing in real browsers: the captured pointer is released on the whole map. The country is now taken when it is pressed; a browser test points at and clicks the map. make messages runs in a container of python:3.13-slim when GNU gettext is not installed, as dashboard.pycal.org does; the catalogs are made with gettext again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8f3a904 commit fcf186d

20 files changed

Lines changed: 1913 additions & 1853 deletions

File tree

‎.dockerignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ docs
77
tests
88
__pycache__
99
.env
10+
.cache

‎Makefile‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,35 @@ lint: .venv ## Check the code style
134134
MANAGE ?= uv run python manage.py
135135
LANGUAGES ?= de es
136136
MESSAGES_IGNORE = -i '.venv/*' -i 'docs/*' -i 'tests/*' -i 'features/*' \
137-
-i 'staticfiles/*' -i 'node_modules/*' -i 'static/vendor/*'
137+
-i 'staticfiles/*' -i 'node_modules/*' -i 'static/vendor/*' -i '.cache/*' -i 'scripts/*' \
138+
-i 'old/*' -i 'build/*' -i 'dist/*'
138139

139140
.PHONY: messages
140-
messages: ## Update the translations in locale/ and compile them; needs GNU gettext
141+
messages: ## Update the translations in locale/ and compile them: with GNU gettext, else in Docker
142+
@if command -v xgettext >/dev/null; then \
143+
$(MAKE) --no-print-directory messages-here; \
144+
else \
145+
echo "GNU gettext is not installed: the translations are made in Docker (python:3.13-slim)"; \
146+
docker run --rm -v "$(CURDIR):/src" -w /src \
147+
-e UV_PROJECT_ENVIRONMENT=/src/.cache/messages-venv -e UV_CACHE_DIR=/src/.cache/uv \
148+
-e SECRET_KEY=messages -e DATA_DIR=/tmp/data -e PRODUCTION=false \
149+
python:3.13-slim sh -c '\
150+
apt-get update -qq && apt-get install -y -qq --no-install-recommends gettext make >/dev/null \
151+
&& pip install -q --root-user-action=ignore uv && uv sync -q --locked --no-dev \
152+
&& make --no-print-directory messages-here MANAGE="uv run --no-sync python manage.py"; \
153+
status=$$?; chown -R $(shell id -u):$(shell id -g) locale .cache; exit $$status'; \
154+
fi
155+
156+
# the virtual environment and the cache of uv of the container are in .cache/ (on the disk of
157+
# the project, reused), not in the container, whose disk is that of Docker
158+
.PHONY: messages-here
159+
messages-here:
141160
@for language in $(LANGUAGES); do \
142161
$(MANAGE) makemessages -l $$language $(MESSAGES_IGNORE) --no-location && \
143162
$(MANAGE) makemessages -d djangojs -l $$language $(MESSAGES_IGNORE) --no-location \
144163
|| exit 1; \
145164
done
146-
@$(MANAGE) compilemessages -i '.venv' -i 'node_modules'
165+
@$(MANAGE) compilemessages -i '.venv' -i 'node_modules' -i '.cache'
147166

148167
.PHONY: test-translations
149168
test-translations: messages ## Update the translations and check that all texts are translated

‎community_insights/templates/community/countries.html‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,24 @@
1414
<button type="button" class="btn btn-outline-secondary" data-zoom="out" aria-label="{% translate "Zoom out" %}" title="{% translate "Zoom out" %}">−</button>
1515
<button type="button" class="btn btn-outline-secondary" data-zoom="reset" aria-label="{% translate "Show the whole world" %}" title="{% translate "Show the whole world" %}">⟲</button>
1616
</div>
17-
<div class="world-map-tip" data-map-tip hidden></div>
1817
<noscript><img src="{% static 'maps/world.svg' %}" alt="{% translate "Map of the world" %}" class="w-100"></noscript>
1918
</div>
20-
<p class="small text-muted heat-legend">
21-
<span class="swatch heat-0"></span> {% translate "nobody" %}
22-
<span class="swatch heat-1 ms-2"></span> {% translate "few" %}
23-
<span class="swatch heat-3"></span>
24-
<span class="swatch heat-5"></span> {% translate "most contributors" %}
25-
{% if found.places %}<span class="swatch ms-2 place-swatch"></span> {% translate "a city or place of contributors" %}{% endif %}
26-
· {% translate "Scroll or pinch to zoom, drag to move, click a country for its contributors." %}
19+
{% translate "Point at a country or a city for its contributors, click for details. Scroll or pinch to zoom, drag to move." as help %}
20+
<div class="world-map-info mb-2" data-map-info data-help="{{ help }}" aria-live="polite">
21+
<div data-info-country>{{ help }}</div>
22+
<div class="small" data-info-place></div>
23+
</div>
24+
<p class="small text-muted heat-legend" data-legend>
25+
<span class="swatch legend-nobody"></span> {% translate "nobody" %}
26+
<span class="legend-scale ms-2" aria-hidden="true"></span> {% blocktranslate count most=most %}from 1 to {{ most }} contributor{% plural %}from 1 to {{ most }} contributors{% endblocktranslate %}
27+
{% if found.places %}<span class="swatch ms-2 place-swatch"></span> {% translate "a city of contributors: the bigger, the more" %}{% endif %}
2728
</p>
2829

2930
<div class="row g-4">
3031
<div class="col-12 col-lg-4">
3132
<h2 class="h5">{% translate "Countries" %}</h2>
3233
{% if rows %}<ol class="small" data-country-list>
33-
{% for row in rows %}<li data-country="{{ row.stats.code }}" data-count="{{ row.stats.count }}" data-heat="{{ row.heat }}" data-tip="{{ row.tip }}"><a href="#country={{ row.stats.code }}">{{ row.name }}</a> <span class="text-muted">{{ row.stats.count }}</span></li>{% endfor %}
34+
{% for row in rows %}<li data-country="{{ row.stats.code }}" data-count="{{ row.stats.count }}" data-color="{{ row.color }}" data-tip="{{ row.tip }}"><a href="#country={{ row.stats.code }}">{{ row.name }}</a> <span class="text-muted">{{ row.stats.count }}</span></li>{% endfor %}
3435
</ol>{% else %}<p class="small text-muted">{% translate "No contributor of this time has a location with a known country." %}</p>{% endif %}
3536
{% if found.unknown %}<h3 class="h6">{% translate "Locations without a known country" %}</h3>
3637
<ul class="small list-unstyled" data-unknown>{% for login, location in found.unknown %}<li><a href="{% url 'person' scope.text login %}{{ scope.query }}">{{ login }}</a> <span class="text-muted">{{ location }}</span></li>{% endfor %}</ul>{% endif %}

‎community_insights/views/geography.py‎

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,37 @@
1010
from ..locations.names import country_name, language_name, locale
1111
from .scope import scope_of, scope_view, stats_page
1212

13-
LEVELS = 5 # the shades of the heat map, from few to most contributors
13+
NOBODY = "#000000" # a country without contributors
14+
FEWEST = (0x0E, 0x6B, 0x0E) # one contributor: dark green
15+
MOST = (0xB5, 0xF0, 0xB5) # the most contributors: light green
1416

1517

16-
def heat(count: int, most: int) -> int:
17-
"""The shade of a country on the map: 0 for none, 1 for few to ``LEVELS`` for the most.
18+
def color(count: int, most: int) -> str:
19+
"""The colour of a country on the map: black for none, dark to light green for few to most.
1820
19-
The shades follow the logarithm, so one country with many contributors does not leave
20-
all others in the lightest shade.
21+
The green follows the logarithm of the count, so one country with many contributors does
22+
not leave all others nearly as dark as one contributor.
2123
2224
Args:
2325
count: The contributors from the country.
2426
most: The contributors from the country with the most.
2527
2628
Returns:
27-
The shade.
29+
The colour as ``#rrggbb``.
2830
2931
Examples:
30-
>>> heat(0, 10), heat(1, 10), heat(3, 10), heat(10, 10), heat(1, 1)
31-
(0, 1, 2, 5, 5)
32+
>>> color(0, 10), color(1, 10), color(10, 10), color(1, 1)
33+
('#000000', '#0e6b0e', '#b5f0b5', '#0e6b0e')
34+
>>> color(3, 9) # halfway on the logarithmic scale
35+
'#62ae62'
3236
"""
3337
if count <= 0:
34-
return 0
35-
if most <= 1:
36-
return LEVELS
37-
return 1 + min(LEVELS - 1, math.floor((LEVELS - 1) * math.log(count) / math.log(most)))
38+
return NOBODY
39+
share = math.log(count) / math.log(most) if most > 1 else 0.0
40+
share = min(1.0, max(0.0, share))
41+
return "#" + "".join(
42+
f"{round(low + (high - low) * share):02x}" for low, high in zip(FEWEST, MOST, strict=True)
43+
)
3844

3945

4046
def tip(count: int, name: str) -> str:
@@ -99,21 +105,24 @@ def countries(request, scope):
99105
{
100106
"stats": country,
101107
"name": name,
102-
"heat": heat(country.count, most),
108+
"color": color(country.count, most),
103109
"tip": tip(country.count, name),
104110
"languages": [language_name(code) for code in country.languages],
105111
}
106112
)
113+
# each city: x, y, the code of its country, its contributors and its text
107114
places = [
108115
[
109116
x,
110117
y,
118+
code,
119+
count,
111120
ngettext(
112121
"%(place)s: %(count)s contributor",
113122
"%(place)s: %(count)s contributors",
114123
count,
115124
)
116-
% {"place": f"{city}, {country_name(code)}", "count": count},
125+
% {"place": city, "count": count},
117126
]
118127
for x, y, city, code, count in found.places
119128
]
@@ -129,6 +138,8 @@ def countries(request, scope):
129138
"names_json": json.dumps(map_names(), ensure_ascii=False, sort_keys=True),
130139
# the tip of a country without contributors; the script puts in the name
131140
"nobody": _("No contributors from %(country)s") % {"country": "{country}"},
141+
"most": most,
142+
"scale": {"nobody": NOBODY, "fewest": color(1, most), "most": color(most, most)},
132143
},
133144
)
134145

‎docs/explanation/countries.rst‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ The map
3131

3232
The map is drawn from the countries of `Natural Earth <https://www.naturalearthdata.com/>`_ (public domain, scale 1:50 million), in the Equal Earth projection, which keeps the areas of the countries: a big country is not drawn bigger than it is. Antarctica is left out. ``make world-map`` makes the map again (``scripts/world_map.py``).
3333

34-
- **Colours.** Gray is a country without contributors. The five greens go from few to the most contributors, on a logarithmic scale: with 100 contributors from one country and 1 from another, the shades are 1, 2 to 3 for 10, and 5 for 100, so one big country does not leave all others in the lightest shade.
35-
- **Tool tip.** Pointing at a country shows *3 contributors from Germany*, or that nobody is from there.
34+
- **Colours.** Black is a country without contributors. With contributors, a country is green: dark green for one contributor, light green for the country with the most, and in between on a logarithmic scale. With 100 contributors from one country, a country with 10 is halfway, so one big country does not leave all others nearly as dark as one contributor. White lines of 1 pixel separate the countries at every zoom.
35+
- **The box below the map.** It always has the same size and place. Pointing at a country shows *3 contributors from Germany*, or that nobody is from there; pointing at a city shows the city below its country, such as *Berlin: 2 contributors*. Without anything pointed at, it shows the country chosen, and without that how to use the map. The border of the country pointed at is three times as wide.
3636
- **Small countries.** Luxembourg, Malta or Singapore are a few pixels or less. A country smaller than about 12 square pixels at the current zoom is small: it gets a dot at its centre, and the pointer chooses it within 10 pixels of that centre, also on top of a bigger neighbour. Zoomed in, it becomes big enough to point at itself.
37-
- **Clicks.** A click on a country opens ``#country=XX`` with its code, which shows the country below the map: its contributors and their locations, the first and the last contribution from there, and its official languages. The address can be shared.
38-
- **Places.** Contributors with a clear city or place are red dots, one per place, with how many contributors are there. They cannot be clicked.
37+
- **Clicks.** A click on a country or a city opens ``#country=XX`` with the code of the country, which shows the country below the map: its contributors and their locations, the first and the last contribution from there, and its official languages. The country is outlined, and the box keeps its text. The address can be shared.
38+
- **Cities.** Contributors with a clear city or place are a green circle with a white border, one per place. Its area grows in proportion to the contributors there: the radius grows with the square root of their number, 3 pixels for one, 6 for four, at every zoom. Only the cities of contributors are on the map. Pointing at a city shows it in the box; a click chooses its country.
3939
- **Zoom.** The mouse wheel or a pinch zooms, dragging moves the map, and the buttons zoom in, out, and back to the whole world.
4040

4141
.. _languages:

‎docs/how-to/translate.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The details of the errors, the names of the variables of queries, the charts and
1616
Change or add a text
1717
====================
1818

19-
1. Install `GNU gettext <https://www.gnu.org/software/gettext/>`_, for example ``sudo apt install gettext``.
19+
1. Install `GNU gettext <https://www.gnu.org/software/gettext/>`_, for example ``sudo apt install gettext``. Without it, ``make messages`` runs in Docker: a container of ``python:3.13-slim`` installs gettext and the dependencies. Its virtual environment and the cache of uv are kept in ``.cache/`` of the project, so the next run is fast and the disk of Docker stays small.
2020
2. Mark the new text in the template, the Python code or the JavaScript as above.
2121
3. Update the catalogs and compile them:
2222

‎locale/de/LC_MESSAGES/django.mo‎

4.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)