Skip to content

Commit

Permalink
simple map data and preview #45
Browse files Browse the repository at this point in the history
  • Loading branch information
mondoboia committed Sep 9, 2022
1 parent 11dbee5 commit 423fdc2
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 66 deletions.
74 changes: 68 additions & 6 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"sections": [
"Listening Experiences",
"Tests",
"musoW",
"Wikidata",
"Zeri"
"Zeri",
"Tests",
"Listening Experiences",
"musoW"
],
"operations": [
"Count",
Expand Down Expand Up @@ -428,10 +428,72 @@
"template_mode": "statistics",
"title": "Simple Map",
"color_code": [
"#39c6b4",
"#39c6b5",
"#17cf31"
],
"section_name": "Tests"
"section_name": "Tests",
"subtitle": "",
"curator": "",
"description": "",
"action": "save",
"dynamic_elements": [
{
"position": 1,
"type": "map",
"map_title": "Museums in Brittany",
"map_points_query": "SELECT DISTINCT ?museumLabel ?museumDescription ?villeId ?villeIdLabel (?villeIdLabel AS ?ville) ?coord ?lat ?long\r\nWHERE\r\n{\r\n ?museum wdt:P539 ?museofile.\r\n ?museum wdt:P131* wd:Q12130.\r\n ?museum wdt:P131 ?villeId.\r\n ?museum wdt:P856 ?link.\r\n ?museum wdt:P625 ?coord .\r\n ?museum p:P625 ?statement.\r\n ?statement psv:P625 ?node.\r\n ?node wikibase:geoLatitude ?lat.\r\n ?node wikibase:geoLongitude ?long.\r\n SERVICE wikibase:label { bd:serviceParam wikibase:language \"fr\". }\r\n}\r\nORDER BY ?villeIdLabel",
"extra_queries": [],
"operations": []
},
{
"position": 2,
"type": "map",
"map_title": "All museums in Barcelona with coordinates",
"map_points_query": "SELECT DISTINCT ?item ?name ?coord ?lat ?long\r\nWHERE\r\n{\r\n hint:Query hint:optimizer \"None\" .\r\n ?item wdt:P131* wd:Q1492 .\r\n ?item wdt:P31/wdt:P279* wd:Q33506 .\r\n ?item wdt:P625 ?coord .\r\n ?item p:P625 ?coordinate .\r\n ?coordinate psv:P625 ?coordinate_node .\r\n ?coordinate_node wikibase:geoLatitude ?lat .\r\n ?coordinate_node wikibase:geoLongitude ?long .\r\n SERVICE wikibase:label {\r\n bd:serviceParam wikibase:language \"ca\" .\r\n ?item rdfs:label ?name\r\n }\r\n}\r\nORDER BY ASC (?name)",
"extra_queries": [],
"operations": []
},
{
"position": 3,
"type": "map",
"map_title": "Museums in Antwerp",
"map_points_query": "SELECT ?item ?itemLabel ?coordinate ?lat ?long\r\nWHERE\r\n{\r\n ?item wdt:P31/wdt:P279* wd:Q33506 ;\r\n wdt:P131 wd:Q12892 ;\r\n wdt:P625 ?coordinate .\r\n ?item p:P625 ?coordinates .\r\n ?coordinates psv:P625 ?coordinate_node .\r\n ?coordinate_node wikibase:geoLatitude ?lat .\r\n ?coordinate_node wikibase:geoLongitude ?long .\r\n SERVICE wikibase:label { bd:serviceParam wikibase:language \"nl, en\" }\r\n }",
"extra_queries": [],
"operations": []
}
]
},
"everything_works": {
"sparql_endpoint": "https://query.wikidata.org/sparql",
"template_mode": "maps",
"title": "Everything Works",
"color_code": [
"#6e7e3a",
"#79f1e9"
],
"section_name": "Tests",
"subtitle": "",
"curator": "",
"description": "",
"action": "save",
"dynamic_elements": [
{
"position": 1,
"type": "map",
"map_title": "",
"map_points_query": "SELECT DISTINCT ?item ?name ?coord ?lat ?long\r\nWHERE\r\n{\r\n hint:Query hint:optimizer \"None\" .\r\n ?item wdt:P131* wd:Q1492 .\r\n ?item wdt:P31/wdt:P279* wd:Q33506 .\r\n ?item wdt:P625 ?coord .\r\n ?item p:P625 ?coordinate .\r\n ?coordinate psv:P625 ?coordinate_node .\r\n ?coordinate_node wikibase:geoLatitude ?lat .\r\n ?coordinate_node wikibase:geoLongitude ?long .\r\n SERVICE wikibase:label {\r\n bd:serviceParam wikibase:language \"ca\" .\r\n ?item rdfs:label ?name\r\n }\r\n}\r\nORDER BY ASC (?name)",
"extra_queries": [],
"operations": []
},
{
"position": 2,
"type": "map",
"map_title": "",
"map_points_query": "SELECT DISTINCT ?museumLabel ?museumDescription ?villeId ?villeIdLabel (?villeIdLabel AS ?ville) ?coord ?lat ?long\r\nWHERE\r\n{\r\n ?museum wdt:P539 ?museofile.\r\n ?museum wdt:P131* wd:Q12130.\r\n ?museum wdt:P131 ?villeId.\r\n ?museum wdt:P856 ?link.\r\n ?museum wdt:P625 ?coord .\r\n ?museum p:P625 ?statement.\r\n ?statement psv:P625 ?node.\r\n ?node wikibase:geoLatitude ?lat.\r\n ?node wikibase:geoLongitude ?long.\r\n SERVICE wikibase:label { bd:serviceParam wikibase:language \"fr\". }\r\n}\r\nORDER BY ?villeIdLabel",
"extra_queries": [],
"operations": []
}
]
}
},
"zeri": {
Expand Down
12 changes: 2 additions & 10 deletions data_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,10 @@ def manage_datastory_data(general_data, file, section_name, datastory_name):
op_list = []
elements_dict = {}
elements_dict['position'] = position
#######################
#######################
extra_set = set()
total_extra_dict = {} # to store together extra data of one chart
extra_queries = [] # to store in separate dict extra data of one chart
#######################
#######################
print(form_data)

for k, v in form_data.items():
if '__' in k:
if position == int(k.split('__')[0]):
Expand All @@ -145,13 +141,11 @@ def manage_datastory_data(general_data, file, section_name, datastory_name):
elif 'map' in k and 'simple' not in k and 'filter' not in k:
elements_dict['type'] = 'map'
elements_dict[k.split('__')[1]] = v
elif 'map' in k and 'simple' not in k and 'filter' in k:
elif 'map' in k and 'simple' not in k and 'filter' in k:
elements_dict['type'] = 'map_filter'
elements_dict[k.split('__')[1]] = v
elif 'action' in k:
op_list.append(v)
#######################
#######################
elif 'extra' in k:
extra_set.add(int(k.split('_')[4]))
total_extra_dict[k.split('__')[1]] = v
Expand All @@ -164,8 +158,6 @@ def manage_datastory_data(general_data, file, section_name, datastory_name):
extra_dict['extra_id'] = str(e)
extra_queries.append(extra_dict)
elements_dict['extra_queries'] = extra_queries
#######################
#######################

# create dicts with operations info
for op in op_list:
Expand Down
95 changes: 45 additions & 50 deletions templates/modify_maps.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<!-- <link rel="stylesheet" href="{{ url_for('static', filename='css/personal.css') }}"> -->
<link rel="stylesheet" href="/melody/static/css/templates.css">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ=="
crossorigin=""/>
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ=="
crossorigin="" />
<link rel="stylesheet" href="/melody/static/css/MarkerCluster.css">
<link rel="stylesheet" href="/melody/static/css/MarkerCluster.Default.css">
<link rel="stylesheet" href="/melody/static/css/leaflet-sidebar.css">
Expand Down Expand Up @@ -92,40 +92,40 @@ <h5 class="text-white op-7 pb-2">
<div class="card-body nopaddingleft" id="sortable">
<span id='loader' class='lds-dual-ring hidden overlay'></span>
{% for dict in datastory_data.dynamic_elements %}
{% if dict.type == 'map' %}
<div id="{{dict.position}}__block_field">
<h4 class="block_title">Add map</h4>
<a href="#" class="trash" id="{{dict.position}}__trash" name="{{dict.position}}__trash">
<i class="far fa-trash-alt" id="{{dict.position}}__bin"></i>
</a>
<br>
<!-- map title -->
<input class='map_title' id='{{dict.position}}__map_title' type='text'
name='{{dict.position}}__map_title' value='{{dict.map_title}}'
placeholder='The title of the map'>
<!-- data points -->
<textarea class='addplaceholder_points' oninput='auto_grow(this)'
name='{{dict.position}}__map_points_query' type='text'
id='{{dict.position}}__map_points_query' rows='10'
required>{{dict.map_points_query}}</textarea>
<a onclick='rerunQuery({{dict.position}})'
data-id='{{dict.position}}_rerun_query'
data-run='true' href="#{{dict.position}}__map_points_query">Rerun the query</a>
<!-- map preview -->
<div class="map_preview_container" id="{{dict.position}}__map_preview_container">
</div>
<h4 id='{{dict.position}}__addmapfilter' class='text-white'>Do you want to add a filter to the map?</h4>
<p>Filters appear on the left side of the map and allow you
{% if dict.type == 'map' %}
<div id="{{dict.position}}__block_field">
<h4 class="block_title">Add map</h4>
<a href="#" class="trash" id="{{dict.position}}__trash" name="{{dict.position}}__trash">
<i class="far fa-trash-alt" id="{{dict.position}}__bin"></i>
</a>
<br>
<!-- map title -->
<input class='map_title' id='{{dict.position}}__map_title' type='text'
name='{{dict.position}}__map_title' value='{{dict.map_title}}'
placeholder='The title of the map'>
<!-- data points -->
<textarea class='addplaceholder_points' oninput='auto_grow(this)'
name='{{dict.position}}__map_points_query' type='text'
id='{{dict.position}}__map_points_query' rows='10'
required>{{dict.map_points_query}}</textarea>
<a onclick='rerunQuery({{dict.position}})' data-id='{{dict.position}}_rerun_query'
data-run='true' href="#{{dict.position}}__map_points_query">Rerun the query</a>
<!-- map preview -->
<div class="map_preview_container" id="{{dict.position}}__map_preview_container">
</div>
<h4 id='{{dict.position}}__addmapfilter' class='text-white'>Do you want to add a filter to the
map?</h4>
<p>Filters appear on the left side of the map and allow you
to filter out points on the map based on a SPARQL query.</p>
<a class='btn btn-primary btn-border'
onclick='add_field(name,"{{dict.position}}__map_points_query")'
name='map_filter'>Add filter</a>
<a class='btn btn-primary btn-border'
onclick='add_field(name,"{{dict.position}}__map_points_query")' name='map_filter'>Add
filter</a>

</div>
</div>

{% endif %}
{% if dict.type == 'map_filter' %}
<div id="{{dict.position}}__block_field">
{% endif %}
{% if dict.type == 'map_filter' %}
<div id="{{dict.position}}__block_field">
<h4 class="block_title">Add map filter</h4>
<a href="#" class="up" id="{{dict.position}}__up" name="{{dict.position}}__up">
<i class="fas fa-arrow-up" id="{{dict.position}}__arrow-up"></i>
Expand All @@ -137,31 +137,26 @@ <h4 class="block_title">Add map filter</h4>
<i class="far fa-trash-alt" id="{{dict.position}}__bin"></i>
</a>
<br>
<input class='map_filter_title'
id='{{dict.position}}__map_filter_title' type='text'
name='{{dict.position}}__map_filter_title'
placeholder='The title of the filter'
<input class='map_filter_title' id='{{dict.position}}__map_filter_title' type='text'
name='{{dict.position}}__map_filter_title' placeholder='The title of the filter'
value="{{dict.map_filter_title}}">
<input class='map_filter_bind_query'
id='{{dict.position}}__map_filter_bind_query'
type='hidden'
name='{{dict.position}}__map_filter_bind_query'
value='{{dict.map_filter_bind_query}}'>
<input class='map_filter_bind_query' id='{{dict.position}}__map_filter_bind_query' type='hidden'
name='{{dict.position}}__map_filter_bind_query' value='{{dict.map_filter_bind_query}}'>
<textarea class='addplaceholder_mapfilter' oninput='auto_grow(this)'
name='{{dict.position}}__map_filter_query' type='text'
id='{{dict.position}}__map_filter_query' rows='6'
data-bind-query='{{dict.map_filter_bind_query}}'
required>{{dict.map_filter_query}}</textarea>
</div>
{% endif %}
</div>
{% endif %}


{% endfor %}

</div>
<!-- ADD buttons -->
<section class="addfieldssection col-md-12 col-lg-12 col-sm-12">
<a class="btn btn-primary btn-border" onclick="add_field(name)" name="mapWithFilters">Add
<a class="btn btn-primary btn-border" onclick="add_field(name)" name="map">Add
a map with filters</a>
</section>
</div>
Expand Down Expand Up @@ -219,11 +214,11 @@ <h4 class="block_title">Add map filter</h4>
{% endif %}

{% for dict in datastory_data.dynamic_elements %}
{% if dict.type == 'map' %}
<script type="text/javascript">
{% if dict.type == 'map' %}
<script type="text/javascript">
var map = initMap("{{dict.position}}");
</script>
{% endif %}
</script>
{% endif %}
{% endfor %}

{% endblock javascripts %}
{% endblock javascripts %}
32 changes: 32 additions & 0 deletions templates/modify_statistics.html
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,30 @@ <h4>Scatter Plot</h4>
</div>
</div>

<!-- MAP -->
{% elif dict.type == 'map' %}
<div id="{{dict.position}}__block_field">
<h4 class="block_title">Add map</h4>
<a href="#" class="trash" id="{{dict.position}}__trash" name="{{dict.position}}__trash">
<i class="far fa-trash-alt" id="{{dict.position}}__bin"></i>
</a>
<br>
<!-- map title -->
<input class='map_title' id='{{dict.position}}__map_title' type='text'
name='{{dict.position}}__map_title' value='{{dict.map_title}}'
placeholder='The title of the map'>
<!-- data points -->
<textarea class='addplaceholder_points' oninput='auto_grow(this)'
name='{{dict.position}}__map_points_query' type='text'
id='{{dict.position}}__map_points_query' rows='10'
required>{{dict.map_points_query}}</textarea>
<a onclick='rerunQuery({{dict.position}})' data-id='{{dict.position}}_rerun_query'
data-run='true' href="#{{dict.position}}__map_points_query">Rerun the query</a>
<!-- map preview -->
<div class="map_preview_container" id="{{dict.position}}__map_preview_container">
</div>
</div>

{% endif %}

{% endfor %}
Expand Down Expand Up @@ -547,4 +571,12 @@ <h4>Scatter Plot</h4>
</script>
{% endif %}

{% for dict in datastory_data.dynamic_elements %}
{% if dict.type == 'map' %}
<script type="text/javascript">
var map = initMap("{{dict.position}}");
</script>
{% endif %}
{% endfor %}

{% endblock javascripts %}

0 comments on commit 423fdc2

Please sign in to comment.