Exemple #1
0
 def __init__(self, datasource, series_options, chart_options=None, x_sortf_mapf_mts=None):
     self.user_input = locals()
     if not isinstance(datasource, DataPool):
         raise APIInputError("%s must be an instance of DataPool." % datasource)
     self.datasource = datasource
     self.series_options = clean_cso(series_options, self.datasource)
     self.x_sortf_mapf_mts = clean_x_sortf_mapf_mts(x_sortf_mapf_mts)
     self.x_axis_vqs_groups = self._groupby_x_axis_and_vqs()
     self._set_default_hcoptions(chart_options)
     self.generate_plot()
Exemple #2
0
 def __init__(self, datasource, series_options, chart_options=None,
              x_sortf_mapf_mts=None):
     self.user_input = locals()
     if not isinstance(datasource, DataPool):
         raise APIInputError("%s must be an instance of DataPool." 
                             %datasource)
     self.datasource = datasource
     self.series_options = clean_cso(series_options, self.datasource)
     self.x_sortf_mapf_mts = clean_x_sortf_mapf_mts(x_sortf_mapf_mts)
     self.x_axis_vqs_groups = self._groupby_x_axis_and_vqs()
     self._set_default_hcoptions(chart_options)
     self.generate_plot()
Exemple #3
0
    def __init__(self, datasource, series_options, chart_options=None,
                 x_sortf_mapf_mts=None):
        """Chart accept the datasource and some options to create the chart and
        creates it.

        **Arguments**:

        - **datasource** (**required**) - a ``DataPool`` object that holds the
          terms and other information to plot the chart from.

        - **series_options** (**required**) - specifies the options to plot
          the terms on the chart. It is of the form ::

            [{'options': {
                #any items from HighChart series. For ex.,
                'type': 'column'
               },
               'terms': {
                 'x_name': ['y_name',
                            {'other_y_name': {
                               #overriding options}},
                            ...],
                 ...
                 },
               },
              ... #repeat dicts with 'options' & 'terms'
              ]

          Where -

          - **options** (**required**) - a ``dict``. Any of the parameters
            from the `Highcharts options object - series array
            <http://www.highcharts.com/ref/#series>`_ are valid as entries in
            the ``options`` dict except ``data`` (because data array is
            generated from your datasource by chartit). For example, ``type``,
            ``xAxis``, etc. are all valid entries here.

            .. note:: The items supplied in the options dict are not validated
               to make sure that Highcharts actually supports them. Any
               invalid options are just passed to Highcharts JS which silently
               ignores them.

          - **terms** (**required**) - a ``dict``. keys are the x-axis terms
            and the values are lists of y-axis terms for that particular
            x-axis term. Both x-axis and y-axis terms must be present in the
            corresponding datasource, otherwise an APIInputError is raised.

            The entries in the y-axis terms list must either be a ``str`` or
            a ``dict``. If entries are dicts, the keys need to be valid y-term
            names and the values need to be any options to override the
            default options. For example, ::

              [{'options': {
                  'type': 'column',
                  'yAxis': 0},
                'terms': {
                  'city': [
                    'temperature',
                   {'rainfall': {
                      'type': 'line',
                      'yAxis': 1}}]}}]

            plots a column chart of city vs. temperature as a line chart on
            yAxis: 0 and city vs. rainfall as a line chart on yAxis: 1. This
            can alternatively be expressed as two separate entries: ::

              [{'options': {
                  'type': 'column',
                  'yAxis': 0},
                'terms': {
                  'city': [
                    'temperature']}},
               {'options': {
                  'type': 'line',
                  'yAxis': 1},
                'terms': {
                  'city': [
                    'rainfall']}}]

        - **chart_options** (*optional*) - a ``dict``. Any of the options from
          the `Highcharts options object <http://www.highcharts.com/ref/>`_
          are valid (except the options in the ``series`` array which are
          passed in the ``series_options`` argument. The following
          ``chart_options`` for example, set the chart title and the axes
          titles. ::

              {'chart': {
                 'title': {
                   'text': 'Weather Chart'}},
               'xAxis': {
                 'title': 'month'},
               'yAxis': {
                 'title': 'temperature'}}

          .. note:: The items supplied in the ``chart_options`` dict are not
             validated to make sure that Highcharts actually supports them.
             Any invalid options are just passed to Highcharts JS which
             silently ignores them.

        **Raises**:

        - ``APIInputError`` if any of the terms are not present in the
          corresponding datasource or if the ``series_options`` cannot be
          parsed.
        """

        self.user_input = locals()
        if not isinstance(datasource, DataPool):
            raise APIInputError("%s must be an instance of DataPool."
                                % datasource)
        self.datasource = datasource
        self.series_options = clean_cso(series_options, self.datasource)
        self.x_sortf_mapf_mts = clean_x_sortf_mapf_mts(x_sortf_mapf_mts)
        self.x_axis_vqs_groups = self._groupby_x_axis_and_vqs()
        self._set_default_hcoptions(chart_options)
        self.generate_plot()
Exemple #4
0
    def __init__(self,
                 datasource,
                 series_options,
                 chart_options=None,
                 x_sortf_mapf_mts=None):
        """Chart accept the datasource and some options to create the chart and
        creates it. 
        
        **Arguments**:
        
        - **datasource** (**required**) - a ``DataPool`` object that holds the 
          terms and other information to plot the chart from.
          
        - **series_options** (**required**) - specifies the options to plot 
          the terms on the chart. It is of the form ::
           
            [{'options': {
                #any items from HighChart series. For ex.,
                'type': 'column'
               },
               'terms': {
                 'x_name': ['y_name', 
                            {'other_y_name': {
                               #overriding options}}, 
                            ...],
                 ...
                 },
               },
              ... #repeat dicts with 'options' & 'terms'
              ]
            
          Where - 
          
          - **options** (**required**) - a ``dict``. Any of the parameters 
            from the `Highcharts options object - series array
            <http://www.highcharts.com/ref/#series>`_ are valid as entries in 
            the ``options`` dict except ``data`` (because data array is 
            generated from your datasource by chartit). For example, ``type``, 
            ``xAxis``, etc. are all valid entries here. 
            
            .. note:: The items supplied in the options dict are not validated 
               to make sure that Highcharts actually supports them. Any 
               invalid options are just passed to Highcharts JS which silently 
               ignores them.
               
          - **terms** (**required**) - a ``dict``. keys are the x-axis terms
            and the values are lists of y-axis terms for that particular 
            x-axis term. Both x-axis and y-axis terms must be present in the 
            corresponding datasource, otherwise an APIInputError is raised.
            
            The entries in the y-axis terms list must either be a ``str`` or 
            a ``dict``. If entries are dicts, the keys need to be valid y-term 
            names and the values need to be any options to override the 
            default options. For example, ::
            
              [{'options': {
                  'type': 'column',
                  'yAxis': 0},
                'terms': {
                  'city': [
                    'temperature',
                   {'rainfall': {
                      'type': 'line',
                      'yAxis': 1}}]}}]
            
            plots a column chart of city vs. temperature as a line chart on 
            yAxis: 0 and city vs. rainfall as a line chart on yAxis: 1. This 
            can alternatively be expressed as two separate entries: ::
            
              [{'options': {
                  'type': 'column',
                  'yAxis': 0},
                'terms': {
                  'city': [
                    'temperature']}},
               {'options': {
                  'type': 'line',
                  'yAxis': 1},
                'terms': {
                  'city': [
                    'rainfall']}}]
                    
        - **chart_options** (*optional*) - a ``dict``. Any of the options from 
          the `Highcharts options object <http://www.highcharts.com/ref/>`_ 
          are valid (except the options in the ``series`` array which are 
          passed in the ``series_options`` argument. The following 
          ``chart_options`` for example, set the chart title and the axes 
          titles. :: 
          
              {'chart': {
                 'title': { 
                   'text': 'Weather Chart'}},
               'xAxis': {
                 'title': 'month'},
               'yAxis': {
                 'title': 'temperature'}}
                 
          .. note:: The items supplied in the ``chart_options`` dict are not 
             validated to make sure that Highcharts actually supports them. 
             Any invalid options are just passed to Highcharts JS which 
             silently ignores them.
             
        **Raises**: 
        
        - ``APIInputError`` if any of the terms are not present in the 
          corresponding datasource or if the ``series_options`` cannot be 
          parsed.
        """

        self.user_input = locals()
        if not isinstance(datasource, DataPool):
            raise APIInputError("%s must be an instance of DataPool." %
                                datasource)
        self.datasource = datasource
        self.series_options = clean_cso(series_options, self.datasource)
        self.x_sortf_mapf_mts = clean_x_sortf_mapf_mts(x_sortf_mapf_mts)
        self.x_axis_vqs_groups = self._groupby_x_axis_and_vqs()
        self._set_default_hcoptions(chart_options)
        self.generate_plot()