max_p = max([item['population'] for item in data]) for item in data: item.update({'z': item['population']}) item.update({ 'color': interpolateRGB([0, 10, 255], [255, 10, 0], item['population'] / max_p) }) H.add_map_data(geojson, name='Basemap', borderColor='#606060', nullColor='rgba(200, 200, 200, 0.2)', showInLegend=False) H.add_data_set(geojson_handler(geojson, 'mapline'), 'mapline', 'Separators', showInLegend=False, enableMouseTracking=False) H.add_data_set(data, 'mapbubble', 'Cities', dataLabels={ 'enabled': True, 'format': '{point.capital}' }, maxSize='12%', is_coordinate=True) H.set_dict_options(options)
1. url is the url (https) where data is located 2. "prefix_regex" and "suffix_regex" are regex patterns used to remove JSONP specific prefix and suffix, such as callback header: "callback(" and end: ");", 3. "sub_d" is regex patterns for any unwanted string in loaded json data (will be replaced by sub_by). 4. "sub_by" is the string to replace any unwanted string defined by sub_d For function coverstion, such as Data.UTC to datetime.datetime, please check JSONPDecoder 2. js_map_loader(url) js_map_loader is to load map data from a .js source. It is designed for using highcharts' map collection: https://code.highcharts.com/mapdata/. Map data from other sources are not guaranteed """ data_url = 'http://www.highcharts.com/samples/data/us-counties-unemployment.json' map_url = 'http://code.highcharts.com/mapdata/countries/us/us-all-all.js' data = json_loader(data_url) geojson = js_map_loader(map_url) """ Convert loaded mapadata into the format readable by highcharts using geojson_handler geojson_handler(geojson, hType='map') geojson_handler is similar to highcharts.geojson function, which is to restructure a geojson object to be add directly by add_map_data or add_data_set method. The geojson will be broken down to fit a specific Highcharts (highmaps) type, either map, mapline or mappoint. Meta data in GeoJSON's properties object will be copied directly over to object['properties'] 1. geojson is the map data (GeoJSON) to be converted 2. hType is the type of highmap types. "map" will return GeoJSON polygons and multipolygons. "mapline" will return GeoJSON linestrings and multilinestrings. "mappoint" will return GeoJSON points and multipoints. default: "map" """ mapdata = geojson_handler(geojson)
'align': 'left', 'x': 5, 'verticalAlign': 'middle' } }] fake_data = [] options = { 'title': { 'text': 'Highmaps basic lat/lon demo' }, 'mapNavigation': { 'enabled': True }, 'tooltip': { 'headerFormat': '', 'pointFormat': '<b>{point.name}</b><br>Lat: {point.lat}, Lon: {point.lon}' }, } H.add_map_data(geojson, name = 'Basemap' ,borderColor = '#A0A0A0', nullColor = 'rgba(200, 200, 200, 0.3)', showInLegend = False) H.add_data_set(data,'mappoint','Cities',color = 'Highcharts.getOptions().colors[1]', is_coordinate = True) H.add_data_set(geojson_handler(geojson, 'mapline'), 'mapline','Separators',color = '#707070', showInLegend = False, enableMouseTracking = False) H.set_dict_options(options) H.htmlcontent
}""", } H = Highmap() """ Drilldown map requires an additional JS library from highcharts, which can be added using add_JSsource method Also, it needs a bootstrap CSS file, which is added using add_CSSsource method """ H.add_JSsource('http://code.highcharts.com/maps/modules/drilldown.js') H.add_CSSsource( 'http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css') map_url = 'http://code.highcharts.com/mapdata/countries/us/us-all.js' geojson = js_map_loader(map_url) data = geojson_handler(geojson) for i, item in enumerate(data): item.update({'drilldown': item['properties']['hc-key']}) item.update({'value': i}) # add bogus data options = { 'chart': { 'events': { 'drilldown': Drilldown_functions_dict['US_States'], 'drillup': "function () {\ this.setTitle(null, { text: 'USA' });\ }", }
'text': 'Highmaps from geojson with multiple geometry types' }, 'mapNavigation': { 'enabled': True, 'buttonOptions': { 'verticalAlign': 'bottom' } }, } H.set_dict_options(options) map_url = 'http://www.highcharts.com/samples/data/australia.geo.json' geojson = json_loader(map_url) states = geojson_handler(geojson, 'map') rivers = geojson_handler(geojson, 'mapline') cities = geojson_handler(geojson, 'mappoint') specialCityLabels = { 'Melbourne': { 'align': 'right' }, 'Canberra': { 'align': 'right', 'y': -5 }, 'Wollongong': { 'y': 5 }, 'Brisbane': { 'y': -5
H = Highmap() """ Drilldown map requires an additional JS library from highcharts, which can be added using add_JSsource method Also, it needs a bootstrap CSS file, which is added using add_CSSsource method """ H.add_JSsource('http://code.highcharts.com/maps/modules/drilldown.js') H.add_CSSsource('http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css') map_url = 'http://code.highcharts.com/mapdata/countries/us/us-all.js' geojson = js_map_loader(map_url) data = geojson_handler(geojson) for i, item in enumerate(data): item.update({'drilldown':item['properties']['hc-key']}) item.update({'value': i}) # add bogus data options = { 'chart' : { 'events': { 'drilldown': Drilldown_functions_dict['US_States'], 'drillup': "function () {\ this.setTitle(null, { text: 'USA' });\ }", } },
}, 'mapNavigation': { 'enabled': True, 'buttonOptions': { 'verticalAlign': 'bottom' } }, } H.set_dict_options(options) map_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=australia.geo.json&callback=?' geojson = jsonp_loader(map_url) states = geojson_handler(geojson, 'map') rivers = geojson_handler(geojson, 'mapline') cities = geojson_handler(geojson, 'mappoint') specialCityLabels = { 'Melbourne': { 'align': 'right' }, 'Canberra': { 'align': 'right', 'y': -5 }, 'Wollongong': { 'y': 5 }, 'Brisbane': { 'y': -5
The drilldown data can be added using add_drilldown_data_set method: add_drilldown_data_set(data, series_type, id, **kwargs) 1. data is the dataset for drilldown level 2. series_type is the type of plot presented at the drilldown level 3. id is the identifier used for the drilldown parent point to identify its series. This needs to be consistent with the drilldown property in dataset of parent level 4. kwargs are for parameters in series or plotOptions (for detail please ref to highcharts API: http://api.highcharts.com/highcharts#) However, the tradeoff is that user needs to query and handle the whole dataset in python environment and put the whole dataset into the .html file, which could make final file very big. """ map_url = 'http://code.highcharts.com/mapdata/countries/us/us-all.js' geojson = js_map_loader(map_url) data = geojson_handler(geojson) for i, item in enumerate(data): item.update({'drilldown':item['properties']['hc-key']}) item.update({'value': i}) # add bogus data options = { 'chart' : { 'events': { # Here event option is only used to change the tittle when different level data is shown 'drilldown': "function(e){\ this.setTitle({ text: e.point.name }, null)\ }", 'drillup': "function () {\ this.setTitle({ text: 'USA' }, null);\ }", }
2. "prefix_regex" and "suffix_regex" are regex patterns used to remove JSONP specific prefix and suffix, such as callback header: "callback(" and end: ");", 3. "sub_d" is regex patterns for any unwanted string in loaded json data (will be replaced by sub_by). 4. "sub_by" is the string to replace any unwanted string defined by sub_d For function coverstion, such as Data.UTC to datetime.datetime, please check JSONPDecoder 2. js_map_loader(url) js_map_loader is to load map data from a .js source. It is designed for using highcharts' map collection: https://code.highcharts.com/mapdata/. Map data from other sources are not guaranteed """ data_url = 'http://www.highcharts.com/samples/data/jsonp.php?filename=us-counties-unemployment.json&callback=?' map_url = 'http://code.highcharts.com/mapdata/countries/us/us-all-all.js' data = jsonp_loader(data_url) geojson = js_map_loader(map_url) """ Convert loaded mapadata into the format readable by highcharts using geojson_handler geojson_handler(geojson, hType='map') geojson_handler is similar to highcharts.geojson function, which is to restructure a geojson object to be add directly by add_map_data or add_data_set method. The geojson will be broken down to fit a specific Highcharts (highmaps) type, either map, mapline or mappoint. Meta data in GeoJSON's properties object will be copied directly over to object['properties'] 1. geojson is the map data (GeoJSON) to be converted 2. hType is the type of highmap types. "map" will return GeoJSON polygons and multipolygons. "mapline" will return GeoJSON linestrings and multilinestrings. "mappoint" will return GeoJSON points and multipoints. default: "map" """ mapdata = geojson_handler(geojson)
The drilldown data can be added using add_drilldown_data_set method: add_drilldown_data_set(data, series_type, id, **kwargs) 1. data is the dataset for drilldown level 2. series_type is the type of plot presented at the drilldown level 3. id is the identifier used for the drilldown parent point to identify its series. This needs to be consistent with the drilldown property in dataset of parent level 4. kwargs are for parameters in series or plotOptions (for detail please ref to highcharts API: http://api.highcharts.com/highcharts#) However, the tradeoff is that user needs to query and handle the whole dataset in python environment and put the whole dataset into the .html file, which could make final file very big. """ map_url = 'http://code.highcharts.com/mapdata/countries/us/us-all.js' geojson = js_map_loader(map_url) data = geojson_handler(geojson) for i, item in enumerate(data): item.update({'drilldown': item['properties']['hc-key']}) item.update({'value': i}) # add bogus data options = { 'chart' : { 'events': { # Here event option is only used to change the tittle when different level data is shown 'drilldown': "function(e){\ this.setTitle({ text: e.point.name }, null)\ }" , 'drillup': "function () {\ this.setTitle({ text: 'USA' }, null);\ }" , }