perspective icon indicating copy to clipboard operation
perspective copied to clipboard

Formatting data types does not adhere to minimumFractionDigits / maximumFractionDigits

Open zepaz opened this issue 4 years ago • 0 comments

Bug Report

Steps to Reproduce:

<!DOCTYPE html>
<html>

<head>

    <meta name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">

    <script src="https://cdn.jsdelivr.net/npm/@finos/perspective/dist/umd/perspective.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@finos/perspective-viewer/dist/umd/perspective-viewer.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@finos/perspective-viewer-datagrid"></script>
    <script src="https://cdn.jsdelivr.net/npm/@finos/perspective-viewer-d3fc"></script>

    <link rel='stylesheet' href="https://cdn.jsdelivr.net/npm/@finos/perspective-viewer/dist/umd/material-dense.css"
        is="custom-style">

    <style>
        perspective-viewer {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
        }
    </style>

</head>

<body>

    <perspective-viewer editable>

    </perspective-viewer>

    <script>
    const style = {
            types: {
                float: {
                    format: {
                        style: "decimal",
                        minimumFractionDigits: 0,
                        maximumFractionDigits: 0
                    }
                },
                customfloat: {
                    type: "float",
                    format: {
                        style: "decimal",
                        minimumFractionDigits: 2,
                        maximumFractionDigits: 3
                    }
                }
            }
        };
        const worker = window.perspective.worker(style);

        document.addEventListener("WebComponentsReady", function () {
            var data = [
                { x: 1, y: "a", z: true, t: "2016-01-13T17:11:29.998", f:1.123456, c:1.123456},
                { x: 3, y: "c", z: true, t: "2016-01-13T17:11:30.000", f:1.34567, c:1.12},
                { x: 4, y: "d", z: false, t: "2016-01-13T17:11:30.001", f:1.45, c:1.1}
            ];
            
            var viewer = document.getElementsByTagName('perspective-viewer')[0];

            table = worker.table({
                x: 'integer',
                y: 'string',
                z: 'boolean',
                t: 'datetime',
                f: 'float',
                c: 'customfloat'
            });

            table.update(data);

            viewer.load(table);
        });
    </script>

</body>

</html>

Expected Result:

I would expect to see

x y z t f c
1 a true 2016-01-13T17:11:29 1 1.123
10 c true 2016-01-13T17:11:30 1 1.12
4 d false 2016-01-13T17:11:30 1 1.10

Actual Result:

x y z t f c
1 a true 2016-01-13T17:11:29 1.12 1.123456
10 c true 2016-01-13T17:11:30 1.34 1.12
4 d false 2016-01-13T17:11:30 1.45 1.1

Environment:

Application Version
Google Chrome 87.0.4280.141 (Official Build) (64-bit)
OS Windows 10 OS Version 1809 (Build 17763.1637)
JavaScript V8 8.7.220.31
Perspective version 0.6.0

Additional Context:

https://jsfiddle.net/6jcz8qft/ image

zepaz avatar Jan 21 '21 03:01 zepaz