Commit 8f0ee093 authored by M Parker's avatar M Parker

Add option to avoid ingesting rows with empty data.

This can prevent infinite recursion on the front-end as of
d3.chart.sankey version 0.2.1.
parent efb62290
......@@ -38,6 +38,7 @@ function d3_sankey_table_group_pp_field_formatter_info() {
'alignLabel' => D3_SANKEY_ALIGNLABEL_AUTO,
'node_colors' => '',
'link_colors' => '',
'skip_rows_with_empty_data' => FALSE,
),
);
......@@ -137,6 +138,14 @@ function d3_sankey_table_group_pp_field_formatter_settings_form($field, $instanc
'#default_value' => $settings['link_colors'],
'#element_validate' => array('d3_sankey_element_validate_optional_color_list'),
);
// Whether to not to skip rows with empty data.
$element['skip_rows_with_empty_data'] = array(
'#type' => 'checkbox',
'#title' => t('Skip rows with empty data'),
'#description' => t("Empty data causes infinite recursion as of d3.chart.sankey version 0.2.1. Enabling this option checks whether there is any empty data in a row, and if so, does not output it. Skipping data makes the chart less accurate, but avoids crashing the end-user's browser."),
'#default_value' => $settings['skip_rows_with_empty_data'],
);
}
return $element;
......@@ -212,6 +221,11 @@ function d3_sankey_table_group_pp_field_formatter_settings_summary($field, $inst
'%colors' => implode(', ', $link_colors),
));
}
// Display whether we're skipping rows with empty data.
if ((bool) $settings['skip_rows_with_empty_data'] === TRUE) {
$summary .= ' ' . t('Skipping rows with empty data.');
}
}
return $summary;
......@@ -276,6 +290,19 @@ function d3_sankey_table_group_pp_field_formatter_view($entity_type, $entity, $f
// raw data out of the preprocessor, and add it to the chart.
$preprocessor = new TableGroupingPreprocessor();
foreach ($rows as $row) {
// If we've been asked to skip rows with empty data, search the columns
// in the current row for empty data.
if ((bool) $settings['skip_rows_with_empty_data'] === TRUE) {
foreach ($row as $column) {
if (empty($column)) {
// We are currently in 2 foreach loops; the inner one for the
// column, and the outer one for the row. We want to skip
// processing the current row iteration.
continue 2;
}
}
}
$preprocessor->ingestRow((array) $row);
}
$raw_data = $preprocessor->getRawData();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment