Skip to content

Commit 5523c37

Browse files
Adding hyper links to access data
1 parent 5665203 commit 5523c37

8 files changed

Lines changed: 180 additions & 84 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ Additional columns can be added, though they will appear in the table view only.
2424
This GeoJSON file can be created using https://geojson.io. A brief outline of how to create this file at the given web address is as follows:
2525
- Navigate to the farm location by using an address in the search bar
2626
- Use the polygon tool (the square icon) to create shapes outlining each pen denoted in the .csv file
27-
- After creating each pen polygon, **click** within the shape to reveal a pop-up, enter 'id' (without quotes) into the left table cell, enter the pen number in the right table cell, click **Save** from within the popup.
27+
- After creating each pen polygon, **click** within the shape to reveal a pop-up, enter 'id' (without quotes) into the left table cell (adding the attribute 'id'), enter the pen number in the right table cell, click **Save** from within the popup.
28+
- These 'id' numbers are used to join the pen number to the appropriate pen location
2829
- After adding all pens (with 'id' numbers), click **Save** on the top left of the interface. This will save a GeoJSON file to your computer. You will be able to reopen this within https://geojson.io to continue to edit
29-
the map, if needed.
30+
the map, if needed.
31+
- Note: If you'd like to see additional attributes in the popup, you can add them. And if you assign an attribute named 'name', this will appear on the map next to the 'id'.
3032

3133
## Running the App
3234
Once you have both required files on your computer, make sure they are saved in the same directory. Navigate to https://geospatialcentroid.github.io/bird_flu_cattle. Within your file system, navigate to the folder where the required files are saved and drag them, in turn, to the file input field of the application.

app.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name,type,data,title_col,filter_cols,date,show_cols,drawing_info,legend
2-
pens,geojson,data/Farm_AL_7.23.25.geojson,id,,,id," {
2+
pens,geojson,data/Farm AL_8.29.25.geojson,id,,,id," {
33
""renderer"": {
44
""type"": ""simple"",
55
""symbol"": {
@@ -41,7 +41,7 @@ pens,geojson,data/Farm_AL_7.23.25.geojson,id,,,id," {
4141
]
4242
}
4343
]}"
44-
movement,csv,data/Farm AL Centroid Data Cleaned 7.22.25.csv,ID,,DATE,," {
44+
movement,csv,data/Farm AL Centroid Data Cleaned 9.9.25.csv,ID,,DATE,," {
4545
""renderer"": {
4646
""type"": ""simple"",
4747
""symbol"": {

css/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,3 +1007,9 @@ input.label{
10071007
font-weight:bold;
10081008

10091009
}
1010+
1011+
.hyper{
1012+
color: blue;
1013+
text-decoration: underline;
1014+
cursor:pointer;
1015+
}

index.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,14 @@
137137
<button id="date_advance_backward" class="btn btn-outline-secondary " onclick="record_manager.move_to_date(-1)" type="button"><i class="bi bi-arrow-left-short"></i></button>
138138
<button id="date_advance_forward" class="btn btn-outline-secondary " onclick="record_manager.move_to_date(1)" type="button"><i class="bi bi-arrow-right-short"></i></button>
139139
</div>
140+
141+
<label class="form-check-label font-weight-bold" for="date_first_infection">First Date of infection</label>
142+
<button id="date_first_infection" class="btn btn-outline-secondary " type="button"></button>
143+
140144
</div>
141145
<div class="col" >
142-
<span class="font-weight-bold">Total Unique Cows:</span> <span id="total_items"></span> <br/>
143-
<span class="font-weight-bold">Duplicate Cows:</span> <span id="duplicate_items"></span> <br/>
146+
<span class="font-weight-bold">Total Unique Cows:</span> <span id="total_items" class="hyper"></span> <br/>
147+
<span class="font-weight-bold">Duplicate Cows:</span> <span id="duplicate_items" class="hyper"></span> <br/>
144148
<div id="cow_count_list"></div>
145149
<span id="warning"></span>
146150
</div>

js/index.js

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ function after_filter(){
169169

170170
record_manager.clean_data()
171171

172+
172173
$("#model_data_form").on("hidden.bs.modal", function () {
173174
process_data_forms();
174175
$("#filter_current_date").trigger('change');
@@ -198,7 +199,7 @@ function setup_interface(_event_settings){
198199
}
199200
load_data("images/cow.svg","",populate_legend)
200201
populate_cow_list()
201-
console.log(event_data)
202+
record_manager.get_first_infection_date()
202203

203204
setTimeout(function(){
204205
if(record_manager.params && record_manager.params[0].date){
@@ -231,7 +232,7 @@ function populate_cow_list(){
231232
for(var i in event_settings){
232233
var obj = event_settings[i]
233234
if(obj["type"]!='plot'){
234-
html+=" <span class='font-weight-bold'>"+obj.label+" Cows:</span> <span id='total_"+obj.label+"'></span> <br/>"
235+
html+=" <span class='font-weight-bold'>"+obj.label+" Cows:</span> <span class='hyper' id='total_"+obj.label+"'></span> <br/>"
235236
}
236237
}
237238

@@ -283,76 +284,3 @@ function populate_cow_list(){
283284

284285
}
285286

286-
create_plot= function(data){
287-
288-
$("#plot").empty()
289-
290-
if(data.length==0){
291-
$("#plot").hide()
292-
return
293-
}
294-
$("#plot").show()
295-
296-
// set the dimensions and margins of the graph
297-
var row_height=25
298-
const margin = {top: 18, right: 0, bottom:25, left: 40},
299-
width = 120 - margin.left - margin.right,
300-
height = (row_height*(data.length+1)) - margin.top - margin.bottom;
301-
302-
// append the svg object to the body of the page
303-
const svg = d3.select("#plot")
304-
.append("svg")
305-
.attr("width", width + margin.left + margin.right)
306-
.attr("height", height + margin.top + margin.bottom)
307-
.append("g")
308-
.attr("transform", `translate(${margin.left}, ${margin.top})`);
309-
310-
311-
svg.append("text")
312-
.attr("x", (0))
313-
.attr("y", 0 - (margin.top / 2))
314-
.style("font-size", "11px")
315-
.style("font-weight", "bolder")
316-
.style('fill', 'black')
317-
.text("Originating Pen")
318-
319-
320-
var extent = d3.extent(data, function(d) {
321-
return d.value;
322-
});
323-
324-
// Add X axis
325-
const x = d3.scaleLinear()
326-
.domain([0, extent[1]])
327-
.range([ 0, width])
328-
329-
svg.append("g")
330-
.attr("transform", `translate(0, ${height})`)
331-
.call(d3.axisBottom(x).ticks(2,d3.format('0f'))).style('color', 'black')
332-
.selectAll("text")
333-
.attr("transform", "translate(-10,0)rotate(-45)")
334-
.style("text-anchor", "end")
335-
.style('color', 'black')
336-
337-
// Y axis
338-
const y = d3.scaleBand()
339-
.range([ 0, height ])
340-
.domain(data.map(d => d.name))
341-
.padding(.1);
342-
svg.append("g")
343-
.call(d3.axisLeft(y))
344-
.style('color', 'black')
345-
346-
//Bars
347-
svg.selectAll("myRect")
348-
.data(data)
349-
.join("rect")
350-
.attr("x", x(0) )
351-
.attr("y", d => y(d.name))
352-
.attr("width", d => x(d.value))
353-
.attr("height", y.bandwidth())
354-
.attr("fill", "black")
355-
356-
357-
358-
}

js/map_manager.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,86 @@ class Map_Manager {
226226
}
227227
}
228228

229+
create_plot= function(data){
229230

231+
$("#plot").empty()
232+
233+
if(data.length==0){
234+
$("#plot").hide()
235+
return
236+
}
237+
$("#plot").show()
238+
239+
// set the dimensions and margins of the graph
240+
var row_height=25
241+
const margin = {top: 18, right: 10, bottom:25, left: 40},
242+
width = 120 - margin.left - margin.right,
243+
height = (row_height*(data.length+1)) - margin.top - margin.bottom;
244+
245+
// append the svg object to the body of the page
246+
const svg = d3.select("#plot")
247+
.append("svg")
248+
.attr("width", width + margin.left + margin.right)
249+
.attr("height", height + margin.top + margin.bottom)
250+
.append("g")
251+
.attr("transform", `translate(${margin.left}, ${margin.top})`);
252+
253+
254+
svg.append("text")
255+
.attr("x", (0))
256+
.attr("y", 0 - (margin.top / 2))
257+
.style("font-size", "11px")
258+
.style("font-weight", "bolder")
259+
.style('fill', 'black')
260+
.text("Originating Pen")
261+
262+
263+
var extent = d3.extent(data, function(d) {
264+
return d.value;
265+
});
266+
267+
// Add X axis
268+
const x = d3.scaleLinear()
269+
.domain([0, extent[1]])
270+
.range([ 0, width])
271+
272+
svg.append("g")
273+
.attr("transform", `translate(0, ${height})`)
274+
.call(d3.axisBottom(x).ticks(2,d3.format('0f'))).style('color', 'black')
275+
.selectAll("text")
276+
.attr("transform", "translate(-10,0)rotate(-45)")
277+
.style("text-anchor", "end")
278+
.style('color', 'black')
279+
280+
// Y axis
281+
const y = d3.scaleBand()
282+
.range([ 0, height ])
283+
.domain(data.map(d => d.name))
284+
.padding(.1);
285+
const yAxisG = svg.append("g")
286+
.call(d3.axisLeft(y))
287+
.style('color', 'blue')
288+
.style('text-decoration', 'underline')
289+
290+
// add a click handler to each tick label
291+
yAxisG.selectAll(".tick text")
292+
.style("cursor", "pointer")
293+
.on("click", function(event, d) {
294+
// show all the data for the pens with originating infections
295+
record_manager.show_orig_sick_pen_data(d)
296+
});
297+
298+
//Bars
299+
svg.selectAll("myRect")
300+
.data(data)
301+
.join("rect")
302+
.attr("x", x(0) )
303+
.attr("y", d => y(d.name))
304+
.attr("width", d => x(d.value))
305+
.attr("height", y.bandwidth())
306+
.attr("fill", "black")
307+
308+
309+
310+
}
230311

js/record_manager.js

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,31 @@ class Record_Manager {
344344

345345
}
346346
}
347+
get_first_infection_date(){
348+
var infection_val=false
349+
var infection_record
350+
for(var i in event_settings){
351+
var e = event_settings[i]
352+
if(e["type"]=='cluster_color'){
353+
infection_val= e.start
354+
break
355+
}
356+
}
357+
358+
if(infection_val){
359+
for(var i=0;i<this.json_data.length;i++){
360+
if(this.json_data[i]["EVENT"]==infection_val){
361+
infection_record = this.json_data[i]
362+
$("#date_first_infection").html(infection_record["START DATE"].format('YYYY-MM-DD'))
363+
$("#date_first_infection").click(function() {
364+
$("#filter_current_date").datepicker().val( infection_record["START DATE"].format('YYYY-MM-DD'))
365+
$("#filter_current_date").trigger('change');
366+
});
367+
break
368+
}
369+
}
370+
}
371+
}
347372

348373
search_by_date(_date){
349374
// let's search for records that fall on a date
@@ -408,19 +433,52 @@ class Record_Manager {
408433
}
409434
}
410435
$("#total_items").html( this.id_track["ids"].length)
436+
// add hyper link to data access
437+
$("#total_items").off("click");
438+
$("#total_items").click(function() {
439+
record_manager.format_data_for_show(record_manager.id_track["ids"],["ID"])
440+
});
441+
411442
$("#duplicate_items").html( this.id_track["duplicate_ids"].length)
443+
$("#duplicate_items").off("click");
444+
$("#duplicate_items").click(function() {
445+
record_manager.format_data_for_show(record_manager.id_track["duplicate_ids"],["ID"])
446+
});
412447
// Show totals
413448
for(var i in event_settings){
414449
var obj = event_settings[i]
415450
if(obj["type"]!='plot'){
416451
$("#total_"+obj.label).html(this.id_track[obj.label].length)
452+
$("#total_"+obj.label).data('label', obj.label);
453+
$("#total_"+obj.label).off("click");
454+
console.log(this.id_track[obj.label])
455+
$("#total_"+obj.label).click(function() {
456+
var label= $(this).data('label')
457+
record_manager.format_data_for_show(record_manager.id_track[label],["ID"])
458+
});
417459
}
418460
}
419461

420462
//
421463
this.show_orig_sick_pen(_date.unix())
422464
this.show_pen_warning()
423465
}
466+
format_data_for_show(data,attrs){
467+
// take an array and convert it to a list of json objects
468+
console.log(data)
469+
var temp_array = data.map(item => {
470+
// if it's not already an array, wrap it so indexing works
471+
const values = Array.isArray(item) ? item : [item];
472+
473+
// build {attr1: val1, attr2: val2, ...}
474+
return attrs.reduce((obj, key, i) => {
475+
obj[key] = values[i] !== undefined ? values[i] : null; // or leave undefined
476+
return obj;
477+
}, {});
478+
});
479+
table_manager.show_data(temp_array)
480+
}
481+
424482
create_pen_warning(pen,t){
425483
// track the unique pens and give a warning
426484
if(!(String(pen) in this.id_track["pen_warning"])){
@@ -461,17 +519,28 @@ class Record_Manager {
461519
if(!ids?.[match_days[i]["from_pen"]]){
462520
ids[match_days[i]["from_pen"]]=[]
463521
}
464-
ids[match_days[i]["from_pen"]].push(match_days[i])
522+
// for ease of future access convert end_date and start_date into formatted datetime objects
523+
var matched_day=Object.assign({}, match_days[i]);
524+
matched_day["start_date"]=moment.unix(matched_day["start_date"]).format('YYYY-MM-DD')
525+
matched_day["end_date"]=moment.unix(matched_day["end_date"]).format('YYYY-MM-DD')
526+
ids[match_days[i]["from_pen"]].push(matched_day)
465527
}
466-
// console.log(ids)
528+
//store the originating pen for later
529+
this.match_days_ids=ids
467530
// convert to CSV
468531
var data =[]
469532
for(var i in ids){
470533
data.push({"name":i,"value":ids[i].length})
471534
}
472-
create_plot(data.sort((a, b) => b.value - a.value)) // Ascending order)
535+
create_plot(data.sort((a, b) => b.value - a.value)) // Ascending order
473536
}
474537
}
538+
show_orig_sick_pen_data(pen){
539+
console.log(this.match_days_ids[pen])
540+
// create a temporary json obj converting the end_date and start_date into formatted datetime objects
541+
542+
table_manager.show_data(this.match_days_ids[pen])
543+
}
475544
show_data(_id,_attr,_at_date){
476545
var data=[];
477546
for(var i=0;i<this.json_data.length;i++){

js/table_manager.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,12 @@ class Table_Manager {
508508
// }
509509
// }
510510
}
511+
show_data(data){
512+
console.log(data)
513+
this.json_data=data
514+
this.generate_table(data,true)
515+
this.show_totals()
516+
}
511517
show_totals(){
512518

513519
var showing_start=1

0 commit comments

Comments
 (0)