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

Improvement Number Format #13744

Merged
merged 5 commits into from
Feb 17, 2023
Merged

Improvement Number Format #13744

merged 5 commits into from
Feb 17, 2023

Conversation

jesusalvino
Copy link
Contributor

Purpose

Implement the improvement https://jira.autodesk.com/browse/DYN-4469

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated

Reviewers

@zeusongit

FYIs

@RobertGlobant20 @filipeotero

@jesusalvino
Copy link
Contributor Author

numberformat_improvement

}
}

private bool IsDoubleRealNumber(string valueToTest)
Copy link
Contributor

@QilongTang QilongTang Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this function? Since this is only a one line if check, maybe we can just fold it to the function above?

if (double.TryParse(valueToTest, out double d) && !Double.IsNaN(d) && !Double.IsInfinity(d))
{
       return Convert.ToDouble(numberValue).ToString(nodeViewModel.DynamoViewModel.PreferenceSettings.NumberFormat);
}
else
{
       return numberValue;
 }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this function? Since this is only a one line if check, maybe we can just fold it to the function above?

if (double.TryParse(valueToTest, out double d) && !Double.IsNaN(d) && !Double.IsInfinity(d))
{
       return Convert.ToDouble(numberValue).ToString(nodeViewModel.DynamoViewModel.PreferenceSettings.NumberFormat);
}
else
{
       return numberValue;
 }

just wanted to keep separate it, probably it would be part of a helper class or similar so we can move latter, like ADSK.Dynamo.Helpers.IsDoubleRealNumber (maybe we already have a similar) or you approach to keep it simple is totally valid, please your thoughts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, in that case, I am fine with keeping it, but we should then probably move this function to one of DynamoUtilites file, like https://github.com/DynamoDS/Dynamo/blob/master/src/DynamoCoreWpf/Utilities/PreferencesPanelUtilities.cs. Also maybe pick a name easier to understand, like IsValidDoubleNumber?

Copy link
Contributor

@QilongTang QilongTang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with two comments

@aparajit-pratap
Copy link
Contributor

aparajit-pratap commented Feb 14, 2023

@jesusalvino I think there was some work done on this before and this issue is not isolated to only String from Object node. Here is the PR that tries to fix this issue more holistically. There was some work left on the UI side to add a default format preference that would not impose any digits: https://jira.autodesk.com/browse/DYN-5101. FYI @Amoursol .

I feel we should consider that previous work before merging this fix that is specific to just one node. ⚠️

@jesusalvino
Copy link
Contributor Author

@aparajit-pratap I have picked up your previous work and refactored the mine based on your suggestion in my last commit 584cbcb , your thoughts please.

Comment on lines 235 to 239
if (Data is double)
{
return (Data as IFormattable).ToString(PrecisionFormat, CultureInfo.InvariantCulture);
}
else
Copy link
Contributor

@aparajit-pratap aparajit-pratap Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would comment out this code for the time being and leave a TODO comment here saying "uncomment this once https://jira.autodesk.com/browse/DYN-5101 is complete".

@@ -259,6 +261,10 @@ private static string GetStringFromObject(object obj)
case TypeCode.Object:
return ObjectToLabelString(obj);
default:
if (double.TryParse(obj.ToString(), out double d))
{
return Convert.ToDouble(obj).ToString(PrecisionFormat, CultureInfo.InvariantCulture);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be ProtoCore.Mirror.MirrorData.PrecisionFormat.

@@ -249,7 +251,7 @@ private static string GetStringFromObject(object obj)
case TypeCode.Boolean:
return ObjectToLabelString(obj);
case TypeCode.Double:
return ((double)obj).ToString(numberFormat, CultureInfo.InvariantCulture);
return ((double)obj).ToString(ProtoCore.Mirror.MirrorData.PrecisionFormat, CultureInfo.InvariantCulture);
Copy link
Contributor

@aparajit-pratap aparajit-pratap Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I would comment out this change for the time being until https://jira.autodesk.com/browse/DYN-5101 is done. Add a TODO.

@@ -241,6 +241,8 @@ public WatchViewModel(string label, string path, Action<string> tagGeometry, boo
IsCollection = label == WatchViewModel.LIST || label == WatchViewModel.DICTIONARY;
}

internal static string PrecisionFormat { get; set; } = "f3";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to add this property.

@@ -381,10 +381,11 @@ private void RefreshExpandedDisplay(Action refreshDisplay)
nodeViewModel.NodeModel.OutPorts.Select(p => p.Name).Where(n => !string.IsNullOrEmpty(n));
}

WatchViewModel.PrecisionFormat = nodeViewModel.DynamoViewModel.PreferenceSettings.NumberFormat;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to this file can be reverted entirely.

@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file can be reverted entirely.

@QilongTang QilongTang added this to the 2.18.0 milestone Feb 17, 2023
@QilongTang
Copy link
Contributor

Reported regression is sporadic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants