fireant.slicer.widgets package

Submodules

fireant.slicer.widgets.base module

class fireant.slicer.widgets.base.TransformableWidget(*items)[source]

Bases: fireant.slicer.widgets.base.Widget

group_pagination = False
transform(data_frame, slicer, dimensions, references)[source]
  • Main entry point -

Transformers the result set pd.DataFrame from a slicer query into the output format for this specific widget type.

Parameters:
  • data_frame – The data frame containing the data. Index must match the dimensions parameter.
  • slicer – The slicer that is in use.
  • dimensions – A list of dimensions that are being rendered.
  • references – A list of references that are being rendered.
Returns:

A dict meant to be dumped as JSON.

class fireant.slicer.widgets.base.Widget(*items)[source]

Bases: object

item(*args, mutate=False, **kwargs)
Parameters:mutate – When True, overrides the immutable behavior of this decorator.
metrics
operations

fireant.slicer.widgets.csv module

class fireant.slicer.widgets.csv.CSV(metric: fireant.slicer.metrics.Metric, *metrics, group_pagination=False, **kwargs)[source]

Bases: fireant.slicer.widgets.pandas.Pandas

transform(data_frame, slicer, dimensions, references)[source]

WRITEME

Parameters:
  • data_frame
  • slicer
  • dimensions
  • references
Returns:

fireant.slicer.widgets.datatables module

class fireant.slicer.widgets.datatables.DataTablesJS(metric, *metrics, pivot=False, max_columns=None)[source]

Bases: fireant.slicer.widgets.base.TransformableWidget

transform(data_frame, slicer, dimensions, references)[source]

WRITEME

Parameters:
  • data_frame
  • slicer
  • dimensions
Returns:

fireant.slicer.widgets.helpers module

fireant.slicer.widgets.helpers.dimensional_metric_label(dimensions, dimension_display_values)[source]

Creates a callback function for rendering series labels.

Parameters:
  • dimensions – A list of fireant.Dimension which is being rendered.
  • dimension_display_values – A dictionary containing key-value pairs for each dimension.
Returns:

a callback function which renders a label for a metric, reference, and list of dimension values.

fireant.slicer.widgets.helpers.extract_display_values(dimensions, data_frame)[source]

Retrieves the display values for each dimension.

For UniqueDimension, this will retrieve the display values from the data frame containing the data from the slicer query. For CategoricalDimension, the values are retrieved from the set of display values configured in the slicer.

Parameters:
  • dimensions – A list of dimensions present in a slicer query.
  • data_frame – The data frame containing the data result of the slicer query.
Returns:

A dict containing keys for dimensions with display values (If there are no display values then the dimension’s key will not be present). The value of the dict will be either a dict or a data frame where the display value can be accessed using the display value as the key.

fireant.slicer.widgets.highcharts module

class fireant.slicer.widgets.highcharts.HighCharts(title=None, colors=None, x_axis_visible=True, tooltip_visible=True)[source]

Bases: fireant.slicer.widgets.chart_base.ChartWidget, fireant.slicer.widgets.base.TransformableWidget

group_pagination = True
transform(data_frame, slicer, dimensions, references)[source]
  • Main entry point -

Transforms a data frame into HighCharts JSON format.

See https://api.highcharts.com/highcharts/

Parameters:
  • data_frame – The data frame containing the data. Index must match the dimensions parameter.
  • slicer – The slicer that is in use.
  • dimensions – A list of dimensions that are being rendered.
  • references – A list of references that are being rendered.
Returns:

A dict meant to be dumped as JSON.

fireant.slicer.widgets.matplotlib module

class fireant.slicer.widgets.matplotlib.Matplotlib(title=None)[source]

Bases: fireant.slicer.widgets.chart_base.ChartWidget, fireant.slicer.widgets.base.TransformableWidget

static get_plot_func_for_series_type(pd_series, label, chart_series)[source]
transform(data_frame, slicer, dimensions, references)[source]
  • Main entry point -

Transformers the result set pd.DataFrame from a slicer query into the output format for this specific widget type.

Parameters:
  • data_frame – The data frame containing the data. Index must match the dimensions parameter.
  • slicer – The slicer that is in use.
  • dimensions – A list of dimensions that are being rendered.
  • references – A list of references that are being rendered.
Returns:

A dict meant to be dumped as JSON.

fireant.slicer.widgets.pandas module

class fireant.slicer.widgets.pandas.Pandas(metric: fireant.slicer.metrics.Metric, *metrics, pivot=(), transpose=False, sort=None, ascending=None, max_columns=None)[source]

Bases: fireant.slicer.widgets.base.TransformableWidget

pivot_data_frame(data_frame, pivot=(), transpose=False)[source]

Pivot and transpose the data frame. Dimensions including in the pivot arg will be unshifted to columns. If transpose is True the data frame will be transposed. If there is only index level in the data frame (ie. one dimension), and that dimension is pivoted, then the data frame will just be transposed. If there is a single metric in the data frame and at least one dimension pivoted, the metrics column level will be dropped for simplicity.

Parameters:
  • data_frame – The result set data frame
  • pivot – A list of index keys for data_frame of levels to shift
  • transpose – A boolean true or false whether to transpose the data frame.
Returns:

The shifted/transposed data frame

sort_data_frame(data_frame)[source]
transform(data_frame, slicer, dimensions, references)[source]

WRITEME

Parameters:
  • data_frame
  • slicer
  • dimensions
  • references
Returns:

fireant.slicer.widgets.reacttable module

class fireant.slicer.widgets.reacttable.ReactTable(metric, *metrics, pivot=(), transpose=False, sort=None, ascending=None, max_columns=None)[source]

Bases: fireant.slicer.widgets.pandas.Pandas

This component does not work with react-table out of the box, some customization is needed in order to work with the transformed data.

// A Custom TdComponent implementation is required by Fireant in order to render display values
const TdComponent = ({
                       toggleSort,
                       className,
                       children,
                       ...rest
                     }) =>
    <div className={classNames('rt-td', className)} role="gridcell" {...rest}>
        {_.get(children, 'display', children.raw) || <span>&nbsp;</span>}
    </div>;

const FireantReactTable = ({
                        config, // The payload from fireant
                      }) =>
    <ReactTable columns={config.columns}
                data={config.data}
                minRows={0}

                TdComponent={ DashmoreTdComponent}
                defaultSortMethod={(a, b, desc) => ReactTableDefaults.defaultSortMethod(a.raw, b.raw, desc)}>
    </ReactTable>;
static format_data_frame(data_frame, dimensions)[source]

This function prepares the raw data frame for transformation by formatting dates in the index and removing any remaining NaN/NaT values. It also names the column as metrics so that it can be treated like a dimension level.

Parameters:
  • data_frame – The result set data frame
  • dimensions
Returns:

static map_display_values(df, dimensions)[source]

Creates a mapping for dimension values to their display values.

Parameters:
  • df – The result data set that is being transformed.
  • dimensions – The list of dimensions included in the query that created the result data set df.
Returns:

A tree-structure dict with two levels of depth. The top level dict has keys for each dimension’s display key. The lower level dict has keys for each raw dimension value and values which are the display value.

Creates a mapping for each dimension to it’s hyperlink template if it is possible to create the hyperlink template for it.

The hyperlink template is a URL-like string containing curley braces enclosing dimension keys: {dimension}. While rendering this widget, the dimension key placeholders need to be replaced with the dimension values for that row.

Parameters:
  • df – The result data set that is being transformed. The data frame SHOULD be pivoted/transposed if that step is required, before calling this function, in order to prevent the template from being included for the dimension if one of the required dimensions is pivoted.
  • dimensions – The list of dimensions included in the query that created the result data set df.
Returns:

A dict with the dimension key as the key and the hyperlink template as the value. Templates will only be included if it will be possible to fill in the required parameters.

transform(data_frame, slicer, dimensions, references)[source]

Transforms a data frame into a format for ReactTable. This is an object containing attributes columns and data which align with the props in ReactTable with the same name.

Parameters:
  • data_frame – The result set data frame
  • slicer – The slicer that generated the data query
  • dimensions – A list of dimensions that were selected in the data query
  • references – A list of references that were selected in the data query
Returns:

An dict containing attributes columns and data which align with the props in ReactTable with the same names.

classmethod transform_data(data_frame, item_map, dimension_display_values, dimension_hyperlink_templates)[source]

Builds a list of dicts containing the data for ReactTable. This aligns with the accessors set by #transform_dimension_column_headers and #transform_metric_column_headers

Parameters:
  • data_frame – The result set data frame
  • item_map – A map to find metrics/operations based on their keys found in the data frame.
  • dimension_display_values – A map for finding display values for dimensions based on their key and value.
  • dimension_hyperlink_templates
classmethod transform_data_row_index(index_values, dimension_display_values, dimension_hyperlink_templates)[source]
classmethod transform_data_row_values(series, item_map)[source]
static transform_dimension_column_headers(data_frame, dimensions)[source]

Convert the un-pivoted dimensions into ReactTable column header definitions.

Parameters:
  • data_frame – The result set data frame
  • dimensions – A list of dimensions in the data frame that are part of the index
Returns:

A list of column header definitions with the following structure.

columns = [{
  Header: 'Column A',
  accessor: 'a',
}, {
  Header: 'Column B',
  accessor: 'b',
}]
static transform_metric_column_headers(data_frame, item_map, dimension_display_values)[source]

Convert the metrics into ReactTable column header definitions. This includes any pivoted dimensions, which will result in multiple rows of headers.

Parameters:
  • data_frame – The result set data frame
  • item_map – A map to find metrics/operations based on their keys found in the data frame.
  • dimension_display_values – A map for finding display values for dimensions based on their key and value.
Returns:

A list of column header definitions with the following structure.

columns = [{
  Header: 'Column A',
  columns: [{
    Header: 'SubColumn A.0',
    accessor: 'a.0',
  }, {
    Header: 'SubColumn A.1',
    accessor: 'a.1',
  }]
}, {
  Header: 'Column B',
  columns: [
    ...
  ]
}]
class fireant.slicer.widgets.reacttable.ReferenceItem(item, reference)[source]

Bases: object

class fireant.slicer.widgets.reacttable.TotalsItem[source]

Bases: object

key = 'totals'
label = 'Totals'
precision = None
prefix = None
suffix = None
fireant.slicer.widgets.reacttable.map_index_level(index, level, func)[source]

Module contents