Skip to content

Commit

Permalink
make visualizations configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
sidgupta committed Apr 17, 2016
1 parent b49b40e commit 07c9310
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 36 deletions.
54 changes: 29 additions & 25 deletions caravel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ROW_LIMIT = 50000
WEBSERVER_THREADS = 8

CARAVEL_WEBSERVER_PORT = 8001
CARAVEL_WEBSERVER_PORT = 8088
CARAVEL_WEBSERVER_TIMEOUT = 60

CUSTOM_SECURITY_MANAGER = None
Expand All @@ -33,7 +33,7 @@
SECRET_KEY = '\2\1thisismyscretkey\1\2\e\y\y\h' # noqa

# The SQLAlchemy connection string.
SQLALCHEMY_DATABASE_URI = 'sqlite:////Users/sidgupta/Desktop/caravelx.db'
SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/caravel.db'
# SQLALCHEMY_DATABASE_URI = 'mysql://myapp@localhost/myapp'
# SQLALCHEMY_DATABASE_URI = 'postgresql://root:password@localhost/myapp'

Expand Down Expand Up @@ -122,30 +122,34 @@
CACHE_CONFIG = {'CACHE_TYPE': 'null'}


# ---------------------------------------------------
# Enable different visualizations: True or False (refer viz.py)
# ---------------------------------------------------

VIZ_TYPES = {
'TableViz': True,
'PivotTableViz': True,
'NVD3TimeSeriesViz': True,
'NVD3CompareTimeSeriesViz': True,
'NVD3TimeSeriesStackedViz': True,
'NVD3TimeSeriesBarViz': True,
'DistributionBarViz': True,
'DistributionPieViz': True,
'BubbleViz': True,
'MarkupViz': True,
'WordCloudViz': True,
'BigNumberViz': True,
'BigNumberTotalViz': True,
'SunburstViz': True,
'DirectedForceViz': True,
'SankeyViz': True,
'WorldMapViz': True,
'FilterBoxViz': True,
'IFrameViz': True,
'ParallelCoordinatesViz': True,
'HeatmapViz': True,
'BoxPlotViz': True,
'TreemapViz': True,
'table': True,
'pivot_table': False,
'markup': False,
'word_cloud': True,
'treemap': True,
'box_plot': True,
'bubble': True,
'big_number': True,
'big_number_total': True,
'line': True,
'bar': True,
'compare': True,
'area': True,
'pie': True,
'dist_bar': True,
'sunburst': True,
'sankey': True,
'directed_force': True,
'world_map': True,
'filter_box': True,
'iframe': True,
'para': True,
'heatmap': True,
}


Expand Down
65 changes: 54 additions & 11 deletions caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import uuid
from collections import OrderedDict, defaultdict
from datetime import datetime, timedelta
import collections
import pandas as pd
import numpy as np
from flask import flash, request, Markup
Expand Down Expand Up @@ -313,6 +312,7 @@ class TableViz(BaseViz):

viz_type = "table"
verbose_name = "Table View"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
credits = 'a <a href="https://github.com/airbnb/caravel">Caravel</a> original'
fieldsets = ({
'label': "Chart Options",
Expand Down Expand Up @@ -371,6 +371,7 @@ class PivotTableViz(BaseViz):

viz_type = "pivot_table"
verbose_name = "Pivot Table"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
credits = 'a <a href="https://github.com/airbnb/caravel">Caravel</a> original'
is_timeseries = False
fieldsets = ({
Expand Down Expand Up @@ -433,6 +434,7 @@ class MarkupViz(BaseViz):

viz_type = "markup"
verbose_name = "Markup Widget"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
fieldsets = ({
'label': None,
'fields': ('markup_type', 'code')
Expand Down Expand Up @@ -461,6 +463,7 @@ class WordCloudViz(BaseViz):

viz_type = "word_cloud"
verbose_name = "Word Cloud"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
is_timeseries = False
fieldsets = ({
'label': None,
Expand Down Expand Up @@ -493,6 +496,7 @@ class TreemapViz(BaseViz):

viz_type = "treemap"
verbose_name = "Treemap"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
credits = '<a href="https://d3js.org">d3.js</a>'
is_timeseries = False

Expand Down Expand Up @@ -534,6 +538,7 @@ class BoxPlotViz(NVD3Viz):

viz_type = "box_plot"
verbose_name = "Box Plot"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
sort_series = False
is_timeseries = True
fieldsets = ({
Expand Down Expand Up @@ -641,6 +646,7 @@ class BubbleViz(NVD3Viz):

viz_type = "bubble"
verbose_name = "Bubble Chart"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
is_timeseries = False
fieldsets = ({
'label': None,
Expand Down Expand Up @@ -709,6 +715,7 @@ class BigNumberViz(BaseViz):

viz_type = "big_number"
verbose_name = "Big Number with Trendline"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
credits = 'a <a href="https://github.com/airbnb/caravel">Caravel</a> original'
is_timeseries = True
fieldsets = ({
Expand Down Expand Up @@ -759,6 +766,7 @@ class BigNumberTotalViz(BaseViz):

viz_type = "big_number_total"
verbose_name = "Big Number"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
credits = 'a <a href="https://github.com/airbnb/caravel">Caravel</a> original'
is_timeseries = False
fieldsets = ({
Expand Down Expand Up @@ -805,6 +813,7 @@ class NVD3TimeSeriesViz(NVD3Viz):

viz_type = "line"
verbose_name = "Time Series - Line Chart"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
sort_series = False
is_timeseries = True
fieldsets = ({
Expand Down Expand Up @@ -945,6 +954,7 @@ class NVD3TimeSeriesBarViz(NVD3TimeSeriesViz):
viz_type = "bar"
sort_series = True
verbose_name = "Time Series - Bar Chart"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
fieldsets = [NVD3TimeSeriesViz.fieldsets[0]] + [{
'label': 'Chart Options',
'fields': (
Expand All @@ -963,6 +973,7 @@ class NVD3CompareTimeSeriesViz(NVD3TimeSeriesViz):

viz_type = 'compare'
verbose_name = "Time Series - Percent Change"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]


class NVD3TimeSeriesStackedViz(NVD3TimeSeriesViz):
Expand All @@ -971,6 +982,7 @@ class NVD3TimeSeriesStackedViz(NVD3TimeSeriesViz):

viz_type = "area"
verbose_name = "Time Series - Stacked"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
sort_series = True
fieldsets = [NVD3TimeSeriesViz.fieldsets[0]] + [{
'label': 'Chart Options',
Expand All @@ -990,6 +1002,7 @@ class DistributionPieViz(NVD3Viz):

viz_type = "pie"
verbose_name = "Distribution - NVD3 - Pie Chart"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
is_timeseries = False
fieldsets = ({
'label': None,
Expand Down Expand Up @@ -1026,6 +1039,7 @@ class DistributionBarViz(DistributionPieViz):

viz_type = "dist_bar"
verbose_name = "Distribution - Bar Chart"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
is_timeseries = False
fieldsets = ({
'label': 'Chart Options',
Expand Down Expand Up @@ -1106,6 +1120,7 @@ class SunburstViz(BaseViz):

viz_type = "sunburst"
verbose_name = "Sunburst"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
is_timeseries = False
credits = (
'Kerry Rodden '
Expand Down Expand Up @@ -1172,6 +1187,7 @@ class SankeyViz(BaseViz):

viz_type = "sankey"
verbose_name = "Sankey"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
is_timeseries = False
credits = '<a href="https://www.npmjs.com/package/d3-sankey">d3-sankey on npm</a>'
fieldsets = ({
Expand Down Expand Up @@ -1236,6 +1252,7 @@ class DirectedForceViz(BaseViz):

viz_type = "directed_force"
verbose_name = "Directed Force Layout"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
credits = 'd3noob @<a href="http://bl.ocks.org/d3noob/5141278">bl.ocks.org</a>'
is_timeseries = False
fieldsets = ({
Expand Down Expand Up @@ -1278,6 +1295,7 @@ class WorldMapViz(BaseViz):

viz_type = "world_map"
verbose_name = "World Map"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
is_timeseries = False
credits = 'datamaps on <a href="https://www.npmjs.com/package/datamaps">npm</a>'
fieldsets = ({
Expand Down Expand Up @@ -1352,6 +1370,7 @@ class FilterBoxViz(BaseViz):

viz_type = "filter_box"
verbose_name = "Filters"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
is_timeseries = False
credits = 'a <a href="https://github.com/airbnb/caravel">Caravel</a> original'
fieldsets = ({
Expand Down Expand Up @@ -1400,6 +1419,7 @@ class IFrameViz(BaseViz):

viz_type = "iframe"
verbose_name = "iFrame"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
credits = 'a <a href="https://github.com/airbnb/caravel">Caravel</a> original'
is_timeseries = False
fieldsets = ({
Expand All @@ -1418,6 +1438,7 @@ class ParallelCoordinatesViz(BaseViz):

viz_type = "para"
verbose_name = "Parallel Coordinates"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
credits = (
'<a href="https://syntagmatic.github.io/parallel-coordinates/">'
'Syntagmatic\'s library</a>')
Expand Down Expand Up @@ -1455,6 +1476,7 @@ class HeatmapViz(BaseViz):

viz_type = "heatmap"
verbose_name = "Heatmap"
enable_viz_type = config.get('VIZ_TYPES')[viz_type]
is_timeseries = False
credits = (
'inspired from mbostock @<a href="http://bl.ocks.org/mbostock/3074470">'
Expand Down Expand Up @@ -1514,13 +1536,34 @@ def get_data(self):
return df.to_dict(orient="records")


viz_types = collections.OrderedDict()

temp = config.get('VIZ_TYPES')


for key, value in temp.items():
if value:
viz_types[key] = key

print(viz_types)
viz_types_list = [
TableViz,
PivotTableViz,
NVD3TimeSeriesViz,
NVD3CompareTimeSeriesViz,
NVD3TimeSeriesStackedViz,
NVD3TimeSeriesBarViz,
DistributionBarViz,
DistributionPieViz,
BubbleViz,
MarkupViz,
WordCloudViz,
BigNumberViz,
BigNumberTotalViz,
SunburstViz,
DirectedForceViz,
SankeyViz,
WorldMapViz,
FilterBoxViz,
IFrameViz,
ParallelCoordinatesViz,
HeatmapViz,
BoxPlotViz,
TreemapViz,
]

viz_types = OrderedDict()

for v in viz_types_list:
if v.enable_viz_type:
viz_types[v.viz_type] = v

0 comments on commit 07c9310

Please sign in to comment.