Template:CountryLocator
<graph mode="interactive"> {
"width": 250,
"height": 100,
"padding": 0,
"idkey": "properties.code",
"mark": {
"strokeWidth":0.5,
"strokeOpacity":0.5
},
"signals": [
{"name": "country", "init": "CA"},
{"name": "centerLat", "init": "56.130366"},
{"name": "centerLon", "init": "-106.346771"},
{"name": "miniX", "init": {"expr":"155+50+((centerLon)*95/360)-5"} },
{"name": "miniY", "init": {"expr":"60+20+((centerLat)*-40/140)+5"} },
{"name": "tooltip",
"init": {"expr": "{x: 0, y: 0, datum: false }"},
"streams": [
{"type": "@map:mouseout, @map:touchstart", "expr": "{x: 0, y: 0, datum: false }" },
{"type": "@map:mouseover, @map:touchstart", "expr": "{x: eventX(), y: eventY(), datum: eventItem().datum}" }
]
}
],
"data": [
{
"name": "highlights",
"values": [
{
"code": "CA",
"v": "royalblue"
},{
"code": "",
"v": "orangered"
}
],
"default": { "v":"#ccc" }
},{
"name": "mini",
"url": "wikiraw:///Template:Graph:Map/Inner/Worldmap2c-json",
"format": {"type": "topojson", "feature": "collection"},
"transform": [{
"type": "geopath",
"projection": "equirectangular",
"scale": 15,
"translate": [202, 84]
}]
},{
"name": "world",
"url": "wikiraw:///Template:Graph:Map/Inner/Worldmap2c-json",
"format": {"type": "topojson", "feature": "collection"},
"transform": [{
"type": "geopath",
"projection": "equirectangular",
"scale": 350,
"rotate":[{"expr":"(centerLon * -1)-10"},{"expr":"(centerLat * -1) - 2"},0],
"translate": [{"expr":"(width/2)+0"}, {"expr":"(height/2)+0"}]
},{
"type": "formula",
"field": "my_id",
"expr": "datum.properties.code"
},{
"type": "formula",
"field": "my_name",
"expr": "datum.properties.name"
},{
"type": "formula",
"field": "my_width",
"expr": "length(datum.properties.name)*7+10"
},{
"type": "lookup",
"keys": ["my_id"],
"on": "highlights",
"onKey": "code",
"as": ["zipped"],
"values": ["v"],
"default": {"v": "#ccc"}
}]
},{
"name": "dummyValue",
"values": [{}]
}],
"marks": [
{
"name": "map",
"type": "path",
"from": {"data": "world"},
"properties": {
"enter": {
"fill":{"value": "#ccc"},
"stroke": {"value": "#eee"},
"path": {"field": "layout_path"}
},
"update": {"fill": {"field": "zipped.v"} },
"hover": {"fill": {"value": "lightsteelblue"} }
}
},{
"type": "rect",
"properties": {
"enter": {
"x":{"value":155},
"y":{"value":60},
"width":{"value": 100},
"height":{"value": 45},
"fill":{"value": "#fff"},
"stroke":{"value":"#ccc"}
}
}
},{
"type": "path",
"from": {"data": "mini"},
"properties": {
"enter": {
"stroke": {"value": "#999"},
"strokeWidth":{"value": 0},
"background":{"value": "#fff"},
"path": {"field": "layout_path"}
},
"update": {
"fill": {"value": "#333"},
"strokeWidth":{"value": 0}
}
}
},{
"type": "symbol",
"properties": {
"enter": {
"shape":"circle",
"x": {"signal":"miniX"},
"y": {"signal":"miniY"},
"size": {"value": 40},
"stroke": {"value": "lightsteelblue"},
"fill": {"value": "royalblue"}
}
}
},{
"name": "tooltip",
"type": "group",
"from": {
"data": "dummyValue",
"transform": [
{"type": "filter", "test": "tooltip.datum"},
{"type": "formula", "field": "offsetX", "expr": "5"},
{"type": "formula", "field": "offsetY", "expr": "15"},
{"type": "formula", "field": "lookupCountry", "expr": "tooltip.datum.properties.code"},
{ "type": "lookup", "on": "world", "onKey": "my_id", "keys": ["lookupCountry"], "as": ["mapDataVal"], "default": null },
{"type": "formula", "field": "tipWidth", "expr": "datum.mapDataVal ? datum.mapDataVal.my_width : '90'"},
{"type": "formula", "field": "tipHeight", "expr": "20"},
{"type": "formula", "field": "alignLeft", "expr": "tooltip.x > width - datum.offsetX - datum.tipWidth"},
{"type": "formula", "field": "alignTop", "expr": "tooltip.y > height - datum.offsetY - datum.tipHeight"},
{"type": "formula", "field": "x", "expr": "max(0, tooltip.x + (datum.alignLeft ? -datum.offsetX-datum.tipWidth : datum.offsetX ))"},
{"type": "formula", "field": "y", "expr": "tooltip.y + (datum.alignTop ? -1 : 1) * datum.offsetY"},
{"type": "formula", "field": "name", "expr": "datum.mapDataVal ? datum.mapDataVal.my_name : '?xyz?'"},
]},
"properties": {
"update": {
"x": {"field": "x" }, "y": {"field": "y" },
"width": {"field": "tipWidth" },
"height": {"field": "tipHeight" },
"fill": {"value": "#fff"},
"fillOpacity": {"value": 0.90},
"stroke": {"value": "#aaa"},
"strokeWidth": {"value": 0.5}
} },
"marks": [
{
"type": "text",
"properties": {
"update": {
"x": {"value": 6}, "y": {"value": 14},
"width": {"field": "tipWidth" },
"text": {"template": "{{parent.name}}"},
"font": {"value":"Lucida Console, Monaco, monospace"},
"limit": {"value": "60"},
"fill": {"value": "#666"}
} } },
]}
]
} </graph>