tableau / extensions-api

Extensions API sample code and developer docs.
http://tableau.github.io/extensions-api
MIT License
268 stars 251 forks source link

Parameter changeValueAsync with percentages expects comma instead of point #104

Closed tjallingt closed 5 years ago

tjallingt commented 6 years ago

Reproducable example: try the Parameter.changeValueAsync method on the Superstore workbook to change the "Churn rate" parameter.

parameter.changeValueAsync(0.1); // 25%
parameter.changeValueAsync("0.1"); // 25%
parameter.changeValueAsync("0,1"); // 10%

This is especially confusing because it will return DataValue.value === "0.1" (point not comma 😖)

benlower commented 6 years ago

We're taking a look at this.

tjallingt commented 6 years ago

Great to hear! This would allow me to strip a really ugly hack out of my extension code 😅

Kovner commented 6 years ago

@tjallingt What is the locale of you Desktop instance set to? If it's not en-US, can you try reproducing with it set to en-US?

tjallingt commented 6 years ago

My locale is set to en-US:

capture2

Kovner commented 6 years ago

OK, It does have to do with your machine's locale and therefore how Tableau is displaying the parameter. With my os language set to English, I could not reproduce this ('0.1' showed 10.00% in the param), but then I changed my os language to French and that changed how Tableau was displaying the value in the param to 10,00% (similar to your screenshot). Now, I have to pass in '0,1' for it to work and '0.1' throws an error.

So in a way that feels consistent, but I also repro'd what you said about param.currentValue returning '0.1' even when the param is using commas for delimeters. So that is inconsistent and we also have to make sure the allowableValues gives you the right info to know what to pass in.

Thanks for letting us know about this.

tjallingt commented 6 years ago

Hey @Kovner thanks for your response, great to hear you figured out what is causing this strange behaviour 👍

So i see two bugs and a feature request here, the bugs (as i see it):

The feature request concerns the fact that obviously string representations of numeric values are not perfect (especially when casting is made difficult by different localisations of the same value). It would be great if allowableValues and changeValueAsync would just use floating point numbers for percentages.

I'm assuming the reason the extension API is spitting out strings is somehow tied to how Tableau is handling this data internally so there might not be a quick fix for that but perhaps the extension api could supply us with a localisation method that takes care of correctly formatting percentages for changeValueAsync (and all the other places values are expected to be localised of course)

Kovner commented 6 years ago

Yep, I agree with all of that. We'll look into it soon, but I'm not sure whether any related fixes will be in v1 of Extensions API or post-v1. And if it's post-v1, we'll have to be sure to not make breaking changes.