Skip to content

Instantly share code, notes, and snippets.

@simonhearne
Last active January 16, 2019 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonhearne/2160a5a3a484956ab1aaeb067f7b5291 to your computer and use it in GitHub Desktop.
Save simonhearne/2160a5a3a484956ab1aaeb067f7b5291 to your computer and use it in GitHub Desktop.
{
"$schema": "https://vega.github.io/schema/vega/v4.json",
"width": 1000,
"height": 600,
"padding": 0,
"autosize": {
"type": "fit",
"resize": true
},
"config": {
"text": {
"font": "Ideal Sans, Avenir Next, Helvetica"
},
"axis": {
"labelFont": "Ideal Sans, Avenir Next, Helvetica",
"labelFontSize": 12,
"titleFont": "Ideal Sans, Avenir Next, Helvetica",
"titleFontSize": 18,
"titleFontWeight": 300,
"domain": false,
"ticks": false,
"labelColor": "#54565b"
}
},
"signals": [
{
"name": "width",
"on": [{
"events": {
"source": "window",
"type": "resize"
},
"update": "containerSize()[0]"
}]
},
{
"name": "height",
"on": [{
"events": {
"source": "window",
"type": "resize"
},
"update": "containerSize()[0]*0.6"
}]
},
{
"name": "plotWidth",
"value": 60,
"update": "(height / data('boxplots').length) - boxplotHeight - 2"
},
{
"name": "offsetPx",
"value": 10,
"update": "height / data('boxplots').length"
},
{
"name": "overlap",
"value": 0
},
{
"name": "maxLoadTime",
"value": 10,
"update": "clamp(loadtime_extent[1]+1,5,20)"
},
{
"name": "boxplotHeight",
"value": 10
},
{
"name": "band_opacity",
"value": 0.05
},
{
"name": "device",
"value": "Phone",
"bind": {
"input": "radio",
"options": [
"Desktop",
"Phone",
"Tablet"
],
"name": "Device Type"
}
},
{
"name": "timer",
"value": "Page Load"
}
],
"data": [
{
"name": "distributions",
"url": "https://gist.githubusercontent.com/simonhearne/fb0bb564a999910e1cd99dbfb2e85b66/raw/aae36eed2c459b0629bc811c9b43b3535fcbf52f/crux_benchmark.json",
"transform": [
{
"type": "filter",
"expr": "datum.bin <= maxLoadTime && datum.bin >= 0 && datum.density >= 0"
},
{
"type": "filter",
"expr": "datum.device == device && datum.timer == timer"
},
{
"type": "formula",
"expr": "toNumber(datum.bin)",
"as": "bin"
},
{
"type": "collect",
"sort": {"field": "bin"}
}
]
},
{
"name": "boxplots",
"values": [
{"origin":"Ebay","device":"Desktop","timer":"Page Load","min":0,"q1":0.5,"q2":1.8,"q3":3,"max":7},
{"origin":"Etsy","device":"Desktop","timer":"Page Load","min":0.2,"q1":1.1,"q2":1.3,"q3":6.5,"max":9},
{"origin":"Amazon","device":"Desktop","timer":"Page Load","min":0.1,"q1":2,"q2":2.5,"q3":7.5,"max":10},
{"origin":"Target","device":"Desktop","timer":"Page Load","min":0,"q1":1.5,"q2":3,"q3":7,"max":10},
{"origin":"Walmart","device":"Desktop","timer":"Page Load","min":0,"q1":2.5,"q2":0.5,"q3":7.5,"max":10},
{"origin":"Ebay","device":"Tablet","timer":"Page Load","min":0,"q1":0.5,"q2":5,"q3":6,"max":7},
{"origin":"Etsy","device":"Tablet","timer":"Page Load","min":0.2,"q1":1.1,"q2":4,"q3":6.6,"max":9},
{"origin":"Amazon","device":"Tablet","timer":"Page Load","min":0.1,"q1":2,"q2":3,"q3":7.6,"max":10},
{"origin":"Target","device":"Tablet","timer":"Page Load","min":0,"q1":1.5,"q2":2,"q3":7.2,"max":10},
{"origin":"Walmart","device":"Tablet","timer":"Page Load","min":0,"q1":2.5,"q2":1,"q3":7.6,"max":15},
{"origin":"Ebay","device":"Phone","timer":"Page Load","min":0,"q1":0.5,"q2":8.9,"q3":9,"max":12},
{"origin":"Etsy","device":"Phone","timer":"Page Load","min":0.2,"q1":1.1,"q2":1.4,"q3":6.6,"max":9},
{"origin":"Amazon","device":"Phone","timer":"Page Load","min":0.1,"q1":2,"q2":0.6,"q3":7.6,"max":10},
{"origin":"Target","device":"Phone","timer":"Page Load","min":0,"q1":1.5,"q2":3.1,"q3":7.2,"max":10},
{"origin":"Walmart","device":"Phone","timer":"Page Load","min":0,"q1":2.5,"q2":5.1,"q3":7.6,"max":10}
],
"transform": [
{
"type": "filter",
"expr": "datum.device == device && datum.timer == timer"
},
{
"type": "extent",
"field": "q3",
"signal": "loadtime_extent"
}
]
}
],
"scales": [
{
"name": "layout",
"type": "band",
"range": "height",
"domain": {
"data": "boxplots",
"field": "origin",
"sort": {"op": "sum", "field": "q2", "order": "ascending"}
}
},
{
"name": "loadTime",
"type": "linear",
"range": "width",
"zero": true,
"domain": [0, {"signal":"maxLoadTime"}]
},
{
"name": "originColor",
"type": "ordinal",
"range": {
"scheme": "viridis"
},
"domain": {
"data": "boxplots",
"field": "origin"
}
}
],
"axes": [
{
"orient": "bottom",
"scale": "loadTime",
"title": "Load Time (s)"
},
{
"orient": "left",
"scale": "layout",
"labelAngle": 270,
"labelAlign": "center",
"labelPadding": 12,
"encode": {
"labels": {
"update": {
"text": {"signal": "upper(datum.value)"}
}
}
}
}
],
"marks": [
{
"type": "group",
"from": {
"facet": {
"name": "background",
"data": "boxplots",
"groupby": ["origin"]
}
},
"encode": {
"enter": {
"yc": {
"scale": "layout",
"field": "origin",
"band": 0.5
}
}
},
"marks": [
{
"type": "rect",
"from": {
"data": "background"
},
"encode": {
"enter": {
"fill": {"value": "#54565b"},
"fillOpacity": {"value" : 0.05}
},
"update": {
"x": {"value": 0},
"x2": {"signal": "width"},
"y": {"signal": "plotWidth / -2"},
"y2": {"signal": "plotWidth / 2"}
}
}
},
{
"type": "rule",
"from": {
"data": "background"
},
"encode": {
"enter": {
"x": {"value": 0},
"x2": {"signal": "width"},
"stroke": {"value": "#54565b"},
"strokeOpacity": {"value": 0.5}
}
}
}
]
},
{
"type": "group",
"from": {
"facet": {
"name": "origin",
"data": "distributions",
"groupby": ["origin"]
}
},
"encode": {
"update": {
"yc": {
"scale": "layout",
"field": "origin",
"band": 0.5
},
"height": {"signal": "plotWidth"},
"width": {"signal": "width"}
}
},
"scales": [
{
"name": "yscale",
"type": "linear",
"range": [{"signal": "plotWidth /2"}, {"signal":"-1 * overlap"}],
"domain": {
"data": "origin",
"field": "density"
}
}
],
"marks": [
{
"type": "area",
"from": {
"data": "origin"
},
"encode": {
"enter": {
"fill": {
"scale": "originColor",
"field": "origin"
},
"fillOpacity": { "value": 0.25 },
"stroke": {
"scale": "originColor",
"field": "origin"
},
"strokeWidth": {
"value": 1
}
},
"update": {
"x": {
"scale": "loadTime",
"field": "bin"
},
"y": {
"signal": "scale('yscale',datum.density * 0.9)"
},
"y2": {
"signal": "scale('yscale',datum.density * -0.9)"
},
"tooltip": {
"signal": "datum"
}
}
}
}
]
},
{
"type": "group",
"from": {
"facet": {
"name": "boxplot",
"data": "boxplots",
"groupby": ["origin"]
}
},
"encode": {
"update": {
"yc": {
"scale": "layout",
"field": "origin",
"band": 0.5
}
}
},
"marks": [
{
"type": "rule",
"from": {
"data": "boxplot"
},
"encode": {
"enter": {
"stroke": {
"value": "black"
},
"strokeWidth": {
"value": 1.5
},
"strokeOpacity": {
"value": 0.9
}
},
"update": {
"x": {
"scale": "loadTime",
"field": "q1"
},
"x2": {
"scale": "loadTime",
"field": "q3"
},
"tooltip": {
"signal": "{'Origin': datum.origin, 'Minimum': format(datum.min,'.2n')+'s','25th %ile': format(datum.q1,'.2n')+'s', 'Median': format(datum.q2,'.2n')+'s', '75th %ile': format(datum.q3,'.2n')+'s', 'Maximum': format(datum.max,'.2n')+'s'}"
}
}
}
},
{
"type": "symbol",
"from": {
"data": "boxplot"
},
"encode": {
"enter": {
"fill": {
"value": "black"
},
"size": {
"signal": "50"
}
},
"update": {
"x": {
"scale": "loadTime",
"field": "q2"
},
"tooltip": {
"signal": "{'Origin': datum.origin, 'Minimum': format(datum.min,'.2n')+'s','25th %ile': format(datum.q1,'.2n')+'s', 'Median': format(datum.q2,'.2n')+'s', '75th %ile': format(datum.q3,'.2n')+'s', 'Maximum': format(datum.max,'.2n')+'s'}"
}
}
}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment