def _set_render_properties(self, jooglechart):
        
        charts = jooglechart.charts
        view_cols = charts[0].view_cols

        # check if all charts have the same view cols
        if len(charts) > 1:
            charts = jooglechart.charts
            for chart in charts[1:]:
                if chart.view_cols != view_cols:
                    message = "For SeriesFilter, all charts must have the same view cols"
                    raise JoogleChartsException(message)
                
        series_indexes, series_names = jooglechart._get_viewable_series_indexes_and_names()

        # make data frame of series names to use for series filter DataTable        
        df = pd.DataFrame({'columns': series_names})

        # default selectedValues to all
        if not self._state.get('selectedValues'):
            self._state['selectedValues'] = series_names

        self._filter_table_json = dataframe_to_gviz(df).ToJSon()
        self._series_indexes = series_indexes
        self._num = get_joogle_object_counter()
        
        if self._label:
            self._name = self._label + FILTER_NAME_ADD_ON
            self._global_name = True
        else:
            self._name = "google_filter_" + str(self._num)
                    
        self._div_id = self._name + "_div_id"
    def _set_render_properties(self, chart_type=None):

        # chart render properties
        self.num = get_joogle_object_counter()
        self.name = "google_chart_" + str(self.num)
        self.chart_div_id = self.name + "_div_id"

        # set chart options to empty dict if it's been nulled out
        if self.chart_options == None:
            self.chart_options = {}


        # add default classes
        self.add_div_class("jooglechart_container")
#         self._div_classes.append("jooglechart_container")        
        chart_type_class = "jooglechart_type_" + self.chart_type
        self.add_div_class(chart_type_class)
#         self._div_classes.append(chart_type_class)


        # set chart type to display
        if chart_type == None:
            self.display_chart_type = self.chart_type
        else:
            self.display_chart_type = chart_type
 def _set_render_properties(self):
     
     # set name, div id, data name, bound filter names
     self._num = get_joogle_object_counter()
     self._name = "super_category_filter_" + str(self._num)
     self._div_id = self._name + "_div_id"
     self._filter_names = [name + FILTER_NAME_ADD_ON for name in self._filter_labels]
    def _set_render_properties(self, freestanding=False):
        
        self._num = get_joogle_object_counter()
        if self._label:
            self._name = self._label + FILTER_NAME_ADD_ON
            self._global_name = True
        else:
            self._name = "google_filter_" + str(self._num)
        self._div_id = self._name + "_div_id"
        
        # get data type, but only used for freestanding filters
        
        if freestanding and not "filterColumnIndex" in self._options:
            raise JoogleChartsException("Standalone filter must have filterColumnIndex")
        else:
            self._filter_column_index = self._options['filterColumnIndex']
#             self.add_options(filterColumnIndex=0)
#             if self._type == "CategoryFilter":
#                 self._data_type = "string"
#             elif self._type == "DateRangeFilter":
#                 self._data_type = "date"
#             elif self._type == "NumberRangeFilter":
#                 self._data_type = "number"

        # get has_selected_values to see if a one time ready listener is needed.
        self._has_selected_values = 'selectedValues' in self._state
    def _set_render_properties(self, chart_type=None):

        """
        Set values needed for rendering the chart
        """


        # jg render properties
        self.num = get_joogle_object_counter()
        self.name = "jooglechart_" + str(self.num)
        self.data_name = self.name + "_data"
        self.view_name = self.name + "_view"
        self.dashboard_name = self.name + "_dashboard"
        self.dashboard_div_id = self.dashboard_name + "_div_id"

        for styler in self._stylers:
            styler(self)            

        if self.json:
            # data is in a dataframe
            num_cols = len(self._dataframe.columns)

            # unicode            
            # Need to wrap the decoding in a try block so the user will be able to reshow
            # a chart in Jupyter.  If you reshow a chart, the code below will 
            # try to decode an already decoded string.         
            try:
                self.json = self.json.decode('utf-8')
            except UnicodeEncodeError:
                pass
        else:
            # data is in a 2d array
            num_cols = len(self._2d_array[0])

        # get the number of columns
        for index, chart in enumerate(self.charts):
            if index == 0:
                chart._set_render_properties(chart_type)
            else:
                chart._set_render_properties()

        # set render properties for filters
        for filter_ in self.filters:
            filter_._set_render_properties()

        # set render properties for series filter
        if self._series_filter:
            self._series_filter._set_render_properties(self)

        # modify json with roles
        if self.roles:
            json_decode = json.loads(self.json)
            for col, role in self.roles:
                if role == 'tooltip' and self.tooltip_html:
                    json_decode['cols'][col].update({'p': {'role': role, 'html': True}})
                    self.add_chart_options(tooltip_isHtml = True)
                else:
                    json_decode['cols'][col].update({'p': {'role': role}})
            self.json = json.dumps(json_decode)
    def _set_render_properties(self, chart_type=None):

        """
        Set values needed for rendering the chart
        """


        # jg render properties
        self.num = get_joogle_object_counter()
        self._name = "agg_chart_" + str(self.num)
        self._div_id = self._name + "_div_id"
        

        for styler in self._stylers:
            styler(self)            

        self._chart._set_render_properties(chart_type)
Exemple #7
0
    def _set_render_properties(self):
        
        self._num = get_joogle_object_counter()
        self._div_id = "button_group_" + str(self._num) + "_div_id"
        
        if type(self._values) == pd.Series:
            self._values = self._values.tolist()
                    
#         if self._clear_button_position == "last":
#             self._append_or_prepend = "append"
#         else:
#             self._append_or_prepend = "prepend"
            
        if self._orientation == "vertical":
            self._button_group_class = "btn-group-vertical"
        else:
            self._button_group_class = "btn-group"
Exemple #8
0
 def _set_render_properties(self):
     
     self._num = get_joogle_object_counter()
     self._div_id = "checkbox_group_" + str(self._num) + "_div_id"
     
     if type(self._values) == pd.Series:
         self._values = self._values.tolist()
     
     if self._clear_button:
         self._clear_button = "true"
     else:
         self._clear_button = 'false'
         
     if self._clear_button_position == "last":
         self._append_or_prepend = "append"
     else:
         self._append_or_prepend = "prepend"
    def __init__(self, type=None, options=None, cols=None, source_cols=None, dest_col=None, pattern=None):


        # validate formatter type
        try:
            formatter_ix = self.FORMATTER_TYPES.index(type)
        except ValueError:
            try:
                formatter = type.lower()
                formatter_ix = self.FORMATTER_TYPES_LOWER.index(formatter)
            except ValueError:
                message = "Format type submitted is not valid"
                raise JoogleChartsException(message)

        type = self.FORMATTER_TYPES[formatter_ix]

        if type == "ColorFormat":
            message = "ColorFormat is not currently supported"
            raise JoogleChartsException(message)


        if type == 'PatternFormat':
            if source_cols is None or pattern is None:
                message = "PatternFormat requires source_cols and pattern"
                raise JoogleChartsException(message)
        elif cols is None or options is None:
            message = "This format requires options and cols"
            raise JoogleChartsException(message)


        self.type = type
        self.options = options
        if isinstance(cols, int):
            cols = [cols]
        self.cols = cols
        self.source_cols = source_cols
        if self.type == "PatternFormat" and dest_col == None:
            self.dest_col = self.source_cols[0]
        else:
            self.dest_col = dest_col
        self.pattern = pattern

        self.num = get_joogle_object_counter()
        self.name = "formatter" + str(self.num)
    def render(self, include_common=None):

        num = get_joogle_object_counter()
        self._div_id = self._div_prefix + str(num)

        context = {}
        context[self._context_name] = self
        context['callback_name'] = 'doStuff_' + str(num)

        # call common context method before rendering all child
        # objects
        set_common_on_context(context, include_common)

        if hasattr(self, "_objects"):
            # container takes multiple objects
            for obj in self._objects:
                if isinstance(obj, (str, unicode)):
                    self._content_strings.append(obj)
                else:
                    self._content_strings.append(obj.render(include_common=False))
        elif hasattr(self, "_content"):
            # container takes one object
            if isinstance(self._content, (str, unicode)):
                self._content_string = self._content
            else:
                self._content_string = self._content.render(include_common=False)


        # check if we need to include the Toggler prototype
#         if self._context_name == "toggler":
#             if ContainerRender._first_toggler:
#                 ContainerRender._first_toggler = False
#                 context["include_toggler_prototype"] = True


        return j2_env.get_template(self._template).render(context).encode('utf-8')
Exemple #11
0
 def _set_render_properties(self):
     
     self._num = get_joogle_object_counter()
     self._div_id = "joogle_legend_" + str(self._num) + "_div_id"