From a46006ba64fd3c8417a3310c9dc0c6d4244f69d4 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 29 Sep 2014 03:43:55 -0400 Subject: [PATCH] cleanup --- public/src/forum/admin/general/dashboard.js | 78 ++++++++++++--------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/public/src/forum/admin/general/dashboard.js b/public/src/forum/admin/general/dashboard.js index 4fc1be28cb..deb29e6aea 100644 --- a/public/src/forum/admin/general/dashboard.js +++ b/public/src/forum/admin/general/dashboard.js @@ -307,55 +307,65 @@ define('forum/admin/general/dashboard', ['semver'], function(semver) { } function updateTopicsGraph(topics) { - var tids = Object.keys(topics); + var tids = Object.keys(topics), + segments = graphs.topics.segments; - var segments = graphs.topics.segments; + function reassignExistingTopics() { + for (var i = 0, ii = segments.length; i < ii; i++ ) { + var tid = segments[i].tid; - for (var i = 0, ii = segments.length; i < ii; i++ ){ - var tid = segments[i].tid; - - if ($.inArray(tid, tids) === -1) { - usedTopicColors.splice($.inArray(segments[i].color, usedTopicColors), 1); - graphs.topics.removeData(i); - } else { - graphs.topics.segments[i].value = topics[tid]; - delete topics[tid]; + if ($.inArray(tid, tids) === -1) { + usedTopicColors.splice($.inArray(segments[i].color, usedTopicColors), 1); + graphs.topics.removeData(i); + } else { + graphs.topics.segments[i].value = topics[tid]; + delete topics[tid]; + } } } - while (segments.length < 10 && tids.length > 0) { - var tid = tids.pop(), - value = topics[tid], - color = null; + function assignNewTopics() { + while (segments.length < 10 && tids.length > 0) { + var tid = tids.pop(), + value = topics[tid], + color = null; - if (!value) { - continue; - } + if (!value) { + continue; + } - do { - for (var i = 0, ii = topicColors.length; i < ii; i++) { - var chosenColor = topicColors[i]; + do { + for (var i = 0, ii = topicColors.length; i < ii; i++) { + var chosenColor = topicColors[i]; - if ($.inArray(chosenColor, usedTopicColors) === -1) { - color = chosenColor; - usedTopicColors.push(color); - break; + if ($.inArray(chosenColor, usedTopicColors) === -1) { + color = chosenColor; + usedTopicColors.push(color); + break; + } } - } - } while (color !== null && usedTopicColors.length === topicColors.length); + } while (color !== null && usedTopicColors.length === topicColors.length); - graphs.topics.addData({ - value: tid, - color: color, - highlight: lighten(color, 10), - label: "tid " + value - }); + graphs.topics.addData({ + value: tid, + color: color, + highlight: lighten(color, 10), + label: "tid " + value + }); - segments[segments.length - 1].tid = tid; + segments[segments.length - 1].tid = tid; + } } + reassignExistingTopics(); + assignNewTopics(); + graphs.topics.update(); } + function buildTopicsLegend() { + + } + return Admin; });