From b9e027a8b3c409447c30da51f2763f533d52ce09 Mon Sep 17 00:00:00 2001
From: esikkala <esko.ikkala@aalto.fi>
Date: Mon, 25 Oct 2021 17:00:28 +0300
Subject: [PATCH] Polygon layer: set fill opacity

---
 src/client/components/facet_results/Deck.js     | 17 ++++++++++++++++-
 .../perspectives/sampo/Perspective1.js          |  6 +++---
 src/client/reducers/sampo/perspective1.js       |  6 +++++-
 src/server/sparql/sampo/BackendSearchConfig.js  |  4 ++--
 .../sparql_queries/SparqlQueriesPerspective1.js |  2 +-
 5 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/src/client/components/facet_results/Deck.js b/src/client/components/facet_results/Deck.js
index 206bede3..fc804884 100644
--- a/src/client/components/facet_results/Deck.js
+++ b/src/client/components/facet_results/Deck.js
@@ -199,7 +199,7 @@ class Deck extends React.Component {
         filled: true,
         lineWidthMinPixels: 1,
         getPolygon: d => d.polygon,
-        getFillColor: d => [255, 0, 0, 30],
+        getFillColor: d => [255, 0, 0, d.instanceCountScaled],
         getLineColor: [80, 80, 80],
         getLineWidth: 1
       })
@@ -270,6 +270,21 @@ class Deck extends React.Component {
               viewState={this.state.viewport}
               layers={[layer]}
               getCursor={() => 'initial'}
+              {...(layerType === 'polygonLayer'
+                ? {
+                    getTooltip: ({ object }) => object && {
+                      html: `
+                      <h2>${object.prefLabel}</h2>
+                      <div>${object.instanceCount}</div>
+                    `
+                    // style: {
+                    //   backgroundColor: '#f00',
+                    //   fontSize: '0.8em'
+                    // }
+                    }
+                  }
+                : {})
+              }
             />
             {this.renderSpinner()}
             {layerType === 'arcLayer' && this.props.instanceAnalysisData && this.state.dialog.open &&
diff --git a/src/client/components/perspectives/sampo/Perspective1.js b/src/client/components/perspectives/sampo/Perspective1.js
index 10b2a315..d7a02617 100644
--- a/src/client/components/perspectives/sampo/Perspective1.js
+++ b/src/client/components/perspectives/sampo/Perspective1.js
@@ -208,13 +208,13 @@ const Perspective1 = props => {
         path={`${rootUrl}/${perspective.id}/faceted-search/choropleth_map`}
         render={() =>
           <Deck
-            center={props.perspectiveState.maps.placesMsMigrations.center}
-            zoom={props.perspectiveState.maps.placesMsMigrations.zoom}
+            center={props.perspectiveState.maps.casualtiesByMunicipality.center}
+            zoom={props.perspectiveState.maps.casualtiesByMunicipality.zoom}
             results={props.perspectiveState.results}
             facetUpdateID={props.facetState.facetUpdateID}
             instanceAnalysisData={props.perspectiveState.instanceAnalysisData}
             instanceAnalysisDataUpdateID={props.perspectiveState.instanceAnalysisDataUpdateID}
-            resultClass='choropleth'
+            resultClass='casualtiesByMunicipality'
             facetClass='perspective1'
             fetchResults={props.fetchResults}
             fetchInstanceAnalysis={props.fetchInstanceAnalysis}
diff --git a/src/client/reducers/sampo/perspective1.js b/src/client/reducers/sampo/perspective1.js
index f6d24d75..842d401c 100644
--- a/src/client/reducers/sampo/perspective1.js
+++ b/src/client/reducers/sampo/perspective1.js
@@ -37,6 +37,10 @@ export const INITIAL_STATE = {
     placesMsMigrations: {
       center: [22.43, 10.37],
       zoom: 2
+    },
+    casualtiesByMunicipality: {
+      center: [65.184809, 27.314050],
+      zoom: 4
     }
   },
   properties: [
@@ -292,7 +296,7 @@ const resultClasses = new Set([
   'manuscriptFacetResultsNetwork',
   'perspective1KnowledgeGraphMetadata',
   'speechesByYearAndParty',
-  'choropleth'
+  'casualtiesByMunicipality'
 ])
 
 const perspective1 = (state = INITIAL_STATE, action) => {
diff --git a/src/server/sparql/sampo/BackendSearchConfig.js b/src/server/sparql/sampo/BackendSearchConfig.js
index 245aeae0..0acc9961 100644
--- a/src/server/sparql/sampo/BackendSearchConfig.js
+++ b/src/server/sparql/sampo/BackendSearchConfig.js
@@ -170,7 +170,7 @@ export const backendSearchConfig = {
       }
     }
   },
-  choropleth: {
+  casualtiesByMunicipality: {
     perspectiveID: 'warsa',
     q: choroplethQuery,
     resultMapper: makeObjectList,
@@ -179,7 +179,7 @@ export const backendSearchConfig = {
       config: {
         variable: 'instanceCount',
         minAllowed: 0,
-        maxAllowed: 1
+        maxAllowed: 255
       }
     }
   },
diff --git a/src/server/sparql/sampo/sparql_queries/SparqlQueriesPerspective1.js b/src/server/sparql/sampo/sparql_queries/SparqlQueriesPerspective1.js
index 0e2fb53e..1036173d 100644
--- a/src/server/sparql/sampo/sparql_queries/SparqlQueriesPerspective1.js
+++ b/src/server/sparql/sampo/sparql_queries/SparqlQueriesPerspective1.js
@@ -603,7 +603,7 @@ export const choroplethQuery = `
     ?id a <http://www.yso.fi/onto/suo/kunta> ;
         skos:prefLabel ?prefLabel ;
         sch:polygon ?polygon .
-    ?death crm-org:P7_took_place_at ?id .
+    OPTIONAL { ?death crm-org:P7_took_place_at ?id }
   }
   GROUP BY ?id ?prefLabel ?polygon
   ORDER BY desc(?instanceCount)
-- 
GitLab