Danh : Différence entre versions

De wiki
Aller à : navigation, rechercher
Ligne 139 : Ligne 139 :
 
| mode=interactive }}
 
| mode=interactive }}
  
<graph>
+
{{#tag:graph|
{
 
  //
 
  // ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:PageViews
 
  //            Please do not modify it anywhere else, as it may get copied and override your changes.
 
  //            Suggestions can be made at https://www.mediawiki.org/wiki/Template_talk:Graph:PageViews
 
  //            The graph uses PageViews API https://wikitech.wikimedia.org/wiki/Analytics/PageviewAPI
 
  //
 
  
   "version": 2,
+
   "$schema": "https://vega.github.io/schema/vega/v4.json",
 
   "width": 400,
 
   "width": 400,
 
   "height": 200,
 
   "height": 200,
 +
  "padding": 5,
  
  // The data for this graph comes from the PageView API.  The request is made for N days back up to now.
 
 
   "data": [
 
   "data": [
 
     {
 
     {
       "name": "pageviews",
+
       "name": "table",
       "url": "wikirest://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/fr.wikipedia.org/all-access/user/Mod%C3%A8le%3AGraph%3APageViews/daily/2018121600/2019011500",
+
       "values": [
      "format": {
+
        {"category": "A", "amount": 28},
         "type": "json",
+
        {"category": "B", "amount": 55},
         "property": "items"
+
        {"category": "C", "amount": 43},
       },
+
        {"category": "D", "amount": 91},
 +
        {"category": "E", "amount": 81},
 +
        {"category": "F", "amount": 53},
 +
         {"category": "G", "amount": 19},
 +
         {"category": "H", "amount": 87}
 +
       ]
 +
    }
 +
  ],
  
      // The response is parsed here, converting date strings of form "20160223" into date 2016-02-23
+
  "signals": [
      "transform": [
+
    {
        { "type": "formula", "field": "year", "expr": "parseInt(substring(datum.timestamp,0,4))" },
+
      "name": "tooltip",
        { "type": "formula", "field": "month", "expr": "parseInt(substring(datum.timestamp,4,6))" },
+
      "value": {},
         { "type": "formula", "field": "day", "expr": "parseInt(substring(datum.timestamp,6,8))" },
+
      "on": [
         { "type": "formula", "field": "date", "expr": "datetime(datum.year,datum.month-1,datum.day)" }
+
         {"events": "rect:mouseover", "update": "datum"},
 +
         {"events": "rect:mouseout", "update": "{}"}
 
       ]
 
       ]
 
     }
 
     }
Ligne 173 : Ligne 174 :
  
 
   "scales": [
 
   "scales": [
    // The dates are scaled to the "x" axis - the width of the graph
 
 
     {
 
     {
       "name": "x",
+
       "name": "xscale",
       "type": "time",
+
       "type": "band",
 +
      "domain": {"data": "table", "field": "category"},
 
       "range": "width",
 
       "range": "width",
       "domain": {"data": "pageviews","field": "date"}
+
       "padding": 0.05,
 +
      "round": true
 
     },
 
     },
    // The pageviews are scaled to the "y" axis - the height of the graph
 
    // Optional scale parameter can change "linear" to other scales like log
 
    // Optional max parameter can fix the upper bound of the graph
 
 
     {
 
     {
       "name": "y",
+
       "name": "yscale",
      "type": "linear",
+
       "domain": {"data": "table", "field": "amount"},
      "range": "height",
+
       "nice": true,
       "domain": {"data": "pageviews","field": "views"},
+
       "range": "height"
       "clamp": true,
 
 
 
       "nice": true
 
 
     }
 
     }
 
   ],
 
   ],
  
  // Simple axis with horizontal grid lines
 
 
   "axes": [
 
   "axes": [
     {"type": "x", "scale": "x", "ticks": 5},
+
     { "orient": "bottom", "scale": "xscale" },
     {"type": "y", "scale": "y", "ticks": 5, "grid": true}
+
     { "orient": "left", "scale": "yscale" }
 
   ],
 
   ],
  
  // The graph is drawn with two elements a thick line at the top, and a semi-transparent area below
 
 
   "marks": [
 
   "marks": [
 
     {
 
     {
       "type": "line",
+
       "type": "rect",
       "from": {"data": "pageviews"},
+
       "from": {"data":"table"},
       "properties": {
+
       "encode": {
 
         "enter": {
 
         "enter": {
           "x": {"scale": "x","field": "date"},
+
           "x": {"scale": "xscale", "field": "category"},
           "y": {"scale": "y","field": "views"},
+
          "width": {"scale": "xscale", "band": 1},
           "stroke": {"value": "#00f"},
+
           "y": {"scale": "yscale", "field": "amount"},
           "strokeWidth": {"value": 3},
+
           "y2": {"scale": "yscale", "value": 0}
           "interpolate": {"value": "monotone"}
+
        },
 +
        "update": {
 +
           "fill": {"value": "steelblue"}
 +
        },
 +
        "hover": {
 +
           "fill": {"value": "red"}
 
         }
 
         }
 
       }
 
       }
 
     },
 
     },
 
     {
 
     {
       "type": "area",
+
       "type": "text",
       "from": {"data": "pageviews"},
+
       "encode": {
      "properties": {
 
 
         "enter": {
 
         "enter": {
           "x": {"scale": "x","field": "date"},
+
           "align": {"value": "center"},
           "y": {"scale": "y","value": 0},
+
          "baseline": {"value": "bottom"},
           "y2": {"scale": "y","field": "views"},
+
           "fill": {"value": "#333"}
           "fill": {"value": "#00f"},
+
        },
           "fillOpacity": {"value": 0.35},
+
        "update": {
          "interpolate": {"value": "monotone"}
+
          "x": {"scale": "xscale", "signal": "tooltip.category", "band": 0.5},
 +
           "y": {"scale": "yscale", "signal": "tooltip.amount", "offset": -2},
 +
           "text": {"signal": "tooltip.amount"},
 +
           "fillOpacity": [
 +
            {"test": "datum === tooltip", "value": 0},
 +
            {"value": 1}
 +
          ]
 
         }
 
         }
 
       }
 
       }
 
     }
 
     }
 
   ]
 
   ]
}
+
}}
</graph>
 

Version du 18 janvier 2019 à 14:31

creation du chinoix

Erreur de syntaxe