Skip to content

Commit

Permalink
[DYN-7334] Revised TuneUp controls layout (#53)
Browse files Browse the repository at this point in the history
* initial button re-arrangement

* DataGrid work

* progress record

* progress record

* collections wotking

fix sorting
add datagrids

* totals aligned

* total run times working

* evaluation completed works

* progress record

* progress

TODO:
- reset PreviousRun TotalGroup nodes' execution times
- remove execution time 0s from NotExecuted nodes when hoover over them

* progress record

TODO:
- Remove executionOrder from TotalGroupNodes
- ExportJSON - write the code
- Total time to be calculated from rounded times
- Remove ExecutionTimes from NotExecuted nodes
- UI to update when a node is renamed
- UI to update when group is renamed and/or background color has changed

* before UI cleanup

* progress record

* progress

* draft PR

* showGroups off by default

* Update ProfiledNodeViewModel.cs
  • Loading branch information
ivaylo-matov authored Sep 17, 2024
1 parent 459f1e2 commit ef46c31
Show file tree
Hide file tree
Showing 7 changed files with 1,558 additions and 472 deletions.
123 changes: 120 additions & 3 deletions TuneUp/ProfiledNodeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,115 @@
using Dynamo.Core;
using Dynamo.Graph.Annotations;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Graph.Nodes.ZeroTouch;

namespace TuneUp
{
public class ProfiledNodeViewModel : NotificationObject
{
#region Properties

/// <summary>
/// Checks if the Node has been Renamed after its creation
/// </summary>
public bool IsRenamed
{
get
{
if (NodeModel == null)
{
return false;
}
isRenamed = GetOriginalName(NodeModel) != NodeModel.Name;
return isRenamed;
}
internal set
{
if (isRenamed == value) return;
isRenamed = value;
RaisePropertyChanged(nameof(IsRenamed));
}
}
private bool isRenamed = false;

/// <summary>
/// The original name of the node
/// </summary>
public string OriginalName
{
get
{
//string originalName = NodeModel.GetOriginalName();
string originalName = GetOriginalName(NodeModel);
return originalName;
}
internal set
{
if (originalName == value) return;
originalName = value;
RaisePropertyChanged(nameof(OriginalName));
}
}
private string originalName = string.Empty;

/// <summary>
/// Indicates whether this node represents the total execution time for its group
/// </summary>
public bool IsGroupExecutionTime
{
get => isGroupExecutionTime;
set
{
isGroupExecutionTime = value;
RaisePropertyChanged(nameof(IsGroupExecutionTime));
}
}
private bool isGroupExecutionTime = false;

/// <summary>
/// Getting the original name before graph author renamed the node
/// </summary>
/// <param name="node">target NodeModel</param>
/// <returns>Original node name as string</returns>
private static string GetOriginalName(NodeModel node)
{
if (node == null) return string.Empty;
// For dummy node, return the current name so that does not appear to be renamed
if (node is DummyNode)
{
return node.Name;
}
if (node.IsCustomFunction)
{
// If the custom node is not loaded, return the current name so that does not appear to be renamed
if ((node as Function).State == ElementState.Error && (node as Function).Definition.IsProxy)
{
return node.Name;
}
// If the custom node is loaded, return original name as usual
var customNodeFunction = node as Function;
return customNodeFunction?.Definition.DisplayName;
}

var function = node as DSFunctionBase;
if (function != null)
return function.Controller.Definition.DisplayName;

var nodeType = node.GetType();
var elNameAttrib = nodeType.GetCustomAttributes<NodeNameAttribute>(false).FirstOrDefault();
if (elNameAttrib != null)
return elNameAttrib.Name;

return nodeType.FullName;
}

/// <summary>
/// Prefix string of execution time.
/// </summary>
public static readonly string ExecutionTimelString = "Execution Time";

public static readonly string GroupNodePrefix = "Group: ";
public static readonly string GroupExecutionTimeString = "Group total";

private string name = String.Empty;
/// <summary>
Expand All @@ -31,7 +128,9 @@ public string Name
get
{
// For virtual row, do not attempt to grab node name
if (!name.Contains(ExecutionTimelString) && !name.StartsWith(GroupNodePrefix))
if (!name.Contains(ExecutionTimelString) &&
!name.StartsWith(GroupNodePrefix) &&
!name.Equals(GroupExecutionTimeString))
name = NodeModel?.Name;
return name;
}
Expand Down Expand Up @@ -102,8 +201,14 @@ public TimeSpan GroupExecutionTime
/// </summary>
public int ExecutionMilliseconds
{
get => (int)Math.Round(ExecutionTime.TotalMilliseconds);
get => executionMilliseconds;
set
{
executionMilliseconds = value;
RaisePropertyChanged(nameof(ExecutionMilliseconds));
}
}
private int executionMilliseconds;

/// <summary>
/// Indicates whether this node was executed on the most recent graph run
Expand Down Expand Up @@ -176,6 +281,18 @@ public bool IsGroup
}
private bool isGroup;

public bool ShowGroupIndicator
{
get => showGroupIndicator;
set
{
showGroupIndicator = value;
RaisePropertyChanged(nameof(ShowGroupIndicator));
}
}
private bool showGroupIndicator;


/// <summary>
/// The background brush for this node
/// If this node represents a group, it inherits the background color from the associated AnnotationModel
Expand Down
7 changes: 4 additions & 3 deletions TuneUp/TuneUpViewExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class TuneUpViewExtension : ViewExtensionBase, IViewExtension

public override void Dispose()
{
TuneUpView.Dispose();
}

public override void Startup(ViewStartupParams p)
Expand All @@ -34,7 +33,9 @@ public override void Loaded(ViewLoadedParams p)
TuneUpView = new TuneUpWindow(p, UniqueId)
{
// Set the data context for the main grid in the window.
NodeAnalysisTable = { DataContext = ViewModel },
LatestRunTable = { DataContext = ViewModel },
PreviousRunTable = { DataContext = ViewModel },
NotExecutedTable = { DataContext = ViewModel },
MainGrid = { DataContext = ViewModel },
Owner = p.DynamoWindow
};
Expand Down Expand Up @@ -114,7 +115,7 @@ public override void Closed()
this.TuneUpMenuItem.IsChecked = false;

// Reset DataGrid sorting order & direction
ViewModel.SortingOrder = "number";
ViewModel.SortingOrder = TuneUpWindowViewModel.SortByNumber;
ViewModel.SortDirection = System.ComponentModel.ListSortDirection.Ascending;
}
}
Expand Down
Loading

0 comments on commit ef46c31

Please sign in to comment.