}
piechart > div {
+ -webkit-border-radius: 50px;
height: 100px;
- padding: 1px;
+ overflow: hidden;
position: relative;
- width: 103px;
+ width: 100px;
}
- piechart > div > div.lslice,
- piechart > div > div.rslice {
- background-color: #4d4d70;
+ piechart > div > div:first-child {
height: 100px;
+ overflow: hidden;
position: absolute;
+ z-index: 102;
+ width: 51px;
}
- piechart > div > div.lslice {
- -webkit-border-bottom-left-radius: 50px;
- -webkit-border-top-left-radius: 50px;
- width: 50px;
- z-index: 2;
+ piechart > div > div:last-child {
+ height: 100px;
+ overflow: hidden;
+ position: absolute;
+ width: 100px;
+ z-index: 0;
}
- piechart > div > div.rslice {
- -webkit-border-bottom-right-radius: 50px;
- -webkit-border-top-right-radius: 50px;
- left: 49px;
- width: 53px;
- z-index: 0;
+ piechart > div div.lslice,
+ piechart > div div.rslice,
+ piechart > div div.tslice,
+ piechart > div div.bslice {
+ background-color: #4d4d70;
}
- piechart > div > div.xslice {
+ piechart > div div.lslice,
+ piechart > div div.rslice,
+ piechart > div div.tslice,
+ piechart > div div.bslice,
+ piechart > div div.xslice {
+ /* XXX: technically, these aren't needed */
-webkit-border-bottom-left-radius: 50px;
-webkit-border-top-left-radius: 50px;
height: 100px;
- left: 2px;
position: absolute;
- -webkit-transform-origin: 50px 50%;
+ -webkit-transform-origin: 100% 50%;
width: 50px;
}
- piechart > div > div.tslice {
+ piechart > div div.lslice {
+ z-index: 100;
+ }
+
+ piechart > div div.rslice,
+ piechart > div div.tslice,
+ piechart > div div.bslice {
+ z-index: 0;
+ }
+
+ piechart > div div.rslice {
+ -webkit-transform: rotate(180deg);
+ }
+
+ piechart > div div.tslice {
+ -webkit-transform: rotate(90deg);
+ }
+
+ piechart > div div.bslice {
+ -webkit-transform: rotate(270deg);
+ }
+
+ piechart > div > div.nslice {
position: absolute;
text-align: center;
top: 42px;
width: 100px;
- z-index: 3;
+ z-index: 103;
}
- piechart > div > div.tslice > div {
+ piechart > div > div.nslice > div {
background-color: rgba(255, 255, 255, 0.7);
-webkit-border-radius: 7px;
display: inline;
<a class="giant-button">
<div class="contents">
- <piechart id="system-chart"><div>
- <div class="lslice"></div>
- <div class="rslice"></div>
- <div class="tslice"><div id="system-size"></div></div>
- <div class="xslice" id="system-slice" style="
- background-color: #7d7da0; -webkit-transform: rotate(10deg); z-index: 1;
- "></div>
+ <piechart><div>
+ <div id="system-left"></div>
+ <div id="system-right">
+ <div class="lslice"></div>
+ <div class="rslice"></div>
+ <div class="tslice"></div>
+ <div class="bslice"></div>
+ </div>
+ <div class="nslice"><div id="system-size"></div></div>
</div></piechart>
<label>System</label>
<a class="giant-button">
<div class="contents">
- <piechart id="private-chart"><div>
- <div class="lslice"></div>
- <div class="rslice"></div>
- <div class="tslice"><div id="private-size"></div></div>
- <div class="xslice" id="private-slice" style="
- background-color: #9090e0; -webkit-transform: rotate(150deg); z-index: 1;
- "></div>
- <div class="xslice" id="private-slice" style="
- background-color: #7070e0; -webkit-transform: rotate(120deg); z-index: 1;
- "></div>
- <div class="xslice" id="private-slice" style="
- background-color: #d0d0f0; -webkit-transform: rotate(90deg); z-index: 1;
- "></div>
- <div class="xslice" id="private-slice" style="
- background-color: #7da0e0; -webkit-transform: rotate(60deg); z-index: 1;
- "></div>
- <div class="xslice" id="private-slice" style="
- background-color: #7d7da0; -webkit-transform: rotate(30deg); z-index: 1;
- "></div>
+ <piechart><div>
+ <div id="private-left"></div>
+ <div id="private-right">
+ <div class="lslice"></div>
+ <div class="rslice"></div>
+ <div class="tslice"></div>
+ <div class="bslice"></div>
+ </div>
+ <div class="nslice"><div id="private-size"></div></div>
</div></piechart>
<label>Private</label>
console.log(cydia.statfs("/"));
+var cut = function (parent, color, fraction, z) {
+ var deg = Math.round(360 * fraction);
+ if (deg < 2)
+ deg = 2;
+ parent.append('<div class="xslice" style="' +
+ 'background-color: ' + color + ';' +
+ '-webkit-transform: rotate(' + deg + 'deg);' +
+ 'z-index: ' + z + ';' +
+ '"></div>');
+};
+
+var chart = function (right, left, slices) {
+ var total = 0;
+ for (var i = 0; i != slices.length; ++i) {
+ var slice = slices[i];
+ var z = slices.length - i;
+ if (slice[1] > 0.5)
+ cut(right, slice[0], total + 0.5, z);
+ total += slice[1];
+ cut(total > 0.5 ? left : right, slice[0], total, z);
+ }
+};
+
var setup = function (name, root, folders) {
var size = $("#" + name + "-size");
var statfs = cydia.statfs(root);
var legend = $("#" + name + "-legend");
var used = 0;
+ var slices = [];
+
if (folders != null)
for (var i = 0; i != folders.length; ++i) {
var folder = folders[i];
var usage = cydia.du(folder[1]);
- list(legend, colors[i + 2], folder[0], usage / kb);
- total += usage;
+ var color = colors[i + 2];
+ var percent = usage / kb;
+ list(legend, color, folder[0], percent);
+ slices.push([color, percent]);
+ used += usage;
}
var free = statfs[0] * statfs[2] / 1024;
- list(legend, colors[0], folders == null ? "Used" : "Other", (kb - free - total) / kb);
+ var other = (kb - free - used) / kb;
+
+ slices.push([colors[0], other]);
+ chart($("#" + name + "-right"), $("#" + name + "-left"), slices);
+
+ list(legend, colors[0], folders == null ? "Used" : "Other", other);
list(legend, colors[1], "Free", statfs[2] / statfs[1]);
};
- (NSNumber *) du:(NSString *)path {
NSNumber *value(nil);
- /* XXX: omfg this is stupid */
- if (FILE *du = popen([[@"du -s " stringByAppendingString:path] UTF8String], "r")) {
+ int fds[2];
+ _assert(pipe(fds) != -1);
+
+ pid_t pid(ExecFork());
+ if (pid == 0) {
+ _assert(dup2(fds[1], 1) != -1);
+ _assert(close(fds[0]) != -1);
+ _assert(close(fds[1]) != -1);
+ execlp("du", "du", "-s", [path UTF8String], NULL);
+ exit(1);
+ _assert(false);
+ }
+
+ _assert(close(fds[1]) != -1);
+
+ if (FILE *du = fdopen(fds[0], "r")) {
char line[1024];
while (fgets(line, sizeof(line), du) != NULL) {
size_t length(strlen(line));
}
}
- pclose(du);
- }
+ fclose(du);
+ } else _assert(close(fds[0]));
+
+ int status;
+ wait:
+ if (waitpid(pid, &status, 0) == -1)
+ if (errno == EINTR)
+ goto wait;
+ else _assert(false);
return value;
}