Skip to content

Instantly share code, notes, and snippets.

@lenagroeger
Created June 17, 2014 16:19
Show Gist options
  • Save lenagroeger/8ba9f4c0c08649ea8211 to your computer and use it in GitHub Desktop.
Save lenagroeger/8ba9f4c0c08649ea8211 to your computer and use it in GitHub Desktop.
guns model/view
//////// THE MODEL, making GunsMap and defining the function getColors();////////
propublica.models.GunsMap = propublica.Model.extend({
getColors : function() {
var arr = ["H001064","D000191","L000573","A000369","K000382","M000133","L000559","S000522","C000714","Y000033","H001050"]
$(".carto .tiny_size .color_overlay").each(function() {
var bioid = $(this).parents(".member_box").attr("data-id");
if (arr.indexOf(bioid) > -1) {
var cur = $(this).attr("data-state")
var color = color2color($(this).css("background-color"), "rgb"); //get the color
var rgb = color.match(/rgb\((\d+), ?(\d+), ?(\d+)/) //parse the color
var o = Math.round(((parseInt(rgb[1], 10) * 299) + (parseInt(rgb[2], 10) * 587) + (parseInt(rgb[3], 10) * 114)) /1000); //calculate its brightness
if((o < 125) && $(this).is(":visible")) {
$('.stabv_'+ cur).css('color', 'white'); //change the label color so you can read it!
}else{
$('.stabv_'+ cur).css('color', 'black');
}
}
});
},
getPositions : function() {
var currentCat = $("*[class$='selected'] a").attr("href").slice(1)
var item = $(".isotope-item")
item.each( function() {
var item = $(this);
var currentScale = item.attr("data-"+currentCat)
var xPosition = item.data("x")
var yPosition = item.data("y")
item.find(".color_overlay").addClass(currentScale)
item.css({
'left': + xPosition +40 +'px',
'top': + yPosition - 10 +'px'
});
});
}
});
var GunsMap = new propublica.models.GunsMap();
//////// THE VIEW, calling GunsMap.getColors(); ////////
propublica.views.cartoSidePanel = propublica.View.extend({
tag : "",
cssClass : "carto-bt",
bindings : {
click : "filterItems",
},
render : function() {
_.bindAll(this, "foo_button_clicked");
},
foo_button_clicked : function($button) {
$(".iso").removeClass("active");
$button.addClass("active");
},
filterItems : function(e) {
var cur = $(e.currentTarget);
var att = cur.find(".iso").data('filter_att');
$(".isotope-item").hide();
$(att+".House").show();
this.foo_button_clicked(cur.find(".iso"));
GunsMap.getColors();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment