Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
marcus-lodspeakr
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
uib-ub
Spesialsamlingene
marcus-lodspeakr
Commits
b5cce4d7
Commit
b5cce4d7
authored
12 years ago
by
alvaro
Browse files
Options
Downloads
Patches
Plain Diff
Adding D3CirclePacking
parent
168feace
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/Haanga/lib/Haanga/Extension/Filter/D3circlepacking.php
+136
-0
136 additions, 0 deletions
lib/Haanga/lib/Haanga/Extension/Filter/D3circlepacking.php
with
136 additions
and
0 deletions
lib/Haanga/lib/Haanga/Extension/Filter/D3circlepacking.php
0 → 100644
+
136
−
0
View file @
b5cce4d7
<?php
class
Haanga_Extension_Filter_D3CirclePacking
{
public
$is_safe
=
TRUE
;
static
function
main
(
$obj
,
$varname
){
$nodesArr
=
array
();
$n
=
0
;
$first
=
""
;
$nodes
=
array
();
$links
=
array
();
$names
=
explode
(
","
,
$varname
);
$varList
=
array
();
$randId
=
uniqid
(
"_ID_"
);
foreach
(
$names
as
$v
){
if
(
strpos
(
$v
,
"="
)){
break
;
}
$variable
[
'name'
]
=
$v
;
$variable
[
'value'
]
=
'value'
;
if
(
strpos
(
$v
,
"."
)){
$aux
=
explode
(
"."
,
$v
);
$variable
[
'name'
]
=
$aux
[
0
];
$variable
[
'value'
]
=
$aux
[
1
];
}
$fieldCounter
++
;
$columnType
=
'number'
;
if
(
$firstColumn
){
$columnType
=
'string'
;
$firstColumn
=
false
;
}
array_push
(
$varList
,
$variable
);
//$data .= " data.addColumn('".$columnType."', '".$variable['name']."');\n";
}
//options
$options
=
array
();
$options
[
'width'
]
=
960
;
$options
[
'height'
]
=
500
;
$options
[
'color'
]
=
'#aec7e8'
;
$options
[
'highlightedColor'
]
=
'#00477f'
;
$options
[
'radius'
]
=
10
;
$options
[
'highlightedStrokeWidth'
]
=
'3px'
;
$options
[
'strokeWidth'
]
=
'1px'
;
for
(
$z
=
2
;
$z
<
count
(
$names
);
$z
++
){
$pair
=
explode
(
"="
,
$names
[
$z
]);
$key
=
trim
(
$pair
[
0
],
"
\"
'"
);
$value
=
trim
(
$pair
[
1
],
"
\"
'"
);
$options
[
$key
]
=
$value
;
}
$maps
=
array
();
$quantities
=
array
();
$rootNode
=
NULL
;
$id
=
$varList
[
0
][
'name'
];
$quantity
=
$varList
[
2
][
'name'
];
$parentId
=
$varList
[
1
][
'name'
];
foreach
(
$obj
as
$k
){
if
(
!
isset
(
$k
->
$parentId
)){
//root
$rootNode
=
$k
->
$id
->
value
;
}
else
{
if
(
!
isset
(
$maps
[
$k
->
$parentId
->
value
])){
$maps
[
$k
->
$parentId
->
value
]
=
array
();
}
if
(
isset
(
$k
->
$quantity
)){
$quantities
[
$k
->
$id
->
value
]
=
$k
->
$quantity
->
value
;
}
array_push
(
$maps
[
$k
->
$parentId
->
value
],
$k
->
$id
->
value
);
}
}
function
travelCirclePacking
(
$node
,
$tree
,
$quantities
){
$total
=
array
();
foreach
(
$tree
[
$node
]
as
$v
){
$branch
=
array
();
if
(
!
isset
(
$tree
[
$v
])){
if
(
isset
(
$quantities
[
$v
])){
$branch
[
'size'
]
=
$quantities
[
$v
];
}
}
else
{
$branch
[
'children'
]
=
travelCirclePacking
(
$v
,
$tree
,
$quantities
);
}
$branch
[
'name'
]
=
$v
;
array_push
(
$total
,
$branch
);
}
return
$total
;
}
$json
[
'name'
]
=
$rootNode
;
$json
[
'children'
]
=
travelCirclePacking
(
$rootNode
,
$maps
,
$quantities
);
$pre
=
'<div id="clusterpacking'
.
$randId
.
'"><div id="name'
.
$randId
.
'" style="font-family:sans-serif;font-size:15px;height:25px"><h2> </h2></div></div><script src="http://d3js.org/d3.v2.min.js?2.9.3"></script>
<script>
// Based on http://bost.ocks.org/mike/treemap/
function initD3CirclePacking'
.
$randId
.
'(json){
var width = 960,
height = 600,
format = d3.format(",d");
var pack = d3.layout.pack()
.size([width - 4, height - 4])
.value(function(d) { return d.size; });
var vis = d3.select("#clusterpacking'
.
$randId
.
'").append("svg")
.attr("width", width)
.attr("height", height)
.attr("class", "pack")
.append("g")
.attr("transform", "translate(2, 2)");
var node = vis.data([json]).selectAll("g.node")
.data(pack.nodes)
.enter().append("g")
.attr("class", function(d) { return d.children ? "node" : "leaf node"; })
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
node.append("title")
.text(function(d) { return d.name + (d.children ? "" : ": " + format(d.size)); });
node.append("circle")
.attr("r", function(d) { return d.r; });
node.filter(function(d) { return !d.children; }).append("text")
.attr("text-anchor", "middle")
.attr("dy", ".3em")
.text(function(d) { return d.name.substring(0, d.r / 3); });
}
var jsonD3'
.
$randId
.
' = '
.
json_encode
(
$json
,
JSON_NUMERIC_CHECK
)
.
';
initD3CirclePacking'
.
$randId
.
'(jsonD3'
.
$randId
.
')
</script>'
;
return
$pre
.
$post
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment