def generate_vector_color_map(self): """Generate color stops array for use with match expression in mapbox template""" vector_stops = [] for row in self.data: # map color to JSON feature using color_property color = color_map(row[self.color_property], self.color_stops, self.color_default) # link to vector feature using data_join_property (from JSON object) vector_stops.append([row[self.data_join_property], color]) return vector_stops
def generate_vector_color_map(self): """Generate color stops array for use with match expression in mapbox template""" vector_stops = [] # if join data specified as filename or URL, parse JSON to list of Python dicts if type(self.data) == str: self.data = geojson_to_dict_list(self.data) # loop through features in self.data to create join-data map for row in self.data: # map color to JSON feature using color_property color = color_map(row[self.color_property], self.color_stops, self.color_default) # link to vector feature using data_join_property (from JSON object) vector_stops.append([row[self.data_join_property], color]) return vector_stops
def test_color_map_interp_exact(): """Compute color for lookup value exactly matching numeric stop in color stops""" interp_stops = [[0.0, 'rgb(255,0,0)'], [50.0, 'rgb(255,255,0)'], [1000.0, 'rgb(0,0,255)']] assert color_map(0.0, interp_stops, 'rgb(32,32,32)') == 'rgb(255,0,0)'
def test_color_map_interp(): """Compute color for lookup value by interpolation of color stops""" interp_stops = [[0.0, 'rgb(255,0,0)'], [50.0, 'rgb(255,255,0)'], [1000.0, 'rgb(0,0,255)']] assert color_map(17, interp_stops, 'orange') == 'rgb(255,87,0)'
def test_color_map_numeric_match(): """Get color for numeric lookup value in categorical color stops if number exists in stops""" match_stops = [[0.0, 'rgb(255,0,255)'], ['CA', 'rgb(255,0,0)'], ['NY', 'rgb(255,255,0)'], ['MA', 'rgb(0,0,255)']] assert color_map(0.0, match_stops, 'green') == 'rgb(255,0,255)'
def test_color_map_default_color(): """Default color when look up value does not match any stop in categorical color stops""" match_stops = [[0.0, 'rgb(255,0,255)'], ['CA', 'rgb(255,0,0)'], ['NY', 'rgb(255,255,0)'], ['MA', 'rgb(0,0,255)']] assert color_map('MI', match_stops, 'gray') == 'gray'
def test_color_map(): """Compute color for lookup value in gradient based on color_stops argument using categorical match""" match_stops = [[0.0, 'rgb(255,0,255)'], ['CA', 'rgb(255,0,0)'], ['NY', 'rgb(255,255,0)'], ['MA', 'rgb(0,0,255)']] assert color_map('CA', match_stops, default_color='gray') == 'rgb(255,0,0)'