Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
MUR Drupal
d3_sankey
Commits
987e7ca3
Commit
987e7ca3
authored
Sep 22, 2016
by
M Parker
Browse files
Add a tablefield formatter that displays a Sankey diagram.
parent
7385134a
Changes
1
Hide whitespace changes
Inline
Side-by-side
modules/d3_sankey_table_group_pp/d3_sankey_table_group_pp.module
View file @
987e7ca3
...
...
@@ -5,6 +5,8 @@
* Hooks and helper functions for the d3_sankey_table_group_pp module.
*/
use
Drupal\d3_sankey_table_group_pp
\
TableGroupingPreprocessor
;
/* Hooks. */
/**
...
...
@@ -13,3 +15,50 @@
function
d3_sankey_table_group_pp_xautoload
(
$adapter
)
{
$adapter
->
absolute
()
->
addPsr4
(
'Drupal\d3_sankey_table_group_pp'
,
'src'
);
}
/**
* Implements hook_field_formatter_info().
*/
function
d3_sankey_table_group_pp_field_formatter_info
()
{
$formatters
=
array
();
// A field formatter for tablefields, which displays a Sankey diagram using
// the table grouping preprocessor.
$formatters
[
'tablefield_d3_sankey_table_group_pp'
]
=
array
(
'label'
=>
t
(
'Sankey diagram (table grouping preprocessor)'
),
'field types'
=>
array
(
'tablefield'
),
);
return
$formatters
;
}
/**
* Implements hook_field_formatter_view().
*/
function
d3_sankey_table_group_pp_field_formatter_view
(
$entity_type
,
$entity
,
$field
,
$instance
,
$langcode
,
$items
,
$display
)
{
$element
=
array
();
// A field formatter for tablefields, which displays a Sankey diagram using
// the table grouping preprocessor.
if
(
$display
[
'type'
]
===
'tablefield_d3_sankey_table_group_pp'
)
{
foreach
(
$items
as
$delta
=>
$item
)
{
$chart
=
_uw_career_common_chart_options
();
// Initialize a GroupingPreprocessor, feed it the query results, get the
// raw data out of the preprocessor, and add it to the chart.
$preprocessor
=
new
TableGroupingPreprocessor
();
foreach
(
$item
[
'tabledata'
]
as
$row
)
{
$preprocessor
->
ingestRow
((
array
)
$row
);
}
$raw_data
=
$preprocessor
->
getRawData
();
$chart
[
'nodes'
]
=
$raw_data
->
getAssocArrayNodes
();
$chart
[
'links'
]
=
$raw_data
->
getAssocArrayLinks
();
// Now draw the chart.
$chart
=
d3_draw
(
$chart
);
$element
[
$delta
][
'#markup'
]
=
$chart
;
}
}
return
$element
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment