Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
unify version color function
Browse files Browse the repository at this point in the history
  • Loading branch information
shekenahglory committed Dec 21, 2016
1 parent e51920c commit 2718dfe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
26 changes: 15 additions & 11 deletions src/app/topology/topology.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ angular.module('ripplecharts.topology', [
var t = new Topology($http)
var m = new TopologyMap($http)

function versionToColor(stable, version) {
var v = version.split('-')[1]
var s = stable ? stable.split('-')[0] : ''
var comp = v && s ? $scope.semverCompare(v, s) : ''
function versionToColor(d) {
var version = d.replace('rippled-', '')
var comp

if (!v || !stable) {
if (!$scope.stable || !$scope.semverCompare) {
return 'grey'
}

comp = $scope.semverCompare(version, $scope.stable)

} else if (comp === -1) {
if (comp === -1) {
return '#c11'

} else if (comp === 1) {
Expand All @@ -51,12 +53,12 @@ angular.module('ripplecharts.topology', [
function updateVersionColors() {
if ($scope.nodes) {
$scope.nodes.forEach(function(d) {
d.new.version_color = versionToColor($scope.stable, d.new.version)
d.new.version_color = versionToColor(d.new.version)
})
}

t.color(versionToColor.bind(t, $scope.stable))
m.color(versionToColor.bind(m, $scope.stable))
t.color(versionToColor)
m.color(versionToColor)
}

function updateVersionGraph(nodes) {
Expand Down Expand Up @@ -192,7 +194,7 @@ angular.module('ripplecharts.topology', [
])
t.update(data)
t.weight(store.get('weight-mode'))
t.color(versionToColor.bind(m, $scope.stable))
t.color(versionToColor)

} else {
console.log('no nodes')
Expand All @@ -217,7 +219,7 @@ angular.module('ripplecharts.topology', [

m.populate(data.nodes)
m.weight(store.get('weight-mode'))
m.color(versionToColor.bind(m, $scope.stable))
m.color(versionToColor)

}).catch(function(e) {
console.log(e)
Expand All @@ -240,6 +242,8 @@ angular.module('ripplecharts.topology', [
fetchAndShowTable(true)
fetchAndShowMap(true)

$scope.color = versionToColor

// click to toggle between charts
$('.switch-input').click(function() {
$('.first').fadeOut(500, function() {
Expand Down
20 changes: 1 addition & 19 deletions src/common/versionsGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,7 @@ angular.module('versionsGraph', [])
tooltip.append('div')
.attr('class', 'uptime')

function versionToColor(version) {
var comp

if (!$scope.stable || !$scope.semverCompare) {
return 'grey'
}

comp = $scope.semverCompare(version, $scope.stable)

if (comp === -1) {
return '#c11'

} else if (comp === 1) {
return '#36c'

} else {
return '#3a3'
}
}
var versionToColor = $scope.color || function() {}

function hideTooltip() {
tooltip.transition()
Expand Down

0 comments on commit 2718dfe

Please sign in to comment.