From 84d87d9609a0bf5dfa5be1c956b4e6f6f4096c00 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 30 Mar 2019 16:51:22 +0100 Subject: update mapppppp --- client/map/index.js | 65 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 24 deletions(-) (limited to 'client/map/index.js') diff --git a/client/map/index.js b/client/map/index.js index b35ffddb..a1c728d9 100644 --- a/client/map/index.js +++ b/client/map/index.js @@ -37,25 +37,31 @@ const redDot = L.icon({ popupAnchor: [0, -5] // point from which the popup should open relative to the iconAnchor }) -function addMarker(map, latlng, title, addresses, year, pdf) { +function addMarker(map, latlng, citations) { const marker = L.marker(latlng, { icon: redDot }).addTo(map) - let message = [ - "", title, "", - ] - if (pdf && pdf.length) { - message.unshift("") - message.push("") - } + let message = citations.map(citation => { + const { title, addresses, year, pdf, doi } = citation + let rec = [ + "", title, "", + ] + if (pdf && pdf.length) { + rec.unshift("") + rec.push("") + } + else if (doi && doi.length) { + rec.unshift("") + rec.push("") + } + const addressString = addresses.map(addr => addr.name).join('
') + rec.push("
") + rec.push(addressString) + if (year) { + rec.push(" (" + year + ")") + } + return rec.join("") + }) - const addressString = addresses.map(addr => addr.name).join('
') - message = message.concat([ - "
", - addressString, - ]) - if (year) { - message.push(" (" + year + ")") - } - marker.bindPopup(message.join('')) + marker.bindPopup(message.join('

')) return marker } @@ -73,7 +79,7 @@ function addArc(map, src, dest, arcStyle) { export default function append(el, payload) { const { data } = payload if (!data) return - let { paper, addresses, citations } = data + let { paper, citations } = data let source = [0, 0] let map = L.map(el).setView([25, 0], 2) @@ -87,30 +93,41 @@ export default function append(el, payload) { accessToken: 'pk.eyJ1IjoiZmFuc2FsY3kiLCJhIjoiY2pvN3I1czJwMHF5NDNrbWRoMWpteHlrdCJ9.kMpM5syQUhVjKkn1iVx9fg' }).addTo(map) - if (addresses && addresses.length) { - source = [address[0].lat, address[0].lng].map(n => (parseFloat(n) || 0)) + if (paper.addresses && paper.addresses.length) { + source = [paper.addresses[0].lat, paper.addresses[0].lng].map(n => (parseFloat(n) || 0)) } else { console.error("No address found for root paper") // console.log(data) } // group papers by address + let citationsByAddress = {} citations.forEach(citation => { - console.log(citation) if (!citation.addresses) { console.log(citation) return } - const citationAddress = citation.addresses[0] + citation.addresses.forEach(address => { + if (!(address.name in citationsByAddress)) { + citationsByAddress[address.name] = { address, citations: []} + } + citationsByAddress[address.name].citations.push(citation) + }) + }) + + Object.keys(citationsByAddress).map(name => { + const { citations: citationList, address: citationAddress } = citationsByAddress[name] + console.log(name, citationsByAddress[name]) + // console.log(citation) const latlng = [citationAddress.lat, citationAddress.lng].map(n => parseFloat(n)) if (Number.isNaN(latlng[0]) || Number.isNaN(latlng[1])) return - addMarker(map, latlng, citation.title, citation.addresses, citation.year, citation.pdf) + addMarker(map, latlng, citationList) addArc(map, source, latlng, arcStyles[citationAddress.type]) }) console.log(paper) - const rootMarker = addMarker(map, source, paper.title, addresses, paper.year) + const rootMarker = addMarker(map, source, [paper]) rootMarker.openPopup() // a transparent div to cover the map, so normal scroll events will not be eaten by leaflet -- cgit v1.2.3-70-g09d2 From 9d1915af786379446ac7465215b6f3679f270e19 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 30 Mar 2019 18:50:32 +0100 Subject: map scroll --- client/map/index.js | 18 ++++++++++++++---- site/assets/css/applets.css | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'client/map/index.js') diff --git a/client/map/index.js b/client/map/index.js index a1c728d9..9ca43867 100644 --- a/client/map/index.js +++ b/client/map/index.js @@ -52,12 +52,12 @@ function addMarker(map, latlng, citations) { rec.unshift("") rec.push("") } - const addressString = addresses.map(addr => addr.name).join('
') - rec.push("
") - rec.push(addressString) if (year) { rec.push(" (" + year + ")") } + const addressString = addresses.map(addr => addr.name).join('
') + rec.push("
") + rec.push(addressString) return rec.join("") }) @@ -107,6 +107,7 @@ export default function append(el, payload) { console.log(citation) return } + console.log(citation) citation.addresses.forEach(address => { if (!(address.name in citationsByAddress)) { citationsByAddress[address.name] = { address, citations: []} @@ -122,7 +123,16 @@ export default function append(el, payload) { const latlng = [citationAddress.lat, citationAddress.lng].map(n => parseFloat(n)) if (Number.isNaN(latlng[0]) || Number.isNaN(latlng[1])) return addMarker(map, latlng, citationList) - addArc(map, source, latlng, arcStyles[citationAddress.type]) + const style = { ...arcStyles[citationAddress.type] } + let weight = Math.min(citationList.length, 5) + let opacity = 0.5 + Math.min(citationList.length / 5, 0.5) + if (citationAddress.type !== 'edu') { + weight += 1 + opacity = 1 + } + style.weight = String(weight) + style.opacity = opacity + addArc(map, source, latlng, style) }) console.log(paper) diff --git a/site/assets/css/applets.css b/site/assets/css/applets.css index e5c427b2..10c0e786 100644 --- a/site/assets/css/applets.css +++ b/site/assets/css/applets.css @@ -168,6 +168,10 @@ .desktop .map_cover:hover { opacity: 1; } +.leaflet-popup-content-wrapper { + max-height: 230px; + overflow-y: auto; +} .leaflet-popup-content a { color: #0078A8; border-bottom: 1px solid rgba(0, 128, 160, 0.4); -- cgit v1.2.3-70-g09d2 From 438cde0ab82cf9fdbdcbb45e0ad8e43efc3525bb Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sun, 31 Mar 2019 17:40:44 +0200 Subject: hide pdf --- client/chart/pie.charts.js | 5 ++++- client/index.js | 4 ++-- client/map/index.js | 8 ++++---- scraper/client/paper/paper.verify.js | 14 ++++++++++---- site/assets/css/applets.css | 12 +++++++++++- site/public/about/faq/index.html | 11 +++++------ site/public/about/press/index.html | 7 +++---- site/public/about/privacy/index.html | 7 +++---- site/public/about/terms/index.html | 7 +++---- 9 files changed, 45 insertions(+), 30 deletions(-) (limited to 'client/map/index.js') diff --git a/client/chart/pie.charts.js b/client/chart/pie.charts.js index 6e579537..84e85c3a 100644 --- a/client/chart/pie.charts.js +++ b/client/chart/pie.charts.js @@ -17,6 +17,7 @@ class PieCharts extends Component { render() { const { payload } = this.props const { paper, citations } = payload.data + console.log(this.props) if (!citations.length) return null const countries = {} @@ -83,9 +84,10 @@ class PieCharts extends Component { } }} size={{ - height: 336, + height: countryRows.length < 4 ? 316 : 336, }} /> + {paper.name}{' dataset citations by country'}
+ {paper.name}{' dataset citations by organization type'}
) diff --git a/client/index.js b/client/index.js index 5c8bc880..5a7315b5 100644 --- a/client/index.js +++ b/client/index.js @@ -87,9 +87,9 @@ function runApplets() { if (dataset === 'index.html') { dataset = path.pop() } - console.log('dataset from path:', dataset) + // console.log('dataset from path:', dataset) } else { - console.log('not on a dataset page') + // console.log('not on a dataset page') return [el, payload] } } diff --git a/client/map/index.js b/client/map/index.js index 9ca43867..475ba3c6 100644 --- a/client/map/index.js +++ b/client/map/index.js @@ -104,10 +104,10 @@ export default function append(el, payload) { let citationsByAddress = {} citations.forEach(citation => { if (!citation.addresses) { - console.log(citation) + // console.log(citation) return } - console.log(citation) + // console.log(citation) citation.addresses.forEach(address => { if (!(address.name in citationsByAddress)) { citationsByAddress[address.name] = { address, citations: []} @@ -118,7 +118,7 @@ export default function append(el, payload) { Object.keys(citationsByAddress).map(name => { const { citations: citationList, address: citationAddress } = citationsByAddress[name] - console.log(name, citationsByAddress[name]) + // console.log(name, citationsByAddress[name]) // console.log(citation) const latlng = [citationAddress.lat, citationAddress.lng].map(n => parseFloat(n)) if (Number.isNaN(latlng[0]) || Number.isNaN(latlng[1])) return @@ -135,7 +135,7 @@ export default function append(el, payload) { addArc(map, source, latlng, style) }) - console.log(paper) + // console.log(paper) const rootMarker = addMarker(map, source, [paper]) rootMarker.openPopup() diff --git a/scraper/client/paper/paper.verify.js b/scraper/client/paper/paper.verify.js index 83eb5b44..fcebac02 100644 --- a/scraper/client/paper/paper.verify.js +++ b/scraper/client/paper/paper.verify.js @@ -60,6 +60,7 @@ class PaperVerify extends Component { ...initialState, ...citationState, ...address.paper, + pdfIndex: citationState.citations.pdf.findIndex(el => el.pdf.match(/^http:/)), } this.setState(newState) } else if (verify && !verify.loading && verify.paper && (!oldPaper || oldPaper !== verify.paper)) { @@ -70,6 +71,7 @@ class PaperVerify extends Component { ...initialState, ...citationState, ...address.paper, + pdfIndex: citationState.citations.pdf.findIndex(el => el.pdf.match(/^http:/)), } this.setState(newState) } else { @@ -79,6 +81,7 @@ class PaperVerify extends Component { newState = { ...citationState, ...address.paper, + pdfIndex: citationState.citations.pdf.findIndex(el => el.pdf.match(/^http:/)), uses_dataset: paper.uses_dataset, images_in_paper: paper.images_in_paper, verified_by: paper.verified_by, @@ -156,7 +159,7 @@ class PaperVerify extends Component { if (citationIndex < 0) { history.push('/paper/' + key + '/info/') } else { - let nextId = citations[citationIndex].id + let nextId = sortedCitations[citationIndex].id history.push('/paper/' + key + '/verify/' + nextId) } } @@ -172,10 +175,10 @@ class PaperVerify extends Component { history.push('/paper/' + key + '/info/') } else { citationIndex += 1 - if (citationIndex >= citations.length) { + if (citationIndex >= sortedCitations.length) { history.push('/paper/' + key + '/info/') } else { - let nextId = citations[citationIndex].id + let nextId = sortedCitations[citationIndex].id history.push('/paper/' + key + '/verify/' + nextId) } } @@ -414,7 +417,10 @@ class PaperVerify extends Component { >{'Next >'} -