Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
MUR Drupal
d3_sankey
Commits
7385134a
Commit
7385134a
authored
Aug 19, 2016
by
M Parker
Browse files
Add an example to demonstrate the table grouping preprocessor.
parent
8813bbcc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
0 deletions
+63
-0
modules/d3_sankey_examples/d3_sankey_examples.module
modules/d3_sankey_examples/d3_sankey_examples.module
+63
-0
No files found.
modules/d3_sankey_examples/d3_sankey_examples.module
View file @
7385134a
...
...
@@ -36,6 +36,21 @@ function d3_sankey_examples_menu() {
'weight'
=>
-
1
,
)
+
$items
[
'd3/examples/sankey'
];
// Uses d3_sankey_table_group_pp to create a Sankey chart.
if
(
module_exists
(
'd3_sankey_table_group_pp'
))
{
$items
[
'd3/examples/sankey/table_group_preprocess'
]
=
array
(
'title'
=>
'Table grouping preprocessor'
,
'description'
=>
'Creates a Sankey chart using a preprocessor that links values in the same row, grouping duplicates.'
,
// For consistency with d3_examples, this has no access restriction (i.e.:
// an open page callback). Note that in this module's implementation of
// hook_requirements() (in d3_sankey_examples.install), we remind users to
// disable this module on the live site.
'access callback'
=>
TRUE
,
'page callback'
=>
'_d3_sankey_examples_table_group_pp'
,
'type'
=>
MENU_LOCAL_TASK
,
);
}
return
$items
;
}
...
...
@@ -174,3 +189,51 @@ function _d3_sankey_examples_sankey() {
return
d3_draw
(
$chart
);
}
/**
* Menu callback: Uses d3_sankey_table_group_pp to create a Sankey chart.
*/
function
_d3_sankey_examples_table_group_pp
()
{
$chart
=
array
(
'type'
=>
'sankey'
,
// See _d3_sankey_examples_sankey() for an explanation of these properties.
'id'
=>
'visualization'
,
'sankeyType'
=>
D3_SANKEY_SANKEYTYPE_PATH
,
'width'
=>
'700'
,
'height'
=>
'400'
,
'nodeWidth'
=>
24
,
'nodePadding'
=>
8
,
'spread'
=>
TRUE
,
'iterations'
=>
1
,
'alignLabel'
=>
D3_SANKEY_ALIGNLABEL_AUTO
,
);
// Create some sample data.
$unprocessed_data
=
array
(
array
(
'1970s'
,
'Drama'
,
'The Godfather'
),
array
(
'1970s'
,
'Sci-fi/Fantasy'
,
'Star Wars'
),
array
(
'1980s'
,
'Sci-fi/Fantasy'
,
'The Empire Strikes Back'
),
array
(
'1990s'
,
'Drama'
,
'The Shawshank Redemption'
),
array
(
'1990s'
,
'Biography'
,
"Schindler's List"
),
array
(
'2000s'
,
'Action'
,
'The Dark Knight'
),
array
(
'2000s'
,
'Sci-fi/Fantasy'
,
'LotR: Return of the King'
),
);
// Initialize a GroupingPreprocessor.
$preprocessor
=
new
\
Drupal\d3_sankey_table_group_pp\TableGroupingPreprocessor
();
// Feed the preprocessor the sample data.
foreach
(
$unprocessed_data
as
$row
)
{
$preprocessor
->
ingestRow
(
$row
);
}
// Get an object containing the raw chart data out of the preprocessor.
$raw_data
=
$preprocessor
->
getRawData
();
// Add the nodes and links to the chart.
$chart
[
'nodes'
]
=
$raw_data
->
getAssocArrayNodes
();
$chart
[
'links'
]
=
$raw_data
->
getAssocArrayLinks
();
return
d3_draw
(
$chart
);
}
Write
Preview
Markdown
is supported
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