Skip to content

Commit

Permalink
short jobs views will try to use the space before its next job
Browse files Browse the repository at this point in the history
  • Loading branch information
hillin committed Aug 23, 2017
1 parent 010fc1e commit 6a3e66d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
6 changes: 3 additions & 3 deletions FASTBuilder/Views/Build/BuildJobView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace FastBuilder.Views.Build
{
public partial class BuildJobView
{
public const double ShortJobThreshold = 36;
public const double ShortJobWidthThreshold = 36;

public BuildJobView() => InitializeComponent();

Expand All @@ -19,14 +19,14 @@ public void Update(double left, double top, double width, string text, bool perf

this.Border.CornerRadius = new CornerRadius(MathEx.Clamp((this.Width - 12) / 2, 0, 2));

if (width < ShortJobThreshold)
if (width < ShortJobWidthThreshold)
{
this.DisplayName.Visibility = Visibility.Hidden;
}
else
{
this.DisplayName.Visibility = System.Windows.Visibility.Visible;
this.DisplayName.Opacity = Math.Min(1, Math.Max(0, (width - ShortJobThreshold) / 48));
this.DisplayName.Opacity = Math.Min(1, Math.Max(0, (width - ShortJobWidthThreshold) / 48));

if (performanceMode)
{
Expand Down
30 changes: 21 additions & 9 deletions FASTBuilder/Views/Build/BuildJobsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public partial class BuildJobsView
private BuildSessionJobManager _jobManager;

// recoreds active (visible) jobs and their corresponding view
private readonly Dictionary<IBuildJobViewModel, BuildJobView> _activeJobViewMap
= new Dictionary<IBuildJobViewModel, BuildJobView>();
private readonly Dictionary<BuildJobViewModel, BuildJobView> _activeJobViewMap
= new Dictionary<BuildJobViewModel, BuildJobView>();

// a queue that stores recycled job views (hidden and no job assigned)
private readonly Queue<BuildJobView> _jobViewPool
Expand Down Expand Up @@ -133,7 +133,7 @@ private void ClearJobs()
_coreTopMap.Clear();
}

private void JobManager_OnJobStarted(object sender, IBuildJobViewModel job)
private void JobManager_OnJobStarted(object sender, BuildJobViewModel job)
{
this.Dispatcher.BeginInvoke(new System.Action(() =>
{
Expand Down Expand Up @@ -173,10 +173,10 @@ private void UpdateCoreTopMap()

private bool IsShortJob(BuildJobViewModel job)
{
return job.ElapsedSeconds * _buildViewportService.Scaling <= BuildJobView.ShortJobThreshold;
return job.ElapsedSeconds * _buildViewportService.Scaling <= BuildJobView.ShortJobWidthThreshold;
}

private void AddJob(IBuildJobViewModel job)
private void AddJob(BuildJobViewModel job)
{

BuildJobView view;
Expand Down Expand Up @@ -248,7 +248,7 @@ private void UpdateJobs()
_endTimeOffset = buildViewportService.ViewEndTimeOffsetSeconds;
_wasNowInTimeFrame = _endTimeOffset >= _currentTimeOffset && _startTimeOffset <= _currentTimeOffset;

var jobs = new HashSet<IBuildJobViewModel>(_jobManager.EnumerateJobs(_startTimeOffset, _endTimeOffset, _visibleCores));
var jobs = new HashSet<BuildJobViewModel>(_jobManager.EnumerateJobs(_startTimeOffset, _endTimeOffset, _visibleCores));

// remove (recycle) job views that are no longer existed in current time frame
var keysToRemove = _activeJobViewMap.Keys.Where(key => !jobs.Contains(key)).ToList();
Expand Down Expand Up @@ -280,15 +280,27 @@ private void UpdateJobViews()

var performanceMode = _activeJobViewMap.Count > 8;

var maxWidth = 24 * 60 * 60 * scaling;

foreach (var pair in _activeJobViewMap)
{
var job = pair.Key;
var view = pair.Value;

var left = Math.Max(minimumLeft, job.StartTimeOffset * scaling);
var width = Math.Max(0, Math.Min(job.EndTimeOffset - Math.Max(_startTimeOffset, job.StartTimeOffset), 24 * 60 * 60) * scaling);
if (width < 1 // job too short to display
|| left + width < 1) // left could be negative
var acceptedStartTimeOffset = Math.Max(_startTimeOffset, job.StartTimeOffset);
var width = MathEx.Clamp((job.EndTimeOffset - acceptedStartTimeOffset) * scaling, 0, maxWidth);

if (width < BuildJobView.ShortJobWidthThreshold)
{
// try to use space before next job
width = job.NextJob != null
? MathEx.Clamp((job.NextJob.StartTimeOffset - acceptedStartTimeOffset) * scaling, 0, BuildJobView.ShortJobWidthThreshold)
: BuildJobView.ShortJobWidthThreshold;
}

if (width < 1 // job too short to display
|| left + width < 1) // left could be negative
{
// we don't recycle this view because it might be shown again after a zoom
view.Visibility = Visibility.Hidden;
Expand Down

0 comments on commit 6a3e66d

Please sign in to comment.