Skip to content

Commit

Permalink
Merge pull request DynamoDS#8553 from pboyer/fixlistcount
Browse files Browse the repository at this point in the history
Fix list count, level display in preview bubble with dictionary present
  • Loading branch information
pboyer authored Feb 9, 2018
2 parents 309f03e + 9c8831a commit c0a0273
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/DynamoCoreWpf/ViewModels/Preview/WatchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ public bool IsOneRowContent
}
}


/// <summary>
/// Number of items in the overall list if node output is a list
/// </summary>
Expand Down Expand Up @@ -256,13 +255,17 @@ private Tuple<int, int> GetMaximumDepthAndItemNumber(WatchViewModel wvm)
{
return GetMaximumDepthAndItemNumber(wvm.Children[0]);
}
else

// if it's a list, recurse
if (wvm.NodeLabel == LIST)
{
var depthAndNumbers = wvm.Children.Select(GetMaximumDepthAndItemNumber);
var maxDepth = depthAndNumbers.Select(t => t.Item1).DefaultIfEmpty(1).Max() + 1;
var itemNumber = depthAndNumbers.Select(t => t.Item2).Sum();
return new Tuple<int, int>(maxDepth, itemNumber);
}

return new Tuple<int, int>(1,1);
}

/// <summary>
Expand Down
20 changes: 20 additions & 0 deletions test/DynamoCoreWpfTests/WatchNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,25 @@ public void WatchFunctionObject_collection_5033()

Assert.AreEqual("Function", watchVM.NodeLabel);
}

[Test]
public void WatchNestedDictionary()
{
string openPath = Path.Combine(TestDirectory, @"core\watch\watchNestedDictionaryList.dyn");
ViewModel.OpenCommand.Execute(openPath);
ViewModel.HomeSpace.Run();

var watchNode = ViewModel.Model.CurrentWorkspace.FirstNodeFromWorkspace<CodeBlockNodeModel>();
var watchVM = ViewModel.WatchHandler.GenerateWatchViewModelForData(
watchNode.CachedValue,
ViewModel.Model.EngineController.LiveRunnerRuntimeCore,
watchNode.AstIdentifierForPreview.Name);

watchVM.CountNumberOfItems();
watchVM.CountLevels();

Assert.AreEqual(3, watchVM.Levels.ElementAt(0));
Assert.AreEqual(2, watchVM.NumberOfItems);
}
}
}
76 changes: 76 additions & 0 deletions test/core/watch/watchNestedDictionaryList.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"Uuid": "b3971a38-9e42-4229-9ebd-7fa012a6ac9b",
"IsCustomNode": false,
"Description": null,
"Name": "watchNestedDictionaryList",
"ElementResolver": {
"ResolutionMap": {
"DesignScript.Builtin.Dictionary": {
"Key": "DesignScript.Builtin.Dictionary",
"Value": "Builtin.dll"
}
}
},
"Inputs": [],
"Nodes": [
{
"ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore",
"NodeType": "CodeBlockNode",
"Code": "[[{\"foo\": [1,2]}, {\"bar\": [1,2,3,4], \"baz\": 1}]];",
"Id": "937132ee84a64220b496e9f7d86f477a",
"Inputs": [],
"Outputs": [
{
"Id": "65eb03b27fd64885a55e921c23592d61",
"Name": "",
"Description": "Value of expression at line 1",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Allows for DesignScript code to be authored directly"
}
],
"Connectors": [],
"Dependencies": [],
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "2.0.0.2821",
"RunType": "Automatic",
"RunPeriod": "1000"
},
"Camera": {
"Name": "Default Camera",
"EyeX": -17.0,
"EyeY": 24.0,
"EyeZ": 50.0,
"LookX": 12.0,
"LookY": -13.0,
"LookZ": -58.0,
"UpX": 0.0,
"UpY": 1.0,
"UpZ": 0.0
},
"NodeViews": [
{
"ShowGeometry": true,
"Name": "Code Block",
"Id": "937132ee84a64220b496e9f7d86f477a",
"Excluded": false,
"X": 119.0,
"Y": 213.0
}
],
"Annotations": [],
"X": 0.0,
"Y": 0.0,
"Zoom": 1.0
}
}

0 comments on commit c0a0273

Please sign in to comment.