feat: add configurable people maps
Add independent map profiles, offline city lookup, bundled world artwork and collision-free portrait placement with optional person details. Deploy with updated requirements, migrations 0029-0031 and collectstatic.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace as Obj
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
os.environ['DJANGO_SETTINGS_MODULE']='config.settings.preview'
|
||||
import django
|
||||
django.setup()
|
||||
from django.template.loader import render_to_string
|
||||
from playwright.sync_api import sync_playwright
|
||||
root=Path(__file__).resolve().parent.parent
|
||||
def preview(count=14):
|
||||
places=[(49.28,-123.12,'Vancouver','Canada'),(49.28,-123.12,'Vancouver','Canada'),(49.28,-123.12,'Vancouver','Canada'),(40.71,-74,'New York','United States'),(42.37,-72.52,'Amherst','United States'),(38.54,-121.74,'Davis','United States'),(46.94,7.45,'Bern','Switzerland'),(35.69,51.39,'Tehran','Iran'),(35.69,51.39,'Tehran','Iran'),(23.58,58.4,'Muscat','Oman'),(37.28,49.58,'Rasht','Iran'),(23.13,113.26,'Guangzhou','China'),(-33.86,151.2,'Sydney','Australia'),(3.14,101.68,'Kuala Lumpur','Malaysia')]
|
||||
names=['Arman Rahmim','Mohammad R. Salmanpour','Steven Lewis','Nicolas Karakatsanis','Joyita Dutta','Emilie Roncali','Isaac Shiri','Ali Fathi Jouzdani','Arman Gorji','Yassine Bouchareb','Shahram Taeb','Lijun Lu','Collaborator in Sydney','Collaborator in Kuala Lumpur']
|
||||
members=[]
|
||||
for i in range(count):
|
||||
lat,lon,city,country=places[i%len(places)] if count<20 else (49.28,-123.12,'Vancouver','Canada')
|
||||
person=Obj(name=names[i%len(names)],qualifications='PhD',role='Collaborator',institution='Research Institute',biography='',photo=None,profile_url='')
|
||||
members.append(Obj(pk=i+1,person=person,latitude=lat,longitude=lon,city=city,country=country))
|
||||
world=Obj(title='Care knows no borders.',description='A connected community bringing computation closer to care, across disciplines and across the world.',show_people_details=True,style='aurora',background_style='classic',background_static_path='images/world-map.svg',background_image=None,memberships=Obj(all=members))
|
||||
html=render_to_string('partials/_people_maps.html',{'placements':[Obj(pk=1,people_map=world)]})
|
||||
html=html.replace('/static/images/world-map.svg', (root/'static/images/world-map.svg').as_uri())
|
||||
return '<!doctype html><meta charset="utf-8"><style>body{margin:0;background:#070c16;padding:32px;font-family:Arial}.container{max-width:1280px;margin:auto}*{box-sizing:border-box}'+(root/'static/css/people-map.css').read_text()+'</style>'+html+'<script>'+(root/'static/js/people-map.js').read_text()+'</script>'
|
||||
with sync_playwright() as p:
|
||||
browser=p.chromium.launch(channel='chrome')
|
||||
page=browser.new_page(viewport={'width':1440,'height':1100})
|
||||
errors=[]
|
||||
page.on('pageerror', lambda error: errors.append(str(error)))
|
||||
for count in [14,60]:
|
||||
path=Path('/tmp/com2care-map-preview.html'); path.write_text(preview(count))
|
||||
page.goto(path.as_uri());page.wait_for_timeout(500)
|
||||
def verify():
|
||||
return page.evaluate('''() => {const pins=[...document.querySelectorAll('.people-map-pin')].map(p=>p.getBoundingClientRect());return pins.flatMap((a,i)=>pins.slice(i+1).filter(b=>a.left<b.right&&a.right>b.left&&a.top<b.bottom&&a.bottom>b.top)).length}''')
|
||||
assert verify()==0, f'overlap {count}'
|
||||
if count==14: page.screenshot(path=str(root/'artifacts/people-map/desktop.png'),full_page=True)
|
||||
page.set_viewport_size({'width':390,'height':844});page.wait_for_timeout(300)
|
||||
assert verify()==0, f'mobile overlap {count}'
|
||||
assert page.evaluate('document.documentElement.scrollWidth <= window.innerWidth'), 'page overflow'
|
||||
page.locator('.people-map-pin').first.click()
|
||||
assert page.evaluate('location.hash')=='#map-1-person-1'
|
||||
if count==14:page.screenshot(path=str(root/'artifacts/people-map/mobile.png'),full_page=True)
|
||||
page.set_viewport_size({'width':1440,'height':1100})
|
||||
print(f'{count} pins: desktop/mobile no collisions; anchor navigation passes')
|
||||
assert not errors, errors
|
||||
browser.close()
|
||||
Reference in New Issue
Block a user