diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2008-12-10 12:34:44 +0000 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2010-09-30 07:09:14 +0000 |
commit | 0adc554ba6925144bab4bcd29fd2371a032cb458 (patch) | |
tree | aeecf3ac4832e7dbecc8a5f69f8990ffb7ea1074 /Cydia.app/storage.js | |
parent | 59c011d87e67a2b7a44bf70576c7fa10e85698bc (diff) |
Finished implementing Storage.
Diffstat (limited to 'Cydia.app/storage.js')
-rw-r--r-- | Cydia.app/storage.js | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/Cydia.app/storage.js b/Cydia.app/storage.js index 926a61d..02dc51b 100644 --- a/Cydia.app/storage.js +++ b/Cydia.app/storage.js @@ -9,6 +9,29 @@ var list = function (legend, color, name, value) { 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); @@ -28,16 +51,26 @@ var setup = function (name, root, folders) { 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]); }; |