Giter VIP home page Giter VIP logo

powerbi-visuals-utils-formattingutils's Introduction

powerbi-visuals-utils-formattingutils's People

Contributors

adiletelf avatar alekssavelev avatar avisander avatar bjarnehelland avatar blackleaden avatar demonkratiy avatar dependabot[bot] avatar eugeneelkin avatar ignatvilesov avatar kulljul avatar microsoft-github-policy-service[bot] avatar mrmeison avatar mulyukovaidar avatar savvinsergey avatar uve avatar zbritva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

powerbi-visuals-utils-formattingutils's Issues

Importing issue

Hi,

After installing the packages and just import them in (pbiviz.json, tsconfig) this error appear in the console
Capture

Globalization does not work if value is specified

This is my code:

let valueFormatterSL = valueFormatter.create({ cultureSelector: "sl-SI" });
console.log(valueFormatterSL.format(3.14159));
let valueFormatterSLThousands = valueFormatter.create({ value: 1e3, cultureSelector: "sl-SI" });
console.log(valueFormatterSLThousands.format(314159));

And this is the output I get:

3,14159
314.16K

As you can see the decimal separator in the first case is comma, which is correct for the "sl-SI" culture. However, the decimal separator in the second case is dot, which is not correct. It seems that as soon as I specify any value for the ValueFormatterOptions it always reverts back to using the default, "en-US" culture.

Is this repo dead?

There have been no meaningful commits since July 2020.

Is there any plan to fix any of the current issues?
The library currently has a couple of bad behaviours like not handling the locale at all, or behaving in a different way compared to the stock visuals.

We have clients that often reports those anomalies to us but we can't basically do nothing.
We could manage to solve those ourselves, but the lack of documentation is a big problem.

Come on, a parameter named value that does all sort of things beside being just a plan "value", followed by an even more obscure value2. Maybe you could try to explain a bit better what those parameters do, without forcing us to look at the source code every time.

Suggestion - More modular packaging for the utils

For our custom visual, the only functionality required from this is powerbi.extensibility.utils.formatting.valueFormatter. However, the way how it is currently packaged, I need to include dataviewutils, formattingutils, typeutils, svgutils and Globalize, if I would use the full npm package as is, it also includes d3, jquery, lodash.

This results in >500KB of code just for number formatting - something that is actually already included in the default powerbi scripts, just not exposed in the API.

Formatting zeroes with unit abbreviation always returns a format with the highest unit abbreviation

I want to format the value of a custom card, and the code is as follows:

let formatter = valueFormatter.create({
    format: "#,#0 €;(#,#0 €);#,#0 €",
    cultureSelector: 'it-IT',
    formatSingleValues: true,
    value: 1e9
});

let formattedValue = formatter.format(value);

The results are great when value is a non-zero number, but it shows 0bn€ when zero.
Setting value as a very low number (like 0.00000001) shows the correct 0 € format.

Since I'm using formatSingleValue: true i expect 0 to be formatted without any unit abbreviation.

Tests I've done:

formatSingleValues: true  | value 10000000 | 10M€    | OK
formatSingleValues: false | value 10000000 | 0,01bn€ | OK
formatSingleValues: true  | value 0.000001 | 0€      | OK
formatSingleValues: false | value 0.000001 | 0bn€    | OK
formatSingleValues: true  | value 0        | 0bn€    | ERROR
formatSingleValues: false | value 0        | 0bn€    | OK

Everything was tested on 4.7.0 and 4.6.0.

valueFormatter ignores culture

Hi all,

I can't get valueFormatter to format my values as expected in terms of the unit abbreviation and the given culture. Even though it produces the correct decimal character (comma), the unit abbreviation still looks like for the default culture ("en-US").

Here's what I've done:

visual.ts:

import valueFormatter = powerbi.extensibility.utils.formatting.valueFormatter;
...
let formatterOptions : utils.formatting.ValueFormatterOptions = {
	value: 1000,
	precision: 1,
	cultureSelector: options.host.locale // "de-DE"
}; 
let formatter = valueFormatter.create(formatterOptions);
let v = formatter.format(2500); // gives 2,5K and not 2,5 Tsd. :-(

pbiviz.json:

... 
"externalJS": [
    "node_modules/globalize/lib/globalize.js",
    "node_modules/globalize/lib/cultures/globalize.cultures.js",
...

First posted at Power BI Community Forum: https://community.powerbi.com/t5/Developer/valueFormatter-ignores-culture-for-displayUnit/td-p/493226

Ignat Vilesov (Moderator) advised me to submit an issue here.

It looks like postfix has not been localized for all of languages. Please create a new bug in GitHub (Ignat Vilesov)

Thank you!
Martin

Regional settings for currency format

A Card with States user reported us an issue with regional format of CZK currency. The involved visual uses v1.0.0 of the formatting library, so I'm not sure how to solve the problem.
Can you help me?

Here is a screenshot:
power_bi

Incorrect formatting for percentage column

Current API gives incorrect formatting for getFormatString(). I used getFormatString() method in the old API (with Dev Tools)which gave the correct formatting. New API gives "#, 0.00" the expected is "0%". Note that however the getFormatStringByColumn() method gives correct formatting fortunately.

here is some sample code to compare the two. Note, metadataColumn is a column provided by the user which is having format as percent.

var alternateFormatProp = {objectName: 'general', propertyName: 'formatString',};

var formatString = valueFormatter.getFormatString(this.metadataColumn, alternateFormatProp);
//above gives incorrect value "#, 0.00"
var formatString = valueFormatter.getFormatStringByColumn(this.metadataColumn);
//above gives correct value "0%"

Floating point formatting issue

I'm running into a formatting issue of numerical values. I assume it's some kind of floating point problem where something gets converted into higher accuracy and then back to lower accuracy or the other way around.
To reproduce create a valueformatter using the following options:

let formatter = valueFormatter.create({
   "columnType": {
      "underlyingType": 259,
      "category": null,
      "primitiveType": 3,
      "extendedType": 259,
      "categoryString": null,
      "text": false,
      "numeric": true,
      "integer": false,
      "bool": false,
      "dateTime": false,
      "duration": false,
      "binary": false,
      "none": false
   },
   "value2": 1,
   "value": 0
});
let value = formatter.format(.2); // returns "0.19999999999999998" instead of "0.2"

I found a workaround where I set the domain boundaries value and value2 to null if they are between -1 and 1. If any of the properties value or value2 are null, this issue does not occur. This works so far for my test cases but it's unclear what side effects I didn't catch.
A fix would be greatly appreciated.

[es-2015 branch] Declaration files missing (v4.2.0)

With the latest beta version (v4.2.0) most of the declaration files are missing:

Could not find a declaration file for module 'powerbi-visuals-utils-formattingutils'. './node_modules/powerbi-visuals-utils-formattingutils/lib/src/index.js' implicitly has an 'any' type.

Is the change on tsconfig#22 intended and should we use import { valueFormatter } from "powerbi-visuals-utils-formattingutils/lib/src"; instead?

Formatting with "auto" display units has a different behaviour compared to built-in visuals.

I have the following valueFormatter:

let formatter = {
            name: y.displayName,
            formatter: valueFormatter.create({
                format: y.format,
                cultureSelector: "en-US",
                formatSingleValues: false,
                value: visualSettings.axisFormat.displayUnitsY // this is the value taken from visualSettings
            })
        }

Formatting a list of values with "auto" display units, gives different results compared to the build in scatterplot (that I'm using as the example).

immagine
The left graph is the stock scatterplot, while the right one is my custom one.
As you can see, while they are representing the same data, with the same formatting and same display units (auto), the Y axis is different

I'm expecting that formatting a number with the same settings, should be coherent with the behaviour of the built-in charts.

IValueFormatter.format() precision not working

precision option in IValueFormatter.format() is not working

Code :

var iValueFormatter = valueFormatter.create({
            format: "0",
            precision: 2
        });
iValueFormatter.format(77.5228);

Expected Output

iValueFormatter.format(77.5228); => 77.52

Actual Output

iValueFormatter.format(77.5228); => 77

"LocalizationLoader.js doesn't exist"

Hello folks,

having problems with:
import { valueFormatter } from "powerbi-visuals-utils-formattingutils

There are no problems with the import itself, but when I try to use it:
let iValueFormatter = valueFormatter.create({ format: dataView.metadata.columns[0].format })

I get this error:
"
ERROR in ./node_modules/powerbi-visuals-utils-formattingutils/lib/globalize/globalize.cultures.js 15:32-68
Module not found: Error: Can't resolve './node_modules/powerbi-visuals-tools/lib/LocalizationLoader.js' in 'D:\PP\Microsoft Pbiviz\D3\kpiBox'
resolve './node_modules/powerbi-visuals-tools/lib/LocalizationLoader.js' in 'D:\PP\Microsoft Pbiviz\D3\kpiBox'
using description file: D:\PP\Microsoft Pbiviz\D3\kpiBox\package.json (relative path: .)
using description file: D:\PP\Microsoft Pbiviz\D3\kpiBox\package.json (relative path: ./node_modules/powerbi-visuals-tools/lib/LocalizationLoader.js)
no extension
D:\PP\Microsoft Pbiviz\D3\kpiBox\node_modules\powerbi-visuals-tools\lib\LocalizationLoader.js doesn't exist
.js
D:\PP\Microsoft Pbiviz\D3\kpiBox\node_modules\powerbi-visuals-tools\lib\LocalizationLoader.js.js doesn't exist
as directory
D:\PP\Microsoft Pbiviz\D3\kpiBox\node_modules\powerbi-visuals-tools\lib\LocalizationLoader.js doesn't exist
@ ./node_modules/powerbi-visuals-utils-formattingutils/lib/src/formattingService/formattingService.js 31:27-74
@ ./node_modules/powerbi-visuals-utils-formattingutils/lib/src/index.js 28:24-72
@ ./src/visual.ts 31:0-71 47:30-51
@ ./.tmp/precompile/visualPlugin.ts 1:0-42 10:12-18 11:23-29

webpack 5.79.0 compiled with 1 error in 569 ms
"
formatting utils is installed and in node_modules

I can upload the whole project if you want to

ty in advance

Getting culture

Is there a way to grab the user local culture inside Power BI Desktop?
I tried this code:
let culture = ((<any>window.navigator).userLanguage || window.navigator.language);

It works in the browser, but in Power BI Desktop (also if the culture is different) it returns always 'en-US'.
Thanks

Incorrect formatting for currencies

See also https://github.com/Microsoft/PowerBI-visuals/issues/82#issuecomment-283703837


The library does not seem to format currency values correctly:

powerbi.extensibility.utils.formatting.valueFormatter.format(
    13594034.895999994, "\\$#,0;(\\$#,0);\\$#,0")

output:

13 594 034,896

but trying the default formattingService (if run from the browser console for the root window):

powerbi.formattingService.formatValue(13594034.895999994, "\\$#,0;(\\$#,0);\\$#,0")

output:

$13,594,035

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.