From aa87db6b846bd07da611afa459bbf298255a3328 Mon Sep 17 00:00:00 2001 From: efarooqui Date: Wed, 30 Sep 2020 10:53:15 -0700 Subject: [PATCH] Working cluster visualization; need to modify styling for clusters for size and work out color based on events --- src/common/utilities.js | 4 +++ src/components/Map.jsx | 22 +++++++++++- .../presentational/Map/Clusters.jsx | 35 ++++++++++++++++--- src/store/initial.js | 2 +- 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/common/utilities.js b/src/common/utilities.js index dac0f4a..3690363 100644 --- a/src/common/utilities.js +++ b/src/common/utilities.js @@ -168,6 +168,10 @@ export function calcOpacity (num) { return base + (Math.min(0.5, 0.08 * (num - 1))) } +export function calcClusterSize (pointCount, numClusters) { + return Math.min(50, 10 + (pointCount / numClusters) * 20) +} + export const dateMin = function () { return Array.prototype.slice.call(arguments).reduce(function (a, b) { return a < b ? a : b diff --git a/src/components/Map.jsx b/src/components/Map.jsx index 5dcafbf..f31b389 100644 --- a/src/components/Map.jsx +++ b/src/components/Map.jsx @@ -12,6 +12,7 @@ import 'leaflet' import Sites from './presentational/Map/Sites.jsx' import Shapes from './presentational/Map/Shapes.jsx' import Events from './presentational/Map/Events.jsx' +import Clusters from './presentational/Map/Clusters.jsx' import SelectedEvents from './presentational/Map/SelectedEvents.jsx' import Narratives from './presentational/Map/Narratives' import DefsMarkers from './presentational/Map/DefsMarkers.jsx' @@ -262,6 +263,10 @@ class Map extends React.Component { return [null, null] } + styleCluster (cluster) { + return [null, null] + } + renderEvents () { const individualClusters = this.state.clusters.filter(cl => !cl.properties.cluster) const filteredLocations = individualClusters.map(cl => this.props.domain.locations.find(location => location.label === cl.properties.id)) @@ -282,6 +287,20 @@ class Map extends React.Component { ) } + renderClusters () { + const allClusters = this.state.clusters.filter(cl => cl.properties.cluster) + return ( + {}} + /> + ) + } + renderSelected () { return ( @@ -313,6 +332,7 @@ class Map extends React.Component { {this.renderShapes()} {this.renderNarratives()} {this.renderEvents()} + {this.renderClusters()} {this.renderSelected()} ) : null diff --git a/src/components/presentational/Map/Clusters.jsx b/src/components/presentational/Map/Clusters.jsx index 6752491..c738520 100644 --- a/src/components/presentational/Map/Clusters.jsx +++ b/src/components/presentational/Map/Clusters.jsx @@ -1,18 +1,43 @@ import React from 'react' import { Portal } from 'react-portal' import colors from '../../../common/global.js' -import { calcOpacity } from '../../../common/utilities' +import { calcOpacity, calcClusterSize } from '../../../common/utilities' function ClusterEvents ({ projectPoint, styleCluster, - onSelect, + // onSelect, svg, clusters, - radius + numClusters, }) { function renderClusterBySize (cluster) { + const { point_count, cluster_id } = cluster.properties + const size = calcClusterSize(point_count, numClusters) + + const width = `${size}px` + const height = `${size}px` + + const styles = ({ + fill: 'blue', + stroke: colors.darkBackground, + strokeWidth: 0, + fillOpacity: calcOpacity(point_count), + width, + height + }) + + return ( + + + + ) } @@ -47,7 +72,7 @@ function ClusterEvents ({ {renderClusterBySize(cluster)} {extraRender ? extraRender() : null} @@ -57,7 +82,7 @@ function ClusterEvents ({ return ( - + {clusters.map(renderCluster)} diff --git a/src/store/initial.js b/src/store/initial.js index 623cc9f..d811cbd 100644 --- a/src/store/initial.js +++ b/src/store/initial.js @@ -53,7 +53,7 @@ const initial = { maxZoom: 18, bounds: null, maxBounds: [[180, -180], [-180, 180]], - clusterRadius: 40, + clusterRadius: 50, }, timeline: { dimensions: {