def _get_graph_fields(): from corehq.apps.userreports.reports.specs import MultibarChartSpec from corehq.apps.app_manager.models import GraphConfiguration, GraphSeries def _locale_config(key): return id_strings.mobile_ucr_configuration( module, config.uuid, key ) def _locale_series_config(index, key): return id_strings.mobile_ucr_series_configuration( module, config.uuid, index, key ) def _locale_annotation(index): return id_strings.mobile_ucr_annotation( module, config.uuid, index ) for chart_config in config.report(domain).charts: if isinstance(chart_config, MultibarChartSpec): graph_config = config.complete_graph_configs.get(chart_config.chart_id, GraphConfiguration( series=[GraphSeries() for c in chart_config.y_axis_columns], )) # Reconcile graph_config.series with any additions/deletions in chart_config.y_axis_columns while len(chart_config.y_axis_columns) > len(graph_config.series): graph_config.series.append(GraphSeries()) if len(chart_config.y_axis_columns) < len(graph_config.series): graph_config.series = graph_config.series[:len(chart_config.y_axis_columns)] for index, column in enumerate(chart_config.y_axis_columns): graph_config.series[index].data_path = ( graph_config.series[index].data_path or get_data_path(config, domain, new_mobile_ucr_restore) ) graph_config.series[index].x_function = ( graph_config.series[index].x_function or _get_column_xpath_template(new_mobile_ucr_restore).format(chart_config.x_axis_column) ) graph_config.series[index].y_function = ( graph_config.series[index].y_function or _get_column_xpath_template(new_mobile_ucr_restore).format(column.column_id) ) yield Field( header=Header(text=Text()), template=GraphTemplate.build('graph', graph_config, locale_config=_locale_config, locale_series_config=_locale_series_config, locale_annotation=_locale_annotation) )
def _get_graph_fields(): from corehq.apps.userreports.reports.specs import MultibarChartSpec # todo: make this less hard-coded for chart_config in config.report(domain).charts: if isinstance(chart_config, MultibarChartSpec): graph_config = config.graph_configs.get( chart_config.chart_id, ReportGraphConfig()) def _column_to_series(column): return Series(nodeset=( "instance('reports')/reports/report[@id='{}']/rows/row[@is_total_row='False']{}" .format( config.uuid, _MobileSelectFilterHelpers.get_data_filter_xpath( config, domain))), x_function="column[@id='{}']".format( chart_config.x_axis_column), y_function="column[@id='{}']".format(column), configuration=ConfigurationGroup(configs=[ ConfigurationItem(id=key, xpath_function=value) for key, value in graph_config. series_configs.get(column, {}).items() ])) yield Field( header=Header(text=Text()), template=GraphTemplate( form='graph', graph=Graph( type=graph_config.graph_type, series=[ _column_to_series(c.column_id) for c in chart_config.y_axis_columns ], configuration=ConfigurationGroup(configs=[ ConfigurationItem(id=key, xpath_function=value) for key, value in graph_config.config.items() ]), ), ))
def _get_graph_fields(): from corehq.apps.userreports.reports.specs import MultibarChartSpec from corehq.apps.app_manager.models import GraphConfiguration, GraphSeries def _locale_config(key): return id_strings.mobile_ucr_configuration(module, config.uuid, key) def _locale_series_config(index, key): return id_strings.mobile_ucr_series_configuration( module, config.uuid, index, key) def _locale_annotation(index): return id_strings.mobile_ucr_annotation(module, config.uuid, index) for chart_config in config.report(domain).charts: if isinstance(chart_config, MultibarChartSpec): graph_config = config.complete_graph_configs.get( chart_config.chart_id, GraphConfiguration(series=[ GraphSeries() for c in chart_config.y_axis_columns ], )) for index, column in enumerate(chart_config.y_axis_columns): graph_config.series[index].data_path = ( graph_config.series[index].data_path or get_data_path(config, domain)) graph_config.series[index].x_function = ( graph_config.series[index].x_function or COLUMN_XPATH_TEMPLATE.format( chart_config.x_axis_column)) graph_config.series[index].y_function = ( graph_config.series[index].y_function or COLUMN_XPATH_TEMPLATE.format(column.column_id)) yield Field(header=Header(text=Text()), template=GraphTemplate.build( 'graph', graph_config, locale_config=_locale_config, locale_series_config=_locale_series_config, locale_annotation=_locale_annotation))