Skip to content

Commit

Permalink
More coffee, local random feed working so far
Browse files Browse the repository at this point in the history
  • Loading branch information
fw42 committed May 20, 2013
1 parent f9dd906 commit 3fae834
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 99 deletions.
70 changes: 30 additions & 40 deletions static/coffee/honeymap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,10 @@ See website for license and contact information.
###

class Honeymap

constructor: (config) ->

@config = config

@hits =
region: {}
regionCount: {}
marker: {}
@markers =
captions: {}
count: 0

@hits = { region: { total: {} }, marker: { total: 0 } }
@captions = {}
@mapElem = jQuery('#world-map')
@fitSize()
@mapElem.vectorMap(
Expand All @@ -35,16 +26,15 @@ class Honeymap
scale: config.colors.scale
attribute: 'fill'
normalizeFunction: 'linear'
values: @hits.region
values: {}
]
onRegionLabelShow: (ev, label, code) =>
label.html("<big>" + label.html() + "</big>")
label.append(Honeymap.eventCountSummary(@hits.region[code]))
onMarkerLabelShow: (ev, label, code) =>
label.html(@markerCaptions[code])
label.html(@captions[code])
label.append(Honeymap.eventCountSummary(@hits.marker[code]))
)

@mapObj = @mapElem.vectorMap('get', 'mapObject')
@mapObj.regions['US'].config.name = "USA"

Expand All @@ -57,15 +47,15 @@ class Honeymap
@mapObj.series.regions[0].params.min = null
@mapObj.series.regions[0].params.max = null
# Update data
@mapObj.series.regions[0].setValues(@hits.regionCount)
@mapObj.series.regions[0].setValues(@hits.region["total"])

removeOldestMarker: ->
# only remove src markers
toremove = jQuery(@mapElem.find("svg g circle.jvectormap-marker[fill=" + @config.colors.src.fill + "]")[0])

par = toremove.parent()
@mapObj.removeMarkers([ toremove.attr('data-index') ])

id = toremove.attr('data-index')
delete(@captions[id])
@mapObj.removeMarkers([ id ])
# Remove parent node too (jVectorMap does not do this by itself)
par.remove()

Expand All @@ -84,36 +74,36 @@ class Honeymap
return null

incMarkerCount: (marker) ->
@hits.marker[marker.id()] ||= {}
@hits.marker[marker.id()][marker.eventName] ||= 0
@hits.marker[marker.id()][marker.eventName]++
# only count src markers which are within a valid region
if marker.type == 'src' and rc = marker.regionCode
@hits.region[rc] ||= {}
@hits.region[rc][marker.eventName] ||= 0
@hits.region[rc][marker.eventname]++

@hits.marker[marker.id] ||= {}
@hits.marker[marker.id][marker.eventName] ||= 0
@hits.marker[marker.id][marker.eventName]++
return unless marker.type == 'src' and rc = marker.regionCode
@hits.region[rc] ||= {}
@hits.region[rc][marker.eventName] ||= 0
@hits.region[rc][marker.eventName]++
@hits.region["total"][rc] ||= 0
@hits.region["total"][rc]++

addMarker: (marker) ->
marker.animate()
@updateRegionColors()
@captions[marker.id()] = marker.caption()
@incMarkerCount(marker)
@updateRegionColors()

# only add new markers to jVectorMap which do not exist yet
return unless @mapObj.markers[marker.id]
# only add new markers div's to jVectorMap which do not exist yet
if @mapObj.markers[marker.id()]
console.log(marker.id() + " already exists")
return

@markers.count++
if @markers.count >= config.markersMaxVisible then @removeOldestMarker()
@mapObj.addMarker(marker.id(), { latLng: marker.gps(), name: marker.name, style: @config.colors[marker.type] }, [])
@hits.marker["total"]++
if @hits.marker["total"] > config.markersMaxVisible then @removeOldestMarker()
@mapObj.addMarker(marker.id(), { latLng: marker.gps(), name: marker.name(), style: @config.colors[marker.type] }, [])

@eventCountSummary: (hits) ->
summary = ""
return unless hits?
total = 0

summary = "<hr/>"
for type, count of hits
if total == 0 then summary += "<hr/>"
summary += "<b>" + type + "</b>: " + (count || 0) + "<br/>"
total += count

if total > 0 then summary += "<hr/><b>total</b>: " + total + " events"
return summary
summary += "<b>" + type + "</b>: " + (total += (count ||= 0)) + "<br/>"
summary + "<hr/><b>total</b>: " + total + " events"
7 changes: 4 additions & 3 deletions static/coffee/log.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Log
constructor: (config) ->
@elem = jQuery("#log")
@max = config.markers_visible
@max = config.markersMaxVisible
@fitSize()

fitSize: ->
Expand All @@ -11,8 +11,9 @@ class Log

clearOld: ->
entries = @elem.find("div.log_entry")
if entries.length > @max
entries.slice(0, entries.length - 1 - @max).remove()
if entries.length >= @max
console.log("clearing")
entries.slice(0, entries.length/2).remove()
@elem.find("br").nextUntil('div.log_entry', 'br').remove()

add: (msg) ->
Expand Down
22 changes: 8 additions & 14 deletions static/coffee/marker.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Marker

constructor: (map, lat, lng, type, eventName, regionCode, cityName) ->
@map = map
@lat = lat
Expand All @@ -24,17 +23,12 @@ class Marker
)
)

id: ->
@lat + "," + @lng

name: ->
"(" + @lat + ", " + @lng + ")"

gps: ->
[ @lat, @lng ]

regionName: ->
@map.mapObj.getRegionName(@regionCode) if @regionCode
caption: ->
caption = "<small>(" + @lat + ", " + @lng + ")</small><br/>"
caption += "<big>" + @cityName + "</big> (" + @regionCode + ")" if @cityName
return caption

setCaption: (caption) ->
@map.markerCaptions[@id()] = caption
id: -> @lat + "," + @lng
name: -> "(" + @lat + ", " + @lng + ")"
gps: -> [ @lat, @lng ]
regionName: -> @map.mapObj.getRegionName(@regionCode) if @regionCode
93 changes: 51 additions & 42 deletions static/js/honeymap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3fae834

Please sign in to comment.