From 07c9310833e46e43371441cf46efd62e0c0a244c Mon Sep 17 00:00:00 2001 From: sidgupta Date: Sun, 17 Apr 2016 16:23:32 -0700 Subject: [PATCH] make visualizations configurable --- caravel/config.py | 54 +++++++++++++++++++++------------------ caravel/viz.py | 65 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 83 insertions(+), 36 deletions(-) diff --git a/caravel/config.py b/caravel/config.py index 47af8a040aec2..1617e27680447 100644 --- a/caravel/config.py +++ b/caravel/config.py @@ -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 @@ -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' @@ -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, } diff --git a/caravel/viz.py b/caravel/viz.py index a78523a606571..73a694d93ec73 100644 --- a/caravel/viz.py +++ b/caravel/viz.py @@ -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 @@ -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 Caravel original' fieldsets = ({ 'label': "Chart Options", @@ -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 Caravel original' is_timeseries = False fieldsets = ({ @@ -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') @@ -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, @@ -493,6 +496,7 @@ class TreemapViz(BaseViz): viz_type = "treemap" verbose_name = "Treemap" + enable_viz_type = config.get('VIZ_TYPES')[viz_type] credits = 'd3.js' is_timeseries = False @@ -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 = ({ @@ -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, @@ -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 Caravel original' is_timeseries = True fieldsets = ({ @@ -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 Caravel original' is_timeseries = False fieldsets = ({ @@ -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 = ({ @@ -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': ( @@ -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): @@ -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', @@ -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, @@ -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', @@ -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 ' @@ -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 = 'd3-sankey on npm' fieldsets = ({ @@ -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 @bl.ocks.org' is_timeseries = False fieldsets = ({ @@ -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 npm' fieldsets = ({ @@ -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 Caravel original' fieldsets = ({ @@ -1400,6 +1419,7 @@ class IFrameViz(BaseViz): viz_type = "iframe" verbose_name = "iFrame" + enable_viz_type = config.get('VIZ_TYPES')[viz_type] credits = 'a Caravel original' is_timeseries = False fieldsets = ({ @@ -1418,6 +1438,7 @@ class ParallelCoordinatesViz(BaseViz): viz_type = "para" verbose_name = "Parallel Coordinates" + enable_viz_type = config.get('VIZ_TYPES')[viz_type] credits = ( '' 'Syntagmatic\'s library') @@ -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 @' @@ -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