-
Notifications
You must be signed in to change notification settings - Fork 9
/
GroupLabel.js
47 lines (45 loc) · 1.29 KB
/
GroupLabel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/** @module dtreemap/GroupLabel */
define(["dcl/dcl", "requirejs-dplugins/css!./themes/GroupLabel.css"],
function (dcl) {
/**
* Mixin that specializes TreeMap to remove leaf labels and display group labels centered on group
* content instead of display them in headers.
* @mixin module:dtreemap/GroupLabel
*/
return dcl(null, /** @lends module:dtreemap/GroupLabel# */ {
createRenderer: dcl.superCall(function (sup) {
return function (item, level, kind) {
var renderer = sup.call(this, item, level, kind);
if (kind === "content" || kind === "leaf") {
var p = this.ownerDocument.createElement("div");
dcl.mix(p.style, {
"zIndex": 30,
"position": "relative",
"height": "100%",
"textAlign": "center",
"top": "50%",
"marginTop": "-.5em"
});
renderer.appendChild(p);
}
return renderer;
};
}),
styleRenderer: function (renderer, item, level, kind) {
switch (kind) {
case "leaf":
renderer.style.background = this.getColorForItem(item).toHex();
/* falls through */
case "content":
if (level === 0) {
renderer.firstChild.innerHTML = this.getLabelForItem(item);
} else {
renderer.firstChild.innerHTML = "";
}
break;
case "header":
renderer.style.display = "none";
}
}
});
});