Skip to content

Move Map and Plugin object to a tree structure #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from

Conversation

BibMartin
Copy link
Contributor

3 simple commits, and an important one (561f060).

The goal of the latter is to move progressively the Map and Plugin objects into a tree structure.

What I have in mind is a tree like :

+- figure
    +- header
    +- css
    +- body
    +- script
    +- maps
        +- Markers
        +- Layers
        +- Plugins
        ...
    +- Others

Each node of the tree would have a render method that can have an effect on his parents.

This would have several positive effects:

Well, discussion is open... ;-)

@BibMartin
Copy link
Contributor Author

I forgot ; for the moment, the tree structure is:

+- Map
    +- figure
        +- header
        +- css
        +- body
        +- script
    +- template_vars
    +- plugins
    ...

The idea is to move progressively template_vars into a structured tree (without changing the API), then to have figure embed several maps.

@themiurgo
Copy link
Contributor

I feel like this PR is actually 2PRs, one part is the plugin render idea, the other is the tree structure.

Some questions:

  • Why is the root name called figure? Shouldn't it be something like "page" or "root"?
  • Why is plugin a child of maps? Surely each plugin affects the whole page and needs to inject their own header. If I embed two maps with the same sets of headers it will be difficult to track whether the js/css has been already injected beforehand.

@BibMartin
Copy link
Contributor Author

Why is the root name called figure? Shouldn't it be something like "page" or "root"?

I chose figure because I have something like matplotlib in mind : a figure in which you can put several maps/axes. I thought we could get closer to their function names. I would be okay for "page" or "root".

Why is plugin a child of maps?

A plugin generally adds something on the map. But you're true, it can require to add somthing to the overall figure. This is why I have designed the thing so that each node knows who is his parent, and can have an effect on it. For example, if you have something like

Figure
    map1
        boatmarker1
        boatmarker2
    map2
        boatmarker3
        boatmarker4

Then each boatmarker will do something like

boatmarker.map.figure.header['boatmarker_js'] = Link('http://...')

But as it is the same Figure object, they will simply overwrite the former header.
BTW, this is why we need to use OrderedDict instead of lists : order is important, but we also need to get objects by their key/name.

@BibMartin
Copy link
Contributor Author

Let's say that VegaPopup is working (though it's pure prototype). @wrobstory I would be happy if you have time to wartch 8ce53ea as it is going far from folium.Map._popup_render and I'm not really sure of the javascript generated.

@BibMartin
Copy link
Contributor Author

💚 At last !

self.map.figure.header['jquery'] = JavascriptLink("https://code.jquery.com/jquery-2.1.0.min.js")
self.map.figure.script['vega_parse'] = Template("""function vega_parse(spec, div) {
vg.parse.spec(spec, function(chart) { chart({el:div}).update(); });}""")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this approach it should be relatively easy to create mpld3 (pr even bokeh) popups.

@ocefpaf ocefpaf mentioned this pull request Aug 16, 2015
@ocefpaf ocefpaf added this to the v0.2.0 milestone Aug 20, 2015
@BibMartin BibMartin mentioned this pull request Aug 26, 2015
@BibMartin
Copy link
Contributor Author

This is outdated. Replaced by #203

@BibMartin BibMartin closed this Sep 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants