Template:Graph:WindRose

From GT New Horizons
Jump to navigation Jump to search

<graph>{

 "width": 200,
 "height": 200,
 "data": [
   {
     "name": "16directions",
     "values": [
         {"d":"N","r":1},
         {"d":"NNE","r":2},
         {"d":"NE","r":3},
         {"d":"ENE","r":4},
         {"d":"E","r":5},
         {"d":"ESE","r":6},
         {"d":"SE","r":7},
         {"d":"SSE","r":8},
         {"d":"S","r":9},
         {"d":"SSW","r":10},
         {"d":"SW","r":11},
         {"d":"WSW","r":12},
         {"d":"W","r":13},
         {"d":"WNW","r":14},
         {"d":"NW","r":15},
         {"d":"NNW","r":16}
         ]
   },
   {
     "name": "table",
     "values": [
       //the ordinal scema
       {"dir":"N","speed":1,"time":0},{"dir":"NNE","speed":1,"time":0},        {"dir":"NE","speed":1,"time":0},{"dir":"ENE","speed":1,"time":0},
       {"dir":"E","speed":1,"time":0},{"dir":"ESE","speed":1,"time":0},        {"dir":"SE","speed":1,"time":0},{"dir":"SSE","speed":1,"time":0},
       {"dir":"S","speed":1,"time":0},{"dir":"SSW","speed":1,"time":0},        {"dir":"SW","speed":1,"time":0},{"dir":"WSW","speed":1,"time":0},
       {"dir":"W","speed":1,"time":0},{"dir":"WNW","speed":1,"time":0},        {"dir":"NW","speed":1,"time":0},{"dir":"NNW","speed":1,"time":0},
       // ggg         
        
       {"dir":"N","speed":1,"time":42}, {"dir":"N","speed":2,"time":20}, {"dir":"N","speed":3,"time":10},
       {"dir":"NNE","speed":1,"time":23}, {"dir":"NNE","speed":2,"time":38}, {"dir":"NNE","speed":3,"time":32},
       {"dir":"NE","speed":1,"time":47}, {"dir":"NE","speed":2,"time":64}, {"dir":"NE","speed":3,"time":27},
       {"dir":"ENE","speed":1,"time":26}, {"dir":"ENE","speed":2,"time":27}, {"dir":"ENE", "speed":3,"time":16},
       {"dir":"E","speed":1,"time":52}, {"dir":"E","speed":2,"time":79}, {"dir":"E","speed":3,"time":38},
       {"dir":"ESE","speed":1,"time":19}, {"dir":"ESE","speed":2,"time":83}, {"dir":"ESE","speed":3,"time":5},
       {"dir":"SE","speed":1,"time":82}, {"dir":"SE","speed":2,"time":20}, {"dir":"SE","speed":3,"time":10},
       {"dir":"SSE","speed":1,"time":23}, {"dir":"SSE","speed":2,"time":38}, {"dir":"SSE","speed":3,"time":32},
       {"dir":"S","speed":1,"time":47}, {"dir":"S","speed":2,"time":64}, {"dir":"S","speed":3,"time":27},
       {"dir":"SSW","speed":1,"time":26}, {"dir":"SSW","speed":2,"time":27}, {"dir":"SSW", "speed":3,"time":16},
       {"dir":"SW","speed":1,"time":52}, {"dir":"SW","speed":2,"time":79}, {"dir":"SW","speed":3,"time":38},
       {"dir":"WSW","speed":1,"time":19}, {"dir":"WSW","speed":2,"time":83}, {"dir":"WSW","speed":3,"time":5},
       {"dir":"W","speed":1,"time":20}, {"dir":"W","speed":2,"time":79}, {"dir":"W","speed":3,"time":38},
       {"dir":"WNW","speed":1,"time":19}, {"dir":"WNW","speed":2,"time":83}, {"dir":"WNW","speed":3,"time":5},
       {"dir":"NW","speed":1,"time":52}, {"dir":"NW","speed":2,"time":79}, {"dir":"NW","speed":3,"time":38},
       {"dir":"NNW","speed":1,"time":120}, {"dir":"NNW","speed":2,"time":83}, {"dir":"NNW","speed":3,"time":5}
     ]
   },
   {
     "name": "stack",
     "source": "table",
     "transform": [
         {"type": "stack", "groupby": ["dir"], "sortby": ["speed"],  "field": "time"}
     ]
   },
   {
     "name": "facets",
     "source": "stack",
     "transform":[
       {"type": "facet", "groupby": ["dir"]},
       {"type": "pie"}
     ]
   }
 ],
 "scales": [
   {
     "name": "color",
     "type": "ordinal",
     "range": ["#d62728","#9467bd","#8c564b"],
     "domain": {"data": "table", "field": "speed"}
   }
 ],
 "marks": [
   {
     "type": "group",
     "from": {"data": "facets"},
     "marks": [
       {
         "type": "arc",
         "properties": {
           "enter": {
             "x": {"value": 100},
             "y": {"value": 100},
             "startAngle": {"field": {"group": "datum.layout_start"}, "offset": -0.181},
             "endAngle": {"field": {"group": "datum.layout_end"}, "offset": -0.211},
             "innerRadius": {"field": "layout_start"},
             "outerRadius": {"field": "layout_end"},
             "stroke": {"value": "#fff"},
             "fill": {"scale": "color", "field": "speed"}
           }
         }
       }
     ]
   }
 ]

} </graph>