Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Holoviews / Bokeh rendering engine #32

Closed
synw opened this issue Nov 17, 2017 · 0 comments
Closed

Support for Holoviews / Bokeh rendering engine #32

synw opened this issue Nov 17, 2017 · 0 comments

Comments

@synw
Copy link
Owner

synw commented Nov 17, 2017

Support for Holoviews with the Bokeh rendering engine has been added #13 . We can now choose what rendering engine to use for each chart. It is possible to compose dashboards that use both engines.

Technically many things have changed. All the charts generation logics now live in an external module: Dataswim, a data analytics library of my composition that is equipped to handle charts.
The generation logics for Altair is isolated in a specific module and freezed while waiting for Altair 2.

Chartflo is now only responsible for Django related stuff: mostly the dashboards view and the events-based charts generation. As a result both the code and api had been drastically simplified: ex:

from chartflo.charts import chart
from django.contrib.auth.models import User

# get the data
all_users = User.objects.filter(is_active=True)
staff = all_users.filter(is_staff=True).count()
superusers = all_users.filter(is_superuser=True).count()
users = all_users.filter(is_superuser=False, is_staff=False).count()

# declare the data
data = [users, staff, superusers]
index = ["Users", "Staff", "Superusers"]
columns = ["Number"]
chart.load_data("Groups", data, columns=columns, index=index)

# get the chart
c = chart.draw("Groups", "Number", chart_type="bar")
# now in a jupyter notebook you can type:just 'c' to draw the chart
# store the chart for later exporting
chart.stack("registrations1", "User registrations 1", c)
# ... make other charts
# then export to files in the folder templates/data/html
chart.export("data/html")

Example of a generator that takes the user registration dates, aggregate them by one day and draw a line chart using Bokeh and points chart using Altair:

from dataswim import ds
from django.contrib.auth.models import User
from chartflo.charts import chart


def run(events=None):
    # 1. crunch data
    q = User.objects.all()
    # load data from a django query
    ds.load_django(q, dateindex="date_joined")
    # keep only the relevant data
    ds.keep("date_joined", "username")
    # resample data by one day periods
    ds.rsum("1D")
    # 2. draw charts
    # Note: ds.df is a pandas DataFrame instance
    c = chart.draw("date", "num", ds.df, "line")
    chart.stack("registrations1", "User registrations 1", c)
    chart.engine = "altair"
    x = ("date", "date:T")
    y = ("num", "num:Q")
    # if no dataset is passed, it will use the previously declared one
    c2 = chart.draw(x, y, chart_type= "circle")
    chart.stack("user_registrations", "User registrations", c2)
   # Write the charts html to files
    chart.export("data/html")

The Holoviews Bokeh rendering engine is now default. Altair 1 is getting old and is lagging behind: we are waiting for Altair 2. Furthermore Bokeh is more powerful and offers a very nice interactivity.

To resume we now have:

  • More power
  • More lazyness

I will update the doc and the examples soon and release.

[Edit]: comments in code

@synw synw added this to the 0.3.0 Roadmap milestone Nov 17, 2017
@synw synw closed this as completed Nov 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant