commit 894e33392a56cacc3523e5de3179d31f5e74fd19
Author: Martin Sebela <msebela@zcu.cz>
Date:   Sat Oct 24 00:47:05 2020 +0200

    Re #8163 - refactoring

diff --git a/website/public/css/style.css b/website/public/css/style.css
index 97ab56d..d61cea7 100644
--- a/website/public/css/style.css
+++ b/website/public/css/style.css
@@ -1225,12 +1225,7 @@ p.logos-partners a:first-of-type img {
   background: url("../img/btn-next.svg") rgba(125, 125, 125, 0.1) no-repeat center center;
 }
 
-.leaflet-popup-content-wrapper #part-info {
-  margin-left: 5px;
-  font-size: 11pt;
-}
-
-.leaflet-popup-content-wrapper #number-info {
+.leaflet-popup-content-wrapper #place-intesity {
   display: flex;
   align-items: center;
   justify-content: center;
@@ -1239,6 +1234,11 @@ p.logos-partners a:first-of-type img {
   font-weight: 700;
 }
 
+.leaflet-popup-content-wrapper #part-info {
+  margin-left: 5px;
+  font-size: 11pt;
+}
+
 .leaflet-popup-content-wrapper #pages {
   margin: auto;
   color: #ffffff;
diff --git a/website/public/css/style.scss b/website/public/css/style.scss
index 1e51686..d06a17a 100755
--- a/website/public/css/style.scss
+++ b/website/public/css/style.scss
@@ -1134,12 +1134,7 @@ p.logos-partners {
     }
   }
 
-  #part-info {
-    margin-left: 5px;
-    font-size: 11pt;
-  }
-
-  #number-info {
+  #place-intesity {
     display: flex;
     align-items: center;
     justify-content: center;
@@ -1148,6 +1143,11 @@ p.logos-partners {
     font-weight: 700;
   }
 
+  #part-info {
+    margin-left: 5px;
+    font-size: 11pt;
+  }
+
   #pages {
     margin: auto;
     color: $primary-text-color;
diff --git a/website/public/js/zcu-heatmap.js b/website/public/js/zcu-heatmap.js
index 0fb65f6..667fe1b 100644
--- a/website/public/js/zcu-heatmap.js
+++ b/website/public/js/zcu-heatmap.js
@@ -77,7 +77,7 @@ const disablePopupControls = () => {
   $('.popup-controls').hide()
 }
 
-const areSameCoord = (first, second) => {
+const areCoordsIdentical = (first, second) => {
   return first.lat === second.lat && first.lng === second.lng
 }
 
@@ -175,7 +175,7 @@ const genPopUpControls = (controls) => {
 
 const genMultipleDatasetsPopUp = (sum, currentPage, countPages, datasetName) => {
   const popupHeader = `<strong id="dataset-name">${datasetName}</strong>`
-  const popupData = `<div id="number-info"><span id="current-number">${sum}</span></div>`
+  const popupData = `<div id="place-intesity"><span id="current-number">${sum}</span></div>`
   const { previousButton, nextButton, pagesList } = getPaginationButtonsInPopup(currentPage, countPages)
 
   return `
@@ -195,7 +195,7 @@ const getPopupContent = (datasetName, placeName, currentCount, sum, currentPage,
     <strong>${datasetName}</strong>
     <div id="place-name">${placeName}</div>`
   const popupData = `
-    <div id="number-info">
+    <div id="place-intesity">
       <span id="current-number">${currentCount}</span>
       <span id="part-info">${(sum && sum !== Number(currentCount)) ? '/' + sum : ''}</span>
     </div>`
@@ -215,7 +215,7 @@ const onCheckboxClicked = async (checkbox) => {
     loadCheckboxDatasetNameData()
 
     data.forEach((item, index) => {
-      Object.keys(item).forEach((datasetName) => {
+      Object.keys(item).forEach(datasetName => {
         if (datasetName === $(checkbox).val()) {
           delete data[index][datasetName]
         }
@@ -295,6 +295,7 @@ function initMap () {
 
 const getCountPagesInPopup = () => {
   const infoKeys = Object.keys(info)
+
   if (infoKeys.length === 1) {
     // return number of records in one dataset (one dataset in area)
     return info[infoKeys[0]].items.length
@@ -303,22 +304,22 @@ const getCountPagesInPopup = () => {
   return infoKeys.length
 }
 
-const getElFromObjectInfo = (position) => {
+const getPopupDataOnPage = (pageInPopup) => {
   const keys = Object.keys(info)
-  return info[keys[position]]
+  return info[keys[pageInPopup]]
 }
 
-const hasInfoMultipleDatasets = () => {
+const areMultipleDatasetsInRadius = () => {
   return Object.keys(info).length > 1
 }
 
-const setNewPopupDatasetName = (datasetName) => {
+const setPopupDatasetClassName = (datasetName) => {
   const popup = $('.leaflet-popup')
 
   popup.removeClass(function (index, css) {
-    return (css.match (/(^|\s)popup-\S+/g) || []).join(' ');
+    return (css.match(/(^|\s)popup-\S+/g) || []).join(' ');
   })
-  popup.addClass(`popup-${datasetName}`)
+  popup.addClass('popup-' + datasetName)
 }
 
 function showInfo (e) {
@@ -341,8 +342,10 @@ function showInfo (e) {
     lng: e.latlng.lng,
     lat: e.latlng.lat
   }
-  Object.keys(data[currentTime]).forEach((key) => {
+
+  Object.keys(data[currentTime]).forEach(key => {
     const namedData = data[currentTime][key]
+
     namedData.items.forEach(element => {
       if (e.latlng.distanceTo(new L.LatLng(element.x, element.y)) < radius) {
         lat += element.x
@@ -369,11 +372,10 @@ function showInfo (e) {
     acc[item.datasetName].number += Number(item.number)
     return acc
   }, {})
-  // There is one dataset
 
-  const numDatasets = Object.keys(datasetsInRadius).length
+  const countDatasets = Object.keys(datasetsInRadius).length
 
-  if (!numDatasets) {
+  if (!countDatasets) {
     if (mymap._popup) {
       $('#part-info').text('')
       $('#current-number').html(0)
@@ -383,33 +385,33 @@ function showInfo (e) {
     return
   }
 
-  if (numDatasets === 1) {
-    const infoDict = getElFromObjectInfo(0)
-    const info_ = infoDict.items
-    const { place, number } = info_[currentPageInPopup]
+  if (countDatasets === 1) {
+    const markersInRadius = getPopupDataOnPage(0)
+    const popupPagesData = markersInRadius.items
+    const { place, number } = popupPagesData[currentPageInPopup]
 
-    if (!globalPopup._popup || !areSameCoord(globalPopup.coord, eventCoord)) {
-      globalPopup._popup = prepareLayerPopUp(lat, lng, i, `popup-${infoDict.datasetName}`)
+    if (!globalPopup._popup || !areCoordsIdentical(globalPopup.coord, eventCoord)) {
+      globalPopup._popup = prepareLayerPopUp(lat, lng, i, `popup-${markersInRadius.datasetName}`)
       globalPopup.coord = eventCoord
     }
     else {
-      setNewPopupDatasetName(infoDict.datasetName)
+      setPopupDatasetClassName(markersInRadius.datasetName)
     }
 
-    setGlobalPopupContent(getPopupContent(datasetDictNameDisplayName[infoDict.datasetName], place, number, total, 1, info_.length))
+    setGlobalPopupContent(getPopupContent(datasetDictNameDisplayName[markersInRadius.datasetName], place, number, total, 1, popupPagesData.length))
 
-    if (info_.length === 1) {
+    if (popupPagesData.length === 1) {
       disablePopupControls()
     }
   } else {
-    const { datasetName, number } = getElFromObjectInfo(currentPageInPopup)
+    const { datasetName, number } = getPopupDataOnPage(currentPageInPopup)
 
-    if (!globalPopup._popup || !areSameCoord(globalPopup.coord, eventCoord)) {
+    if (!globalPopup._popup || !areCoordsIdentical(globalPopup.coord, eventCoord)) {
       globalPopup._popup = prepareLayerPopUp(lat, lng, i, `popup-${datasetName}`)
       globalPopup.coord = eventCoord
     }
     else {
-      setNewPopupDatasetName(datasetName)
+      setPopupDatasetClassName(datasetName)
     }
 
     setGlobalPopupContent(genMultipleDatasetsPopUp(number, 1, getCountPagesInPopup(), datasetDictNameDisplayName[datasetName]))
@@ -435,8 +437,8 @@ function setNextPageInPopup () {
 }
 
 function setPageContentInPopup (page) {
-  const previousPageData = hasInfoMultipleDatasets() ? getElFromObjectInfo(page) : getElFromObjectInfo(0).items[page]
-  const currentPageData = hasInfoMultipleDatasets() ? getElFromObjectInfo(currentPageInPopup) : getElFromObjectInfo(0).items[currentPageInPopup]
+  const previousPageData = areMultipleDatasetsInRadius() ? getPopupDataOnPage(page) : getPopupDataOnPage(0).items[page]
+  const currentPageData = areMultipleDatasetsInRadius() ? getPopupDataOnPage(currentPageInPopup) : getPopupDataOnPage(0).items[currentPageInPopup]
   const datasetName = $('#dataset-name')
 
   if (datasetName) {
