Карта мира: различия между версиями
Перейти к навигации
Перейти к поиску
Метка: визуальный редактор отключён |
|||
(не показано 5 промежуточных версий этого же участника) | |||
Строка 1: | Строка 1: | ||
<graph> |
<graph> |
||
+ | |||
⚫ | |||
"version": 2, |
"version": 2, |
||
− | "width": |
+ | "width": 1, |
− | "height": |
+ | "height": 1, |
− | "data": [ |
+ | "data": [ |
− | + | "values": [ |
|
+ | {"a": "C", "b": 2}, {"a": "C", "b": 7}, {"a": "C", "b": 4}, |
||
− | // Data is retrieved from the MediaWiki API. By default it uses current wiki's "Extension by category" |
||
+ | {"a": "D", "b": 1}, {"a": "D", "b": 2}, {"a": "D", "b": 6}, |
||
⚫ | |||
+ | {"a": "E", "b": 8}, {"a": "E", "b": 4}, {"a": "E", "b": 7} |
||
− | "url": "wikiapi:///?generator=categorymembers&gcmtitle=Category:Extensions+by+category&gcmtype=subcat&action=query&gcmlimit=max&prop=categoryinfo&formatversion=2&format=json", |
||
⚫ | |||
− | // We are only interested in the content of query.pages subelement. |
||
⚫ | |||
⚫ | |||
− | + | "mark": "point", |
|
+ | "encoding": { |
||
− | // sort in descending order using category size as the sort key |
||
− | + | "x": {"field": "a", "type": "nominal"}, |
|
+ | "y": {"field": "b", "type": "quantitative"} |
||
− | // To visualize, use "pie" transformation to add layout_start, layout_end, and layout_mid fields to each page object |
||
+ | ] |
||
− | // These fields contain angles at which to start and stop drawing arcs. First element's start will be 0, and last element's end will be 360 degrees (in radians) |
||
+ | </graph> |
||
− | {"type": "pie","field": "categoryinfo.size"} |
||
+ | <graph> |
||
− | ] |
||
⚫ | |||
⚫ | |||
+ | "version": 2, |
||
⚫ | |||
⚫ | |||
− | // Scales are like functions -- marks use them to convert a data value into a visual value, like x or y coordinate on the graph, or a color value. |
||
− | " |
+ | "height": 1, |
− | + | "data": [ |
|
⚫ | |||
− | // This scale will be used to assign a color to each slice, using a palette of 10 colors |
||
− | "name": " |
+ | "name": "highlights", |
+ | "values": [{"id":"US","v":"blue"},{"id":"AU","v":"purple"},{"id":"CN","v":"red"},{"id":"BR","v":"pink"},{"id":"DZ","v":"green"}] |
||
− | "domain": {"data": "table","field": "title"}, |
||
− | + | }, |
|
− | + | { |
|
⚫ | |||
− | } |
||
+ | "url": "wikiraw:///Extension:Graph/Demo/RawData:WorldMap-iso2-json", |
||
− | ], |
||
⚫ | |||
− | "marks": [ |
||
+ | "transform": [ |
||
− | { |
||
− | + | { |
|
+ | "type": "geopath", |
||
− | // Each element is an arc between layout_start and layout_end angles (as calculated by the pie transformation) |
||
⚫ | |||
− | // drawn with a given radius, stroke, and fill. |
||
− | + | "scale": 80, |
|
− | + | "translate":[0,0], |
|
+ | "projection": "equirectangular" |
||
− | "properties": { |
||
− | + | }, |
|
− | + | { |
|
− | " |
+ | "type": "lookup", |
− | + | "keys": [ "id" ], |
|
− | + | "on": "highlights", |
|
− | + | "onKey": "id", |
|
− | " |
+ | "as": [ "zipped" ], |
+ | "default": { |
||
+ | "v": "#C0C0C0" |
||
+ | } |
||
+ | } |
||
⚫ | |||
} |
} |
||
− | + | ], |
|
− | + | "marks": [ |
|
− | { |
+ | { |
⚫ | |||
− | // This mark draws labels around the pie chart after the pie chart has been drawn |
||
− | " |
+ | "from": { |
+ | "data": "countries" |
||
− | // Before drawing, we need to perform a number of calculations to figure out the exact location and orientation of the text |
||
− | + | }, |
|
− | " |
+ | "properties": { |
− | " |
+ | "enter": { |
− | + | "path": { |
|
+ | "field": "layout_path" |
||
− | // Formula transformation evaluates the expression and assigns result to the datapoint |
||
− | + | } |
|
⚫ | |||
− | { "type": "formula", "field": "sliceSize", "expr": "(datum.layout_end - datum.layout_start)*180/PI" }, |
||
+ | "update": { |
||
− | // Draw text only if the slice of the arc is more than 2 degrees to avoid overcrowding |
||
− | + | "fill": { |
|
− | + | "field": "zipped.v" |
|
+ | } |
||
− | { "type": "formula", "field": "title", "expr": "substring(datum.title, 1+indexof(datum.title,':'), 40)" }, |
||
− | + | }, |
|
+ | "hover": { |
||
− | { "type": "formula", "field": "invert", "expr": "datum.layout_mid*180/PI < 180 ? 1 : -1" }, |
||
− | + | "fill": { |
|
− | + | "value": "#989898" |
|
− | + | } |
|
+ | } |
||
− | { "type": "formula", "field": "angle", "expr": "(datum.layout_mid*180/PI)-90*datum.invert" }, |
||
− | + | } |
|
− | { "type": "formula", "field": "fontSize", "expr": "datum.sliceSize > 20 ? 15 : (datum.sliceSize > 10 ? 14 : 10)" }, |
||
− | // Make font bold for largest pie slices |
||
− | { "type": "formula", "field": "fontWeight", "expr": "datum.sliceSize > 15 ? 'bold' : 'normal'" } |
||
⚫ | |||
⚫ | |||
− | "properties": { |
||
⚫ | |||
− | // Use the fields calculated in the transformation to draw category names |
||
− | "align": {"field": "align"}, |
||
− | "angle": {"field": "angle"}, |
||
− | "baseline": {"value": "middle"}, |
||
⚫ | |||
− | "fontSize": {"field": "fontSize"}, |
||
− | "fontWeight": {"field": "fontWeight"}, |
||
− | "radius": {"value": 270}, |
||
⚫ | |||
− | "theta": {"field": "layout_mid"} |
||
} |
} |
||
− | + | ] |
|
− | } |
||
− | ] |
||
} |
} |
||
Текущая версия от 17:24, 7 ноября 2022
Синтаксическая ошибка