{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### New notes taken from latest [tutorial](https://bitbucket.org/hrojas/dc.js-in-ipython-notebooks) on how ipython notebook interacts with dc.js" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Learning Notes\n", "\n", "### 1. Use `\"\"\"\n", " .format(srcdoc = stuff))" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": true }, "outputs": [], "source": [ "head = HTML(\"\"\"\n", "\n", " \n", " \n", " \n", " \n", "\n", "\"\"\")\n", "\n", "body = HTML(\"\"\"\n", "\n", "
\n", " \n", " Row Chart\n", " \n", " reset\n", "
\n", " \n", " Current filter: \n", "
\n", "
\n", "
\n", "\"\"\")\n", "\n", "dc_template = jinja2.Template(\"\"\" \n", "\n", "// Create Global Variables\n", "var RowChart = dc.rowChart(\"#rowchart\");\n", "\n", "// Load data\n", "var dataset = {{ data }};\n", "\n", "// Call function\n", "Graph(dataset);\n", "\n", "\n", "// Create function\n", "function Graph(data) {\n", "\n", " \n", " // Feed it through crossfilter \n", " var ndx = crossfilter(data);\n", " \n", " // for testing\n", " //console.log(data);\n", "\n", " //define a dimension\n", " //Here we will group by state\n", " var dim = ndx.dimension(function(d) {return d[\"flower_type\"]});\n", "\n", " //Here we group by state and sum on column population\n", " var g = dim.group().reduceSum(function(d){return d[\"sepal width (cm)\"];});\n", " \n", " //Lets create a row chart\n", " RowChart.dimension(dim)\n", " .group(g)\n", " .width(500); \n", "\n", " dc.renderAll(); // render all charts on the page\n", " \n", "}; // end graph function \n", " \n", "\"\"\"\n", ")\n", "\n", "dc_plot = Javascript(dc_template.render(data = df.to_json(orient=\"records\")))" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "iframe(head.data + body.data + \"\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }