diff --git a/viz/index.js b/viz/index.js index 743c302..7b97e8f 100644 --- a/viz/index.js +++ b/viz/index.js @@ -15,6 +15,26 @@ main = function($scope, $timeout, $interval){ $scope.curdis = $scope.diseases[0]; $scope.playing = false; $scope.yearIndex = 0; + $scope.getDataBoundary = function(cancerType){ + var year, ts, d, v; + $scope.maxBound = d3.max([d3.max((function(){ + var ref$, results$ = []; + for (year in ref$ = cancer.data) { + ts = ref$[year]; + results$.push(d3.max((fn$()))); + } + return results$; + function fn$(){ + var ref$, results$ = []; + for (d in ref$ = ts[cancerType]) { + v = ref$[d]; + results$.push(v); + } + return results$; + } + }()))]); + $scope.minBound = 0; + }; $scope.stop = function(){ if ($scope.playing) { $interval.cancel($scope.playing); @@ -60,6 +80,7 @@ main = function($scope, $timeout, $interval){ return $scope.updateData(); }); $scope.$watch('curdis', function(){ + $scope.getDataBoundary($scope.curdis); return $scope.updateData(); }); return d3.json('rpi.json', function(rpi){ @@ -107,16 +128,12 @@ main = function($scope, $timeout, $interval){ ? it.properties.nvalue : it.properties.value; if (v && (min === -1 || min > v)) { - return min = v; - } - }); - max = d3.max(map.topo.features, function(it){ - if ($scope.normalize) { - return it.properties.nvalue; - } else { - return it.properties.value; + min = v; } + return it.properties.value = v || 0; }); + max = $scope.maxBound; + min = min > 1 ? min : 1; if (min <= 0) { min = 0.0001; } diff --git a/viz/index.ls b/viz/index.ls index c4dd167..7671c1f 100644 --- a/viz/index.ls +++ b/viz/index.ls @@ -8,6 +8,10 @@ main = ($scope, $timeout, $interval) -> $scope.curdis = $scope.diseases.0 $scope.playing = false $scope.year-index = 0 + + $scope.get-data-boundary = (cancer-type) !-> + $scope.max-bound = d3.max [d3.max [d3.max [v for d,v of ts[cancer-type]] for year, ts of cancer.data]] + $scope.min-bound = 0 $scope.stop = -> if $scope.playing => $interval.cancel $scope.playing $scope.playing = false @@ -32,7 +36,9 @@ main = ($scope, $timeout, $interval) -> data = $scope.cancer-data $scope.map $scope.update-map $scope.map, data $scope.$watch 'curyear', -> $scope.update-data! - $scope.$watch 'curdis', -> $scope.update-data! + $scope.$watch 'curdis', -> + $scope.get-data-boundary $scope.curdis + $scope.update-data! (rpi) <- d3.json \rpi.json $scope.$watch 'chosen' -> $scope.chosen-value = $scope.hash[$scope.chosen] $scope.$watch 'chosen' -> $scope.chosen-value = $scope.hash[$scope.chosen] @@ -60,9 +66,13 @@ main = ($scope, $timeout, $interval) -> it.properties.nvalue = if p => parseInt(100000 * v / p)/1000 else 0 v = if $scope.normalize => it.properties.nvalue else it.properties.value if v and (min == -1 or min > v) => min := v + it.properties.value = v or 0 #if popu[mgyear] => console.log popu[mgyear][c][t], v, p, it.properties.nvalue - max = d3.max(map.topo.features, (-> if $scope.normalize => it.properties.nvalue else it.properties.value)) #>? 0.2 #min = min >? 0.2 if $scope.normalize => it.properties.nvalue else it.properties.value)) #>? 0.2 + max = $scope.max-bound + min = min >? 1 if min <=0 => min = 0.0001 if max <=0 => max = 0.2 map.heatmap = d3.scale.linear!domain [0, min, (min*2 + max)/2, max] .range map.heatrange