Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Maluuba/bokeh

Repository files navigation

Bokeh: Maluuba FigureQA Fork

Introduction

This fork of Bokeh gets the bounding boxes of drawn primitives.

It is based on Bokeh version 0.12.6.

Bokeh is very easy to use and extend, and has no dependency on matplotlib.

At a high-level, here's how the library works:

  • The figure is defined in Python. Source code lives in the Bokeh Python library (bokeh/bokeh).

    • Make sure you add name attributes to the different parts of your figure.
    • Use the export_png_and_data function from bokeh.io to get the PNG and a Python dict of the bounding box data.
    • See the examples in bokeh/bokeh/example_graphs.
  • The Bokeh Python library calls the Bokeh JavaScript library (bokeh/bokehjs) which renders the plot to a canvas using a headless browser, then exports this to a PNG.

    • The Python lib generates an HTML file with JSON defining the figure.
    • The JS lib takes the HTML file and renders it in a headless browser (PhantomJS).
    • The JS lib renders the figure (model-view coffeescript, like Backbone.js) and performs the drawing to canvas.
    • While drawing, the JS lib calculates bounding boxes, associates them with names defined in the Python figure, and saves these annotations to localStorage in PhantomJS.
    • The Python lib then grabs the data from the PhantomJS webdriver's localStorage.

Prerequisites and Installation

Note: there's no need to install the requirements from requirements.txt if you run setup.py.

  1. If on Linux, install these packages:
    • libfontconfig (e.g. sudo apt-get install libfontconfig).
    • zlib (e.g. sudo apt-get install zlib1g-dev)
    • libjpeg (e.g. sudo apt-get install libjpeg-dev)
  2. Install NodeJS LTS from here. These instructions are based on Node version 11.15.0. Note that this won't build with node > 11 because of a gulp issue.
  3. npm install -g phantomjs-prebuilt to install PhantomJS globally. This may have to be done in sudo or Administrator mode.
    • Note if you are using npm >= 5.x add --unsafe-perm to the command (see here).
    • If you have trouble on Windows, try npm cache clean --force. A full list of troubleshooting tips can be found here.
  4. Make sure the PhantomJS executable is on your PATH. On Windows, I found mine in C:\Users\<user>\AppData\Roaming\npm\node_modules\phantomjs-prebuilt\lib\phantom\bin.
  5. Clone this repo or unzip the source from the release page.
  6. cd bokeh/bokehjs.
  7. npm install.
  8. cd ../bokeh.
  9. python setup.py install --build-js

Development

See the Bokeh developer guide here.

Python + JS

To use changes to both the Bokeh Python and JS libs, you need to run either

  • python setup.py develop --build-js (to build the JS bundle fresh and include it in the Python library) or
  • python setup.py develop --install-js (to use the last built JS bundle)

every time you want to use new Bokeh JS changes with the Bokeh Python library.

I.e. if you've made changes to the JS files and want to test them with the Python lib, you need to run python setup.py develop --build-js again to package the latest JS lib into the Python lib.

Python Only

If you've made changes to the Python files only, and run python setup.py develop --build-js/--install-js once, you don't need to do anything more.

Your Bokeh Python changes will be picked up immediately.

JS Only

  1. cd bokeh/bokehjs
  2. gulp watch if you want to recompile on new changes, or gulp dev-build to build an un-minified bundle.

Workflow

You can run gulp watch to rebuild the library in dev mode everytime bokeh/bokehjs/src files are modified.

To use this bundle right away, you can use a modified HTML file generated by the Python lib. This can be done with a reference to the generated bundle in the build directory using a script tag like <script type="text/javascript" src="build/js/bokeh.js"></script>. This will pick up the latest bundle genenerated by gulp.

This lets you analyze console errors and debug faster than rebuilding the whole Bokeh library every time.

See the samples in the bokeh/bokeh/example_graphs directory to see how you can generate one of these files.

Usage and Examples

Some examples are provided in bokeh/bokeh/example_graphs.

Stuff from original Bokeh README

Latest Release latest release
License Bokeh license
Build Status build status
Conda conda downloads
PyPI
Gitter
Twitter

Bokeh, a Python interactive visualization library, enables beautiful and meaningful visual presentation of data in modern web browsers. With Bokeh, you can quickly and easily create interactive plots, dashboards, and data applications.

Bokeh helps provide elegant, concise construction of novel graphics in the style of D3.js, while also delivering high-performance interactivity over very large or streaming datasets.

image anscombe stocks lorenz candlestick scatter splom
iris histogram periodic choropleth burtin streamline image_rgba
stacked quiver elements boxplot categorical unemployment les_mis

Documentation

Visit the Bokeh web page for information and full documentation.

Contribute to Bokeh

To contribute to Bokeh, please review the Developer Guide.

Follow us

Follow us on Twitter @bokehplots and on YouTube.