Skip to content

Commit

Permalink
fix instgraam locations display logic via click instead of hover
Browse files Browse the repository at this point in the history
  • Loading branch information
do-me committed Jul 24, 2024
1 parent b5f24ae commit 6fc8627
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ <h5><label for="margin" class="d-inline-block" data-toggle="tooltip"
<button type="button" id="queryData" class="btn btn-primary" disabled>Submit</button>
<br>
<br>
<h5><label data-toggle="tooltip" title="Instagram Locations in last-hovered hexbin">Instagram
Locations</label></h5>
<h5><label data-toggle="tooltip" title="Instagram Locations in last-clicked hexbin">Instagram
Locations (click hexbin)</label></h5>
<div id="locations"></div>


Expand Down
35 changes: 22 additions & 13 deletions static/assets/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ $(document).ready(function () {
}
));

hexLayer.dispatch()
.on('click', function(d, i) {
//console.log({ type: 'click', event: d, index: i, context: this });
hexagon_click(d);
});

updateRadius()

updateColorValueFunction()
Expand Down Expand Up @@ -286,18 +292,6 @@ $(document).ready(function () {
const maxScore = aboveThreshold.reduce((max, obj) => Math.max(max, obj["o"]["score"]), 0);
/////////////////////////////////////////////////////

var locations = d.reduce(function (acc, obj) { acc.push(obj["o"]["node.location_id"]); return acc; }, []);
locations = [...new Set(locations)]

let locationsHTML = ""; // initialize result variable as empty string

for (let i = 0; i < locations.length; i++) {
const element = locations[i];
const href = `https://www.instagram.com/explore/locations/${element}`; // generate href attribute
const link = `<a href="${href}" target="_blank">${element}</a>`; // wrap element in a tag
locationsHTML += link + "<br>"; // concatenate link and <br> tag to result
}

// plain html version
var tooltip_text =
`<table>
Expand All @@ -324,9 +318,24 @@ $(document).ready(function () {
// Posts: ${String(SumCounts)}<br>
// Posts Above Threshold: ${String(aboveThresholdSumCounts)}<br>
// Highest Score (Color): ${String(maxScore.toFixed(2))}<br>`
return tooltip_text
}

function hexagon_click(d){
var locations = d.reduce(function (acc, obj) { acc.push(obj["o"]["node.location_id"]); return acc; }, []);
locations = [...new Set(locations)]

let locationsHTML = ""; // initialize result variable as empty string

for (let i = 0; i < locations.length; i++) {
const element = locations[i];
const href = `https://www.instagram.com/explore/locations/${element}`; // generate href attribute
const link = `<a href="${href}" target="_blank">${element}</a>`; // wrap element in a tag
locationsHTML += link + "<br>"; // concatenate link and <br> tag to result
}

$("#locations").html(locationsHTML)
return tooltip_text

}

function updateRadius() {
Expand Down

0 comments on commit 6fc8627

Please sign in to comment.