Skip to content

Commit

Permalink
Merge pull request #3122 from tardyp/waterfall_view
Browse files Browse the repository at this point in the history
Waterfall view
  • Loading branch information
tardyp committed Apr 19, 2017
2 parents 6e243a7 + caf1a6f commit 0b9229a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 19 deletions.
4 changes: 2 additions & 2 deletions www/console_view/src/module/main.module.coffee
Expand Up @@ -51,7 +51,7 @@ class State extends Config
type: 'integer'
name: 'changeLimit'
caption: 'Number of changes to fetch'
default_value: 10
default_value: 30
]

class Console extends Controller
Expand Down Expand Up @@ -92,7 +92,7 @@ class Console extends Controller
@buildsets.length == 0 or @buildrequests == 0
return
if not @onchange_debounce?
@onchange_debounce = @$timeout(@_onChange, 500)
@onchange_debounce = @$timeout(@_onChange, 100)

_onChange: =>
@onchange_debounce = undefined
Expand Down
Expand Up @@ -48,3 +48,10 @@ class DataProcessor extends Service
builder.started_at = latest?.started_at
builder.complete = latest?.complete or false
builder.results = latest?.results

filterBuilders: (builders) ->
ret = []
for builder in builders
if builder.builds?.length
ret.push(builder)
return ret
66 changes: 49 additions & 17 deletions www/waterfall_view/src/module/main.module.coffee
Expand Up @@ -12,8 +12,18 @@ class Waterfall extends Controller
self = null
constructor: (@$scope, $q, $timeout, @$window, @$log,
@$uibModal, dataService, d3Service, @dataProcessorService,
scaleService, @bbSettingsService) ->
scaleService, @bbSettingsService, glTopbarContextualActionsService) ->
self = this
actions = [
caption: ""
icon: "search-plus"
action: @zoomPlus
,
caption: ""
icon: "search-minus"
action: @zoomMinus
]
glTopbarContextualActionsService.setContextualActions(actions)

# Show the loading spinner
@loading = true
Expand Down Expand Up @@ -50,9 +60,8 @@ class Waterfall extends Controller
buildidBackground: @s.number_background_waterfall.value

# Load data (builds and builders)
@$scope.builders = @builders = @dataAccessor.getBuilders(order: 'name')
@$scope.builders.queryExecutor.isFiltered = (v) ->
return not v.masterids? or v.masterids.length > 0
@all_builders = @dataAccessor.getBuilders(order: 'name')
@$scope.builders = @builders = []
@buildLimit = @c.limit
@$scope.builds = @builds = @dataAccessor.getBuilds({limit: @buildLimit, order: '-complete_at'})

Expand All @@ -62,7 +71,8 @@ class Waterfall extends Controller
@scale = new scaleService(@d3)

# Create groups and add builds to builders
@groups = @dataProcessorService.getGroups(@builders, @builds, @c.threshold)
@groups = @dataProcessorService.getGroups(@all_builders, @builds, @c.threshold)
@$scope.builders = @builders = @dataProcessorService.filterBuilders(@all_builders)
# Add builder status to builders
@dataProcessorService.addStatus(@builders)

Expand All @@ -85,7 +95,6 @@ class Waterfall extends Controller
(n, o) => if n != o then @render()
, true
)
angular.element(@$window).bind 'resize', => @render()

# Update view on data change
@loadingMore = false
Expand All @@ -102,18 +111,31 @@ class Waterfall extends Controller
# Bind scroll event listener
angular.element(containerParent).bind 'scroll', onScroll

@$window.onkeydown = (e) =>
resizeHandler = => @render()
window = angular.element(@$window)
window.bind 'resize', resizeHandler
keyHandler = (e) =>
# +
if e.key is '+'
e.preventDefault()
@incrementScaleFactor()
@render()
@zoomPlus()
# -
if e.key is '-'
e.preventDefault()
@decrementScaleFactor()
@render()
@zoomMinus()
window.bind 'keypress', keyHandler
@$scope.$on '$destroy', ->
window.unbind 'keypress', keyHandler
window.unbind 'resize', resizeHandler


zoomPlus: =>
@incrementScaleFactor()
@render()

zoomMinus: =>
@decrementScaleFactor()
@render()
###
# Increment and decrement the scale factor
###
Expand Down Expand Up @@ -158,11 +180,12 @@ class Waterfall extends Controller
.attr('transform', "translate(#{@c.margin.left}, #{@c.margin.top})")
.attr('class', 'chart')

height = @getHeaderHeight()
@waterfall.select(".header").style("height", height)
@header = @header.append('svg')
.append('g')
.attr('transform', "translate(#{@c.margin.left}, #{@getHeaderHeight()})")
.attr('transform', "translate(#{@c.margin.left}, #{height})")
.attr('class', 'header')

###
# Get the container width
###
Expand Down Expand Up @@ -204,6 +227,9 @@ class Waterfall extends Controller
if height < parseInt @waterfall.style('height').replace('px', ''), 10
@loadMore()
@container.style('height', "#{height}px")
height = @getHeaderHeight()
@waterfall.select("div.header").style("height", height + "px")
@header.attr('transform', "translate(#{@c.margin.left}, #{height})")

###
# Returns content width
Expand All @@ -222,7 +248,11 @@ class Waterfall extends Controller
###
# Returns headers height
###
getHeaderHeight: -> parseInt @header.style('height').replace('px', ''), 10
getHeaderHeight: ->
max_buildername = 0
for builder in @builders
max_buildername = Math.max(builder.name.length, max_buildername)
return Math.max(100, max_buildername * 3)

###
# Returns the result string of a builder, build or step
Expand Down Expand Up @@ -275,7 +305,7 @@ class Waterfall extends Controller
# Rotate text
xAxisSelect.selectAll('text')
.style('text-anchor', 'start')
.attr('transform', 'translate(0, -5) rotate(-60)')
.attr('transform', 'translate(0, -5) rotate(-25)')
.attr('dy', '.75em')
.each(link)

Expand Down Expand Up @@ -387,10 +417,11 @@ class Waterfall extends Controller
return a
return b
# Draw rectangle for each build
height = (build) -> max(10, Math.abs(y(build.started_at) - y(build.complete_at)))
builds.append('rect')
.attr('class', self.getResultClassFromThing)
.attr('width', x.rangeBand(1))
.attr('height', (build) -> max(10, Math.abs(y(build.started_at) - y(build.complete_at))))
.attr('height', height)
.classed('fill', true)

# Optional: grey rectangle below buildids
Expand Down Expand Up @@ -499,7 +530,8 @@ class Waterfall extends Controller
selectedBuild: -> build

renderNewData: =>
@groups = @dataProcessorService.getGroups(@builders, @builds, @c.threshold)
@groups = @dataProcessorService.getGroups(@all_builders, @builds, @c.threshold)
@$scope.builders = @builders = @dataProcessorService.filterBuilders(@all_builders)
@dataProcessorService.addStatus(@builders)
@render()
@loadingMore = false
Expand Down
2 changes: 2 additions & 0 deletions www/waterfall_view/src/styles/styles.less
Expand Up @@ -40,6 +40,8 @@
height: 100px;
line-height: 100px;
margin-bottom: 2px;
// @FIXME: add a bit of margin-right in order to be able to see the rotated titles.
margin-right: -150px;
vertical-align: middle;

.header-content {
Expand Down

0 comments on commit 0b9229a

Please sign in to comment.