Created
August 11, 2015 18:56
-
-
Save anonymous/6a291dda73c84b13a2e9 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/kehoxi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.js"></script> | |
<script src="http://dimplejs.org/dist/dimple.v2.1.6.min.js"></script> | |
</head> | |
<body> | |
<div id="chart"> | |
</div> | |
<script id="jsbin-javascript"> | |
var BOOK_URL = "bestias"; | |
var BOOK_TITLE = "bestias"; | |
var _search = { | |
"aggs": { | |
"nov": { | |
"filters": { | |
"filters": { | |
"open": { | |
"term": { "protoPayload.line.json.event.raw": "bookOpen" } | |
}, | |
"review": { | |
"term": {"protoPayload.line.json.event.raw": "newReview" } | |
}, | |
"highlight": { | |
"term": {"protoPayload.line.json.event.raw": "newHighlight" } | |
} | |
} | |
}, | |
"aggs": { | |
"book_count": { | |
"cardinality": {"field": "protoPayload.line.json.book.url.raw"} | |
} | |
} | |
}, | |
"mine": { | |
"filter": { | |
"term": {"protoPayload.line.json.book.url.raw": BOOK_URL} | |
}, | |
"aggs": { | |
"book_events": { | |
"filters": { | |
"filters": { | |
"open": { | |
"term": { "protoPayload.line.json.event.raw": "bookOpen" } | |
}, | |
"review": { | |
"term": {"protoPayload.line.json.event.raw": "newReview" } | |
}, | |
"highlight": { | |
"term": {"protoPayload.line.json.event.raw": "newHighlight" } | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}; | |
document.addEventListener('DOMContentLoaded', function () { | |
d3.json('http://104.197.73.81/_search') | |
.post(JSON.stringify(_search), function (error, data) { | |
function mineCount(name) { | |
return data.aggregations.mine.book_events.buckets[name].doc_count; | |
} | |
function noviAvg(name) { | |
return data.aggregations.nov.buckets[name].doc_count / Math.max(1, data.aggregations.nov.buckets[name].book_count.value); | |
} | |
var mine = { | |
scope: BOOK_TITLE, | |
open: mineCount('open'), | |
review: mineCount('review'), | |
highlight: mineCount('highlight') | |
}; | |
var avg = { | |
scope: "Novelistik Average Book", | |
open: noviAvg('open'), | |
review: noviAvg('review'), | |
highlight: noviAvg('highlight') | |
}; | |
//console.log(mine, avg); | |
var SCOPE = "Scope"; | |
var METRIC = "Metric"; | |
var COUNT = "Total"; | |
function row(d, count, metric) { | |
var obj = {}; | |
obj[SCOPE] = d.scope; | |
obj[COUNT] = d[count]; | |
obj[METRIC] = metric; | |
return obj; | |
} | |
var table = [ | |
row(avg, 'open', 'Book reads'), | |
row(avg, 'highlight', 'Highlights'), | |
row(avg, 'review', 'Reviews'), | |
row(mine, 'open', 'Book reads'), | |
row(mine, 'highlight', 'Highlights'), | |
row(mine, 'review', 'Reviews') | |
]; | |
//console.log(table); | |
var svg = | |
dimple.newSvg("#chart", 590, 400); | |
var chart = new dimple.chart(svg, table); | |
chart.addCategoryAxis("x", [METRIC, SCOPE]); | |
chart.addMeasureAxis("y", COUNT); | |
chart.addSeries(SCOPE, dimple.plot.bar); | |
chart.addLegend(65, 10, 510, 20, "right"); | |
chart.draw(); | |
}); | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var BOOK_URL = "bestias"; | |
var BOOK_TITLE = "bestias"; | |
var _search = { | |
"aggs": { | |
"nov": { | |
"filters": { | |
"filters": { | |
"open": { | |
"term": { "protoPayload.line.json.event.raw": "bookOpen" } | |
}, | |
"review": { | |
"term": {"protoPayload.line.json.event.raw": "newReview" } | |
}, | |
"highlight": { | |
"term": {"protoPayload.line.json.event.raw": "newHighlight" } | |
} | |
} | |
}, | |
"aggs": { | |
"book_count": { | |
"cardinality": {"field": "protoPayload.line.json.book.url.raw"} | |
} | |
} | |
}, | |
"mine": { | |
"filter": { | |
"term": {"protoPayload.line.json.book.url.raw": BOOK_URL} | |
}, | |
"aggs": { | |
"book_events": { | |
"filters": { | |
"filters": { | |
"open": { | |
"term": { "protoPayload.line.json.event.raw": "bookOpen" } | |
}, | |
"review": { | |
"term": {"protoPayload.line.json.event.raw": "newReview" } | |
}, | |
"highlight": { | |
"term": {"protoPayload.line.json.event.raw": "newHighlight" } | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}; | |
document.addEventListener('DOMContentLoaded', function () { | |
d3.json('http://104.197.73.81/_search') | |
.post(JSON.stringify(_search), function (error, data) { | |
function mineCount(name) { | |
return data.aggregations.mine.book_events.buckets[name].doc_count; | |
} | |
function noviAvg(name) { | |
return data.aggregations.nov.buckets[name].doc_count / Math.max(1, data.aggregations.nov.buckets[name].book_count.value); | |
} | |
var mine = { | |
scope: BOOK_TITLE, | |
open: mineCount('open'), | |
review: mineCount('review'), | |
highlight: mineCount('highlight') | |
}; | |
var avg = { | |
scope: "Novelistik Average Book", | |
open: noviAvg('open'), | |
review: noviAvg('review'), | |
highlight: noviAvg('highlight') | |
}; | |
//console.log(mine, avg); | |
var SCOPE = "Scope"; | |
var METRIC = "Metric"; | |
var COUNT = "Total"; | |
function row(d, count, metric) { | |
var obj = {}; | |
obj[SCOPE] = d.scope; | |
obj[COUNT] = d[count]; | |
obj[METRIC] = metric; | |
return obj; | |
} | |
var table = [ | |
row(avg, 'open', 'Book reads'), | |
row(avg, 'highlight', 'Highlights'), | |
row(avg, 'review', 'Reviews'), | |
row(mine, 'open', 'Book reads'), | |
row(mine, 'highlight', 'Highlights'), | |
row(mine, 'review', 'Reviews') | |
]; | |
//console.log(table); | |
var svg = | |
dimple.newSvg("#chart", 590, 400); | |
var chart = new dimple.chart(svg, table); | |
chart.addCategoryAxis("x", [METRIC, SCOPE]); | |
chart.addMeasureAxis("y", COUNT); | |
chart.addSeries(SCOPE, dimple.plot.bar); | |
chart.addLegend(65, 10, 510, 20, "right"); | |
chart.draw(); | |
}); | |
});</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var BOOK_URL = "bestias"; | |
var BOOK_TITLE = "bestias"; | |
var _search = { | |
"aggs": { | |
"nov": { | |
"filters": { | |
"filters": { | |
"open": { | |
"term": { "protoPayload.line.json.event.raw": "bookOpen" } | |
}, | |
"review": { | |
"term": {"protoPayload.line.json.event.raw": "newReview" } | |
}, | |
"highlight": { | |
"term": {"protoPayload.line.json.event.raw": "newHighlight" } | |
} | |
} | |
}, | |
"aggs": { | |
"book_count": { | |
"cardinality": {"field": "protoPayload.line.json.book.url.raw"} | |
} | |
} | |
}, | |
"mine": { | |
"filter": { | |
"term": {"protoPayload.line.json.book.url.raw": BOOK_URL} | |
}, | |
"aggs": { | |
"book_events": { | |
"filters": { | |
"filters": { | |
"open": { | |
"term": { "protoPayload.line.json.event.raw": "bookOpen" } | |
}, | |
"review": { | |
"term": {"protoPayload.line.json.event.raw": "newReview" } | |
}, | |
"highlight": { | |
"term": {"protoPayload.line.json.event.raw": "newHighlight" } | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}; | |
document.addEventListener('DOMContentLoaded', function () { | |
d3.json('http://104.197.73.81/_search') | |
.post(JSON.stringify(_search), function (error, data) { | |
function mineCount(name) { | |
return data.aggregations.mine.book_events.buckets[name].doc_count; | |
} | |
function noviAvg(name) { | |
return data.aggregations.nov.buckets[name].doc_count / Math.max(1, data.aggregations.nov.buckets[name].book_count.value); | |
} | |
var mine = { | |
scope: BOOK_TITLE, | |
open: mineCount('open'), | |
review: mineCount('review'), | |
highlight: mineCount('highlight') | |
}; | |
var avg = { | |
scope: "Novelistik Average Book", | |
open: noviAvg('open'), | |
review: noviAvg('review'), | |
highlight: noviAvg('highlight') | |
}; | |
//console.log(mine, avg); | |
var SCOPE = "Scope"; | |
var METRIC = "Metric"; | |
var COUNT = "Total"; | |
function row(d, count, metric) { | |
var obj = {}; | |
obj[SCOPE] = d.scope; | |
obj[COUNT] = d[count]; | |
obj[METRIC] = metric; | |
return obj; | |
} | |
var table = [ | |
row(avg, 'open', 'Book reads'), | |
row(avg, 'highlight', 'Highlights'), | |
row(avg, 'review', 'Reviews'), | |
row(mine, 'open', 'Book reads'), | |
row(mine, 'highlight', 'Highlights'), | |
row(mine, 'review', 'Reviews') | |
]; | |
//console.log(table); | |
var svg = | |
dimple.newSvg("#chart", 590, 400); | |
var chart = new dimple.chart(svg, table); | |
chart.addCategoryAxis("x", [METRIC, SCOPE]); | |
chart.addMeasureAxis("y", COUNT); | |
chart.addSeries(SCOPE, dimple.plot.bar); | |
chart.addLegend(65, 10, 510, 20, "right"); | |
chart.draw(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment