Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5092c19
apply latest d3 number format instead of d3 v3 format
archmoj Jun 26, 2021
cd0d392
update baselines
archmoj Jun 26, 2021
c7ecdc7
reflect schema changes
archmoj Jul 7, 2021
320b270
draft log for PR 5615
archmoj Jul 7, 2021
3ea8d90
refactor adjustFormat
archmoj Jul 12, 2021
a5fd000
refactor number format functions
archmoj Jul 12, 2021
6b93e61
Merge remote-tracking branch 'origin/master' into new-d3-number-format
archmoj Jul 12, 2021
25a30a8
catch and handle bad d3 number format instead of throwing error
archmoj Jul 12, 2021
05b221c
point to d3-format v1.4.5 options not higher
archmoj Jul 12, 2021
a5a94cd
Merge remote-tracking branch 'origin/master' into new-d3-number-format
archmoj Jul 12, 2021
e88a134
link d3 v3 without d3.format
archmoj Jul 12, 2021
d5d282d
edit draft log
archmoj Jul 12, 2021
68fe2b7
Merge remote-tracking branch 'origin/master' into new-d3-number-format
archmoj Jul 12, 2021
17e73b6
cast to string in the case of bad format
archmoj Jul 12, 2021
785f128
add jasmine tests
archmoj Jul 12, 2021
dc0d9cb
removed d3.time now switch to use d3-time
archmoj Jul 13, 2021
a425925
correct comment
archmoj Jul 13, 2021
11a75d9
centralized fn Lib.beginCap to work with new d3 methods
archmoj Jul 13, 2021
dc94854
Merge remote-tracking branch 'origin/master' into new-d3-number-format
archmoj Jul 13, 2021
bdb69fc
Merge remote-tracking branch 'origin/master' into new-d3-number-format
archmoj Jul 14, 2021
693ebd7
Update src/lib/index.js
archmoj Jul 17, 2021
1efc41e
use titleCase function
archmoj Jul 17, 2021
878034b
warn once encountered a bad format
archmoj Jul 17, 2021
80d37d2
Merge remote-tracking branch 'origin/master' into new-d3-number-format
archmoj Jul 17, 2021
518029a
update baseline using Raleway font instead of Dosis
archmoj Jul 17, 2021
32898a1
bump plotly/d3 to v3.8.0
archmoj Jul 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add jasmine tests
  • Loading branch information
archmoj committed Jul 12, 2021
commit 785f128b0bf81a38c02b0bc4db7fa9a45f931203
4 changes: 1 addition & 3 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ var MAX_SAFE = numConstants.FP_SAFE;
var MIN_SAFE = -MAX_SAFE;
var BADNUM = numConstants.BADNUM;

var lib = module.exports = {
_numberFormat: d3.format // simply to test d3.format before switching to d3-format
};
var lib = module.exports = {};

lib.adjustFormat = function adjustFormat(formatStr) {
if(
Expand Down
40 changes: 38 additions & 2 deletions test/jasmine/tests/lib_number_format_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var numberFormat = require('@src/lib')._numberFormat;
var numberFormat = require('@src/lib').numberFormat;

describe('number format', function() {
'use strict';
Expand All @@ -17,12 +17,22 @@ describe('number format', function() {
{ format: '.5%', number: ratio, exp: '67.89010%'},

// multiply by 100, round to significant digits, and then decimal notation with a percent sign
{ format: '.0p', number: ratio, exp: '70%'},
{ format: '.1p', number: ratio, exp: '70%'},
{ format: '.2p', number: ratio, exp: '68%'},
{ format: '.3p', number: ratio, exp: '67.9%'},
{ format: '.4p', number: ratio, exp: '67.89%'},
{ format: '.5p', number: ratio, exp: '67.890%'},

// type none
{ format: '.1', number: float, exp: '1e+4'},
{ format: '.2', number: float, exp: '1.2e+4'},
{ format: '.3', number: float, exp: '1.23e+4'},
{ format: '.4', number: float, exp: '1.235e+4'},
{ format: '.5', number: float, exp: '12346'},
{ format: '.6', number: float, exp: '12345.7'},
{ format: '.7', number: float, exp: '12345.68'},

// fixed point notation
{ format: '.0f', number: float, exp: '12346'},
{ format: '.1f', number: float, exp: '12345.7'},
Expand All @@ -31,14 +41,18 @@ describe('number format', function() {
{ format: '.4f', number: float, exp: '12345.6789'},
{ format: '.5f', number: float, exp: '12345.67890'},

// f with stating zero
// handle for backward compatibility
{ format: '0.0f', number: float, exp: '12346'},
{ format: '0.1f', number: float, exp: '12345.7'},
{ format: '0.2f', number: float, exp: '12345.68'},
{ format: '0.3f', number: float, exp: '12345.679'},
{ format: '0.4f', number: float, exp: '12345.6789'},
{ format: '0.5f', number: float, exp: '12345.67890'},

// bad formats
{ format: '0f', number: float, exp: '12345.678901'},
{ format: '1f', number: float, exp: '12345.678901'},

// space-filled and default sign
{ format: '-13', number: float, exp: '-12345.678901'},
{ format: '-14', number: float, exp: ' -12345.678901'},
Expand All @@ -49,6 +63,16 @@ describe('number format', function() {
{ format: '+14', number: float, exp: ' +12345.678901'},
{ format: '+15', number: float, exp: ' +12345.678901'},

// space-filled and negatives in parentheses
{ format: '(14', number: float, exp: ' (12345.678901)'},
{ format: '(15', number: float, exp: ' (12345.678901)'},
{ format: '(16', number: float, exp: ' (12345.678901)'},

// space-filled and negatives in parentheses with currency symbols per the locale definition
{ format: '($15', number: float, exp: ' ($12345.678901)'},
{ format: '($16', number: float, exp: ' ($12345.678901)'},
{ format: '($17', number: float, exp: ' ($12345.678901)'},

// hexadecimal, octal, or binary notation with symbol
{ format: '#0X', number: integer, exp: '0xDE'},
{ format: '#0x', number: integer, exp: '0xde'},
Expand All @@ -61,14 +85,26 @@ describe('number format', function() {
{ format: 'o', number: integer, exp: '336'},
{ format: 'b', number: integer, exp: '11011110'},

// exponent notation
{ format: 'e', number: float, exp: '1.234568e+4'},

// decimal notation, rounded to integer
{ format: 'd', number: float, exp: '12346'},

// decimal notation, rounded to significant digits
{ format: 'r', number: float, exp: '12345.7'},
{ format: '0.3r', number: float, exp: '12300'},
{ format: ',.3r', number: float, exp: '12,300'},
{ format: ',.2r', number: float, exp: '12,000'},
{ format: ',.1r', number: float, exp: '10,000'},

// decimal notation with an SI prefix, rounded to significant digits
{ format: '0.3s', number: float, exp: '12.3k'},
{ format: 's', number: float, exp: '12.3457k'},
{ format: 's', number: float * 1e+6, exp: '12.3457G'},
{ format: 's', number: float * 1e+3, exp: '12.3457M'},
{ format: 's', number: float * 1e-6, exp: '12.3457m'},
{ format: 's', number: float * 1e-9, exp: '12.3457µ'},
].forEach(function(test) {
var number = test.number;
var format = test.format;
Expand Down