User:Jason.nlw: Difference between revisions

From Semantic Name Authority Repository Cymru
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:


<graph>
<graph>
{
{
   "$schema": "https://vega.github.io/schema/vega/v5.json",
   "$schema": "https://vega.github.io/schema/vega/v5.json",
   "description": "A configurable map of countries of the world.",
   "description": "An arc diagram depicting character co-occurrence in the novel Les Misérables.",
   "autosize": "none",
   "width": 770,
  "padding": 5,


   "signals": [
   "data": [
    {
      "name": "edges",
      "url": "data/miserables.json",
      "format": {"type": "json", "property": "links"}
    },
     {
     {
       "name": "type",
       "name": "sourceDegree",
       "value": "mercator",
       "source": "edges",
       "bind": {
       "transform": [
         "input": "select",
         {"type": "aggregate", "groupby": ["source"]}
        "options": [
      ]
          "albers",
    },
          "albersUsa",
    {
          "azimuthalEqualArea",
      "name": "targetDegree",
          "azimuthalEquidistant",
      "source": "edges",
          "conicConformal",
      "transform": [
          "conicEqualArea",
        {"type": "aggregate", "groupby": ["target"]}
          "conicEquidistant",
       ]
          "equalEarth",
          "equirectangular",
          "gnomonic",
          "mercator",
          "naturalEarth1",
          "orthographic",
          "stereographic",
          "transverseMercator"
        ]
       }
     },
     },
    { "name": "scale", "value": 150,
      "bind": {"input": "range", "min": 50, "max": 2000, "step": 1} },
    { "name": "rotate0", "value": 0,
      "bind": {"input": "range", "min": -180, "max": 180, "step": 1} },
    { "name": "rotate1", "value": 0,
      "bind": {"input": "range", "min": -90, "max": 90, "step": 1} },
    { "name": "rotate2", "value": 0,
      "bind": {"input": "range", "min": -180, "max": 180, "step": 1} },
    { "name": "center0", "value": 0,
      "bind": {"input": "range", "min": -180, "max": 180, "step": 1} },
    { "name": "center1", "value": 0,
      "bind": {"input": "range", "min": -90, "max": 90, "step": 1} },
    { "name": "translate0", "update": "width / 2" },
    { "name": "translate1", "update": "height / 2" },
    { "name": "graticuleDash", "value": 0,
      "bind": {"input": "radio", "options": [0, 3, 5, 10]} },
    { "name": "borderWidth", "value": 1,
      "bind": {"input": "text"} },
    { "name": "background", "value": "#ffffff",
      "bind": {"input": "color"} },
    { "name": "invert", "value": false,
      "bind": {"input": "checkbox"} }
  ],
  "projections": [
     {
     {
       "name": "projection",
       "name": "nodes",
       "type": {"signal": "type"},
       "url": "data/miserables.json",
       "scale": {"signal": "scale"},
       "format": {"type": "json", "property": "nodes"},
       "rotate": [
       "transform": [
         {"signal": "rotate0"},
         { "type": "window", "ops": ["rank"], "as": ["order"] },
         {"signal": "rotate1"},
         {
        {"signal": "rotate2"}
          "type": "lookup", "from": "sourceDegree", "key": "source",
      ],
          "fields": ["index"], "as": ["sourceDegree"],
      "center": [
          "default": {"count": 0}
        {"signal": "center0"},
        },
         {"signal": "center1"}
         {
      ],
          "type": "lookup", "from": "targetDegree", "key": "target",
      "translate": [
          "fields": ["index"], "as": ["targetDegree"],
        {"signal": "translate0"},
          "default": {"count": 0}
         {"signal": "translate1"}
        },
         {
          "type": "formula", "as": "degree",
          "expr": "datum.sourceDegree.count + datum.targetDegree.count"
        }
       ]
       ]
     }
     }
   ],
   ],


   "data": [
   "scales": [
     {
     {
       "name": "world",
       "name": "position",
       "url": "data/world-110m.json",
       "type": "band",
       "format": {
       "domain": {"data": "nodes", "field": "order", "sort": true},
        "type": "topojson",
       "range": "width"
        "feature": "countries"
       }
     },
     },
     {
     {
       "name": "graticule",
       "name": "color",
       "transform": [
       "type": "ordinal",
        { "type": "graticule" }
      "range": "category",
      ]
      "domain": {"data": "nodes", "field": "group"}
     }
     }
   ],
   ],
Line 99: Line 70:
   "marks": [
   "marks": [
     {
     {
       "type": "shape",
       "type": "symbol",
       "from": {"data": "graticule"},
      "name": "layout",
      "interactive": false,
       "from": {"data": "nodes"},
       "encode": {
       "encode": {
        "enter": {
          "opacity": {"value": 0}
        },
         "update": {
         "update": {
           "strokeWidth": {"value": 1},
           "x": {"scale": "position", "field": "order"},
           "strokeDash": {"signal": "[+graticuleDash, +graticuleDash]"},
          "y": {"value": 0},
           "stroke": {"signal": "invert ? '#444' : '#ddd'"},
           "size": {"field": "degree", "mult": 5, "offset": 10},
           "fill": {"value": null}
          "fill": {"scale": "color", "field": "group"}
        }
      }
    },
    {
      "type": "path",
      "from": {"data": "edges"},
      "encode": {
        "update": {
           "stroke": {"value": "#000"},
          "strokeOpacity": {"value": 0.2},
           "strokeWidth": {"field": "value"}
         }
         }
       },
       },
       "transform": [
       "transform": [
         { "type": "geoshape", "projection": "projection" }
         {
          "type": "lookup", "from": "layout", "key": "datum.index",
          "fields": ["datum.source", "datum.target"],
          "as": ["sourceNode", "targetNode"]
        },
        {
          "type": "linkpath",
          "sourceX": {"expr": "min(datum.sourceNode.x, datum.targetNode.x)"},
          "targetX": {"expr": "max(datum.sourceNode.x, datum.targetNode.x)"},
          "sourceY": {"expr": "0"},
          "targetY": {"expr": "0"},
          "shape": "arc"
        }
       ]
       ]
     },
     },
     {
     {
       "type": "shape",
       "type": "symbol",
       "from": {"data": "world"},
       "from": {"data": "layout"},
       "encode": {
       "encode": {
         "update": {
         "update": {
           "strokeWidth": {"signal": "+borderWidth"},
           "x": {"field": "x"},
           "stroke": {"signal": "invert ? '#777' : '#bbb'"},
           "y": {"field": "y"},
           "fill": {"signal": "invert ? '#fff' : '#000'"},
           "fill": {"field": "fill"},
           "zindex": {"value": 0}
           "size": {"field": "size"}
         },
         }
         "hover": {
      }
           "strokeWidth": {"signal": "+borderWidth + 1"},
    },
           "stroke": {"value": "firebrick"},
    {
           "zindex": {"value": 1}
      "type": "text",
      "from": {"data": "nodes"},
      "encode": {
         "update": {
           "x": {"scale": "position", "field": "order"},
           "y": {"value": 7},
          "fontSize": {"value": 9},
          "align": {"value": "right"},
          "baseline": {"value": "middle"},
           "angle": {"value": -90},
          "text": {"field": "name"}
         }
         }
       },
       }
      "transform": [
        { "type": "geoshape", "projection": "projection" }
      ]
     }
     }
   ]
   ]
}
}
</graph>
</graph>

Revision as of 15:50, 10 July 2024

{{#babel:en|cy}}