function generateLegend(scale, id) {
	var domain = scale.domain().reverse();
	console.log(domain)

	// Go through each color and return the sorted domain of values that corresponds to each class
	var breaks = $.map(scale.range(), function(color) {
		var current = []
		for (i = domain[0]; i <= domain[1]; i++) {
			if (scale(i) == color) {
				current.push(i);
			}
		}

		return {
			color: color,
			min: d3.min(current),
			max: d3.max(current),
		}
	});

	var row = d3.select('#' + id)
		.selectAll('div')
		.data(breaks)
		.enter().append('div')
		.classed('legend-row clearfix', true)

	// Add the legend cell
	row.append('div')
		.classed('legend-cell', true)
		.style('background-color', function(d) {
			// Extract the RGB value from the RGBA string
			return d.color;
		})

	row.append('div')
		.classed('legend-label', true)
		.text(function(d) {
			return d.min + ' to ' + d.max;
		});
}
// Given a domain array, scale, colors and div id, generate a legend
Given a domain array, scale, colors and div id, generate a legend
Given a domain array scale colors and div id generate a legend
function generateLegend(scale, id) {
	var domain = scale.domain().reverse();
	console.log(domain)
	var breaks = $.map(scale.range(), function(color) {
		var current = []
		for (i = domain[0]; i <= domain[1]; i++) {
			if (scale(i) == color) {
				current.push(i);
			}
		}
		return {
			color: color,
			min: d3.min(current),
			max: d3.max(current),
		}
	});
	var row = d3.select('#' + id)
		.selectAll('div')
		.data(breaks)
		.enter().append('div')
		.classed('legend-row clearfix', true)
	row.append('div')
		.classed('legend-cell', true)
		.style('background-color', function(d) {
			return d.color;
		})
	row.append('div')
		.classed('legend-label', true)
		.text(function(d) {
			return d.min + ' to ' + d.max;
		});
}
function generateLegend ( scale , id ) { var domain = scale . domain ( ) . reverse ( ) ; console . log ( domain ) var breaks = $ . map ( scale . range ( ) , function ( color ) { var current = [ ] for ( i = domain [ 0 ] ; i <= domain [ 1 ] ; i ++ ) { if ( scale ( i ) == color ) { current . push ( i ) ; } } return { color : color , min : d3 . min ( current ) , max : d3 . max ( current ) , } } ) ; var row = d3 . select ( '#' + id ) . selectAll ( 'div' ) . data ( breaks ) . enter ( ) . append ( 'div' ) . classed ( 'legend-row clearfix' , true ) row . append ( 'div' ) . classed ( 'legend-cell' , true ) . style ( 'background-color' , function ( d ) { return d . color ; } ) row . append ( 'div' ) . classed ( 'legend-label' , true ) . text ( function ( d ) { return d . min + ' to ' + d . max ; } ) ; }
Given a domain array, scale, colors and div id, generate a legend
Given a domain array scale colors and div id generate a legend
// Go through each color and return the sorted domain of values that corresponds to each class // Add the legend cell // Extract the RGB value from the RGBA string