Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented a new configurable color scheme #15

Merged
merged 1 commit into from
Jan 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions assets/js/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,56 +28,3 @@ app.config ['$routeProvider', '$locationProvider', ($routeProvider, $locationPro
]
app.constant 'apiUri', '/api/'
app.constant 'socketUri', "ws://#{window.location.host}/socket"
app.constant 'chartTemplates',
lineChart:
options:
chart:
type: 'lineChart'
x: (data) -> data.x
y: (data) -> data.y
valueFormat: d3.format '.2e'
xAxis:
tickFormat: d3.format '.2e'
yAxis:
tickFormat: d3.format '.2e'
margin:
top: 20
right: 20
bottom: 45
left: 60
historicalBarChart:
options:
chart:
type: 'historicalBarChart'
x: (data) ->
return (data.range[0] + data.range[1]) / 2
y: (data) ->
return data.count
valueFormat: d3.format '.2e'
xAxis:
axisLabel: 'Value'
tickFormat: d3.format '.2e'
yAxis:
axisLabel: 'Count'
tickFormat: d3.format '.2e'
margin:
top: 20
right: 20
bottom: 45
left: 60
multiBarChart:
options:
chart:
type: 'multiBarChart'
x: (data) -> data.x
y: (data) -> data.y
valueFormat: d3.format '.2e'
xAxis:
tickFormat: d3.format '.2e'
yAxis:
tickFormat: d3.format '.2e'
margin:
top: 50
right: 20
bottom: 45
left: 60
58 changes: 58 additions & 0 deletions assets/js/chartTemplates.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
app.constant 'chartColors',
defaultColor: '#90A4AE'
targetColor: '#4CAF50'
selectionColor1: '#FFB74D'
selectionColor2: '#FF5722'
app.constant 'chartTemplates',
lineChart:
options:
chart:
type: 'lineChart'
x: (data) -> data.x
y: (data) -> data.y
valueFormat: d3.format '.2e'
xAxis:
tickFormat: d3.format '.2e'
yAxis:
tickFormat: d3.format '.2e'
margin:
top: 20
right: 20
bottom: 45
left: 60
historicalBarChart:
options:
chart:
type: 'historicalBarChart'
x: (data) ->
return (data.range[0] + data.range[1]) / 2
y: (data) ->
return data.count
valueFormat: d3.format '.2e'
xAxis:
axisLabel: 'Value'
tickFormat: d3.format '.2e'
yAxis:
axisLabel: 'Count'
tickFormat: d3.format '.2e'
margin:
top: 20
right: 20
bottom: 45
left: 60
multiBarChart:
options:
chart:
type: 'multiBarChart'
x: (data) -> data.x
y: (data) -> data.y
valueFormat: d3.format '.2e'
xAxis:
tickFormat: d3.format '.2e'
yAxis:
tickFormat: d3.format '.2e'
margin:
top: 50
right: 20
bottom: 45
left: 60
37 changes: 31 additions & 6 deletions assets/js/controllers/FeatureInfoCtrl.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
app.controller 'FeatureInfoCtrl', ['$scope', '$routeParams', '$timeout', '$http', 'apiUri', 'chartTemplates',\
($scope, $routeParams, $timeout, $http, apiUri, chartTemplates) ->
app.controller 'FeatureInfoCtrl', ['$scope', '$routeParams', '$timeout', '$http', 'apiUri', 'chartTemplates', 'chartColors',\
($scope, $routeParams, $timeout, $http, apiUri, chartTemplates, chartColors) ->

retrieveSelectedFeature = (features) ->
featurePredicate = (feature) -> feature.name == $routeParams.featureName
Expand Down Expand Up @@ -119,6 +119,7 @@ app.controller 'FeatureInfoCtrl', ['$scope', '$routeParams', '$timeout', '$http'
{
values: $scope.feature.samples or []
key: $scope.feature.name
color: chartColors.defaultColor
}
]
$scope.histogram = angular.merge {}, chartTemplates.historicalBarChart,
Expand All @@ -138,18 +139,42 @@ app.controller 'FeatureInfoCtrl', ['$scope', '$routeParams', '$timeout', '$http'
renderEnd: ->
element = $scope.histogramApi.getElement()
svg = d3.select element[0]

slicesContained = (d) ->
return $scope.feature.slices.filter (slice) ->
return slice.range[0] < d.range[1] and
slice.range[1] > d.range[0]

buckets = $scope.histogram.data[0].values
bucketSignificances = buckets.map (bucket) ->
slices = slicesContained bucket
if slices.length == 0
return null
sliceSignificances = slices.map (slice) -> slice.significance
return sliceSignificances.mean()

filteredSignificances = bucketSignificances.filter (b) -> b?
minSignificance = Math.min.apply null, filteredSignificances
maxSignificance = Math.max.apply null, filteredSignificances

svg.selectAll 'rect.nv-bar'
.classed 'selected', (d) ->
return d.range == $scope.selectedRange
.classed 'significant', (d) ->
containedSlices = $scope.feature.slices.filter (slice) ->
return slice.range[0] < d.range[1] and
slice.range[1] > d.range[0]
return containedSlices.length > 0
return slicesContained(d).length > 0
.attr 'significance', (d, i) ->
significance = bucketSignificances[i]
if not significance?
return 0
scaledSignificance = (significance - minSignificance) /
(maxSignificance - minSignificance)
significanceLevel = Math.ceil(scaledSignificance * 10) * 10
return significanceLevel
data: [
{
values: mergeBucketsSqrt $scope.feature.buckets
key: $scope.feature.name
color: chartColors.defaultColor
}
]

Expand Down
7 changes: 4 additions & 3 deletions assets/js/directives/FeatureSliceVisualizer.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
app.directive 'featureSliceVisualizer', ['$timeout', 'chartTemplates', ($timeout, chartTemplates) ->
app.directive 'featureSliceVisualizer', ['$timeout', 'chartTemplates', 'chartColors',\
($timeout, chartTemplates, chartColors) ->
return {
restrict: 'E'
template: JST['assets/templates/featureSliceVisualizer']
Expand Down Expand Up @@ -33,12 +34,12 @@ app.directive 'featureSliceVisualizer', ['$timeout', 'chartTemplates', ($timeout
values: []
key: 'Marginal probability distribution'
area: true
color: 'rgb(31, 119, 180)'
color: chartColors.targetColor
conditionalProbDistr =
values: []
key: 'Conditional probability distribution'
area: true
color: '#F44336'
color: chartColors.selectionColor2
scope.probabilityDistributions = angular.merge {}, chartTemplates.multiBarChart,
options:
chart:
Expand Down
9 changes: 9 additions & 0 deletions assets/js/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ Array.prototype.shuffle = ->
for i in [this.length...0] by -1
j = Math.floor(Math.random() * i)
[this[i - 1], this[j]] = [this[j], this[i - 1]]

# Calculates the sum
Array.prototype.sum = ->
sumOp = (ac, val) -> ac + val
return this.reduce sumOp, 0

# Calculates the mean
Array.prototype.mean = ->
return this.sum() / this.length
8 changes: 8 additions & 0 deletions assets/styles/colors.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@featureColor: #90A4AE;
@targetColor: #4CAF50;

@chartDefaultColor: @featureColor;
@chartTargetColor: @targetColor;
@chartHighlightColor: #F44336;
@chartSelectionColor: #FFB74D;
@chartSelection2Color: #FF5722;
12 changes: 8 additions & 4 deletions assets/styles/featureInfo.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
width: 100%;

rect.nv-bar {
&.significant {
fill: #EF5350;
.significant-loop (@i) when (@i > 0) {
&.significant[significance='@{i}'] {
fill: mix(@chartHighlightColor, @chartDefaultColor, min(@i + 20, 100));
}
.significant-loop(@i - 10);
}
.significant-loop (100);
&.selected {
fill: #FFB74D;
fill: @chartSelectionColor !important;
}
&:hover {
cursor: pointer;
Expand All @@ -22,7 +26,7 @@
rect.highlight{
pointer-events: none;
fill-opacity: 0.5;
fill: #FFB74D;
fill: @chartSelectionColor;
stroke: black;
stroke-width: 0.5;
stroke-dasharray: 3;
Expand Down
4 changes: 2 additions & 2 deletions assets/styles/featureMap.less
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
rx: 80;
ry: 40;
stroke: #BDBDBD;
fill: #29B6F6;
fill: lighten(@featureColor, 20%);
}

text {
text-anchor: middle;
}

&.is-target ellipse {
fill: #E57373;
fill: @targetColor;
}
}
}
2 changes: 1 addition & 1 deletion assets/styles/featureSliceVisualizer.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ feature-slice-visualizer {
.histogram {
height: 170px;
rect.nv-bar {
fill: #FFB74D;
fill: @chartSelectionColor;
}
}
.probability-distributions {
Expand Down
1 change: 1 addition & 0 deletions assets/styles/importer.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

@import 'animations.less';
@import 'colors.less';
@import 'base.less';

@import 'featureMap.less';
Expand Down
4 changes: 2 additions & 2 deletions assets/styles/sliceChart.less
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ slice-chart {

rect {
height: 10px;
fill: #FFB74D;
fill: @chartSelectionColor;
fill-opacity: .75;
&:hover {
fill-opacity: 1;
cursor: pointer;
}
&.selected {
fill: #F44336;
fill: @chartSelection2Color;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions views/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ html(ng-app='predots')
script(src="/vendor/angular-websocket/angular-websocket.js")
script(src="/vendor/svg-pan-zoom/svg-pan-zoom.js")
script(src="/js/app.js")
script(src="/js/chartTemplates.js")
script(src="/js/controllers/AppCtrl.js")
script(src="/js/controllers/FeatureInfoCtrl.js")
script(src="/js/controllers/FeatureListCtrl.js")
Expand Down