Popup

class visigoth.containers.popup.Popup(element, title='', stroke_width=2, stroke='grey', fill='white', popup_group_id=None, opacity=1.0, corner_radius=4, font_height=18, text_attributes={}, opened=False)

Wrap an element within a closable popup box

Parameters
  • element (DiagramElement) – element to wrap

  • title (str) – title for the popup

Keyword Arguments
  • stroke_width (int) – width of the border in pixels

  • stroke (str) – colour of the border

  • fill (str) – fill colour for the box

  • popup_group_id (str) – (optional) id of an enclosing svg <g> element

  • opacity (float) – set the opacity of the popup, in range 0.0 (transparent) to 1.0 (opaque)

  • corner_radius (float) – radius of the popup corners in pixels

  • font_height (int) – font size in pixels

  • text_attributes (dict) – a dict containing SVG name/value attributes

  • opened (boolean) – True iff the popup should be initially open

Example

Screenshot (Link to open SVG for interactive features):

../_images/example17.png

Source Code (Link to Github):


import os
import sys
import argparse
import json
import random

from visigoth import Diagram

from visigoth.containers.map import Map
from visigoth.utils.mapping import Metadata, Geocoder

from visigoth.map_layers.geoimport import Geoimport
from visigoth.map_layers.gridsquares import GridSquares
from visigoth.map_layers.wms import WMS
from visigoth.containers.popup import Popup
from visigoth.containers.box import Box
from visigoth.map_layers.geoplot import Geoplot, Multipoint
from visigoth.common.space import Space
from visigoth.utils.colour import Colour
from visigoth.utils.mapping import Mapping,Projections
from visigoth.utils.js import Js

if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("--outpath", help="path for output SVG", default="example.svg")
    args = parser.parse_args()

    folder=os.path.split(__file__)[0]

    d = Diagram(fill="white")

    gc = Geocoder()

    center = gc.fetchCenter("New York")
    bounds = Mapping.computeBoundaries(center,200000,projection=Projections.ESPG_3857)

    timesq = gc.fetchCenter("Times Square, New York")
    timesq_bounds = Mapping.computeBoundaries(timesq,500,projection=Projections.ESPG_3857)
    

    timesq_m = Map(256,boundaries=timesq_bounds,projection=Projections.ESPG_3857,font_height=5)
    timesq_wms = WMS(type="osm")
    timesq_m.addLayer(timesq_wms)
    timesq_popup = Popup(timesq_m,"Times Square",fill="white")

    m = Map(512,boundaries=bounds,projection=Projections.ESPG_3857,zoom_to=2)

    wms = WMS(type="osm")
    wms.setInfo("Map")

    gp = Geoplot(multipoints=[Multipoint([timesq],label="Times Square",popup=timesq_popup)])
    grid = GridSquares()

    m.addLayer(wms)
    m.addLayer(gp)
    m.addLayer(grid)
    d.add(Space(100))
    d.add(m)

    svg = d.draw()

    f = open(args.outpath, "wb")
    f.write(svg)
    f.close()