|
|
(8 intermediate revisions by 2 users not shown) |
Line 2: |
Line 2: |
| | | |
| == Food Grid == | | == Food Grid == |
− | <graph>
| |
− | {
| |
− | "width": 800,
| |
− | "height": 500,
| |
− | "padding": 50,
| |
− | "data": [
| |
− |
| |
− |
| |
− |
| |
− |
| |
| | | |
− |
| |
− | ],
| |
− | "signals": [
| |
− | {
| |
− | "name": "point",
| |
− | "init": 0,
| |
− | "streams": [
| |
− | {
| |
− | "type": "mousedown",
| |
− | "expr": "{x: eventX(), y: eventY()}"
| |
− | }
| |
− | ]
| |
− | },
| |
− | {
| |
− | "name": "delta",
| |
− | "init": 0,
| |
− | "streams": [
| |
− | {
| |
− | "type": "[mousedown, window:mouseup] > window:mousemove",
| |
− | "expr": "{x: point.x - eventX(), y: eventY() - point.y}"
| |
− | }
| |
− | ]
| |
− | },
| |
− | {
| |
− | "name": "xAnchor",
| |
− | "init": 0,
| |
− | "streams": [
| |
− | {
| |
− | "type": "mousemove",
| |
− | "expr": "eventX()",
| |
− | "scale": {"name": "x","invert": true}
| |
− | }
| |
− | ]
| |
− | },
| |
− | {
| |
− | "name": "yAnchor",
| |
− | "init": 0,
| |
− | "streams": [
| |
− | {
| |
− | "type": "mousemove",
| |
− | "expr": "eventY()",
| |
− | "scale": {"name": "y","invert": true}
| |
− | }
| |
− | ]
| |
− | },
| |
− | {
| |
− | "name": "zoom",
| |
− | "init": 1,
| |
− | "verbose": true,
| |
− | "streams": [
| |
− | {
| |
− | "type": "wheel",
| |
− | "expr": "pow(1.001, event.deltaY*pow(16, event.deltaMode))"
| |
− | }
| |
− | ]
| |
− | },
| |
− | {
| |
− | "name": "xs",
| |
− | "streams": [
| |
− | {
| |
− | "type": "mousedown, mouseup, wheel",
| |
− | "expr": "{min: xMin, max: xMax}"
| |
− | }
| |
− | ]
| |
− | },
| |
− | {
| |
− | "name": "ys",
| |
− | "streams": [
| |
− | {
| |
− | "type": "mousedown, mouseup, wheel",
| |
− | "expr": "{min: yMin, max: yMax}"
| |
− | }
| |
− | ]
| |
− | },
| |
− | {
| |
− | "name": "xMin",
| |
− | "init": -1.6,
| |
− | "streams": [
| |
− | {
| |
− | "type": "delta",
| |
− | "expr": "xs.min + (xs.max-xs.min)*delta.x/width"
| |
− | },
| |
− | {
| |
− | "type": "zoom",
| |
− | "expr": "(xs.min-xAnchor)*zoom + xAnchor"
| |
− | }
| |
− | ]
| |
− | },
| |
− | {
| |
− | "name": "xMax",
| |
− | "init": 1.6,
| |
− | "streams": [
| |
− | {
| |
− | "type": "delta",
| |
− | "expr": "xs.max + (xs.max-xs.min)*delta.x/width"
| |
− | },
| |
− | {
| |
− | "type": "zoom",
| |
− | "expr": "(xs.max-xAnchor)*zoom + xAnchor"
| |
− | }
| |
− | ]
| |
− | },
| |
− | {
| |
− | "name": "yMin",
| |
− | "init": -1,
| |
− | "streams": [
| |
− | {
| |
− | "type": "delta",
| |
− | "expr": "ys.min + (ys.max-ys.min)*delta.y/height"
| |
− | },
| |
− | {
| |
− | "type": "zoom",
| |
− | "expr": "(ys.min-yAnchor)*zoom + yAnchor"
| |
− | }
| |
− | ]
| |
− | },
| |
− | {
| |
− | "name": "yMax",
| |
− | "init": 1,
| |
− | "streams": [
| |
− | {
| |
− | "type": "delta",
| |
− | "expr": "ys.max + (ys.max-ys.min)*delta.y/height"
| |
− | },
| |
− | {
| |
− | "type": "zoom",
| |
− | "expr": "(ys.max-yAnchor)*zoom + yAnchor"
| |
− | }
| |
− | ]
| |
− | },
| |
− | {
| |
− | "name": "pointSize",
| |
− | "init": 20,
| |
− | "streams": [
| |
− | {
| |
− | "type": "xMin",
| |
− | "expr": "clamp(60/(xMax-xMin), 1, 100)"
| |
− | }
| |
− | ]
| |
− | }
| |
− | ],
| |
− | "scales": [
| |
− | {
| |
− | "name": "x",
| |
− | "type": "linear",
| |
− | "range": "width",
| |
− | "zero": false,
| |
− | "domainMin": {"signal": "xMin"},
| |
− | "domainMax": {"signal": "xMax"}
| |
− | },
| |
− | {
| |
− | "name": "y",
| |
− | "type": "linear",
| |
− | "range": "height",
| |
− | "zero": false,
| |
− | "domainMin": {"signal": "yMin"},
| |
− | "domainMax": {"signal": "yMax"}
| |
− | }
| |
− | ],
| |
− | "axes": [
| |
− | {
| |
− | "type": "x",
| |
− | "scale": "x",
| |
− | "grid": true,
| |
− | "layer": "back",
| |
− | "properties": {"labels": {"fontSize": {"value": 14}}}
| |
− | },
| |
− | {
| |
− | "type": "y",
| |
− | "scale": "y",
| |
− | "grid": true,
| |
− | "layer": "back",
| |
− | "properties": {"labels": {"fontSize": {"value": 14}}}
| |
− | }
| |
− | ],
| |
− | "marks": [
| |
− | {
| |
− | "type": "group",
| |
− | "properties": {
| |
− | "enter": {
| |
− | "x": {"value": 0},
| |
− | "width": {"field": {"group": "width"}},
| |
− | "y": {"value": 0},
| |
− | "height": {"field": {"group": "height"}},
| |
− | "clip": {"value": true}
| |
− | }
| |
− | },
| |
− | "marks": [
| |
− | {
| |
− | "type": "symbol",
| |
− | "from": {"data": "points"},
| |
− | "properties": {
| |
− | "update": {
| |
− | "x": {"scale": "x","field": "X"},
| |
− | "y": {"scale": "y","field": "Y"},
| |
− | "fill": {"value": "steelblue"},
| |
− | "size": {"signal": "pointSize"}
| |
− | }
| |
− | }
| |
− | }
| |
− | ]
| |
− | }
| |
− | ]
| |
− | }
| |
− | </graph>
| |
− | == Testing ==
| |
| | | |
| <graph> | | <graph> |
| { | | { |
− | "width": 1200, | + | "width": 800, |
| "height": 800, | | "height": 800, |
| "padding": 50, | | "padding": 50, |
Line 419: |
Line 203: |
| "marks": [ | | "marks": [ |
| { | | { |
− | "type": "symbol", | + | "type": "text", |
| "from": {"data": "points"}, | | "from": {"data": "points"}, |
| "properties": { | | "properties": { |
Line 425: |
Line 209: |
| "x": {"scale": "x","field": "X"}, | | "x": {"scale": "x","field": "X"}, |
| "y": {"scale": "y","field": "Y"}, | | "y": {"scale": "y","field": "Y"}, |
− | "fill": {"value": "steelblue"}, | + | "fill": {"value": "black"}, |
| + | "text": {"field": "Ingredient"}, |
| "size": {"signal": "pointSize"} | | "size": {"signal": "pointSize"} |
| } | | } |
| } | | } |
− | } | + | }, |
| + | { |
| + | "type": "symbol", |
| + | "from": {"data": "points"}, |
| + | "properties": { |
| + | "update": { |
| + | "x": {"scale": "x","field": "X"}, |
| + | "y": {"scale": "y","field": "Y"}, |
| + | "fill": {"field": "Color"}, |
| + | "size": {"signal": "pointSize"} |
| + | } |
| + | } |
| + | } |
| + | |
| ] | | ] |
| } | | } |