diff --git a/DESCRIPTION b/DESCRIPTION index 7289bba..c6f7595 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: apexcharter -Version: 0.1.2.910 +Version: 0.1.2.920 Title: Create Interactive Chart with the JavaScript 'ApexCharts' Library Description: Provides an 'htmlwidgets' interface to 'apexcharts.js'. 'Apexcharts' is a modern JavaScript charting library to build interactive charts and visualizations with simple API. diff --git a/NAMESPACE b/NAMESPACE index 4500950..0457433 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -35,6 +35,7 @@ export(ax_yaxis) export(ax_yaxis2) export(bar_opts) export(events_opts) +export(format_num) export(heatmap_opts) export(parse_df) export(pie_opts) diff --git a/NEWS.md b/NEWS.md index 075d169..87435c2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +apexcharter 0.1.3 +================== + +* Upgraded ApexCharts.js to 3.10.1 +* New function `format_num()` to format labels on y-axis for example. + + + apexcharter 0.1.2 ================== diff --git a/R/format.R b/R/format.R new file mode 100644 index 0000000..ec10eb9 --- /dev/null +++ b/R/format.R @@ -0,0 +1,38 @@ + +#' Format numbers (with D3) +#' +#' @param format Format for numbers, currency, percentage, e.g. \code{".0\%"} for rounded percentage. +#' See online documentation : \url{https://github.com/d3/d3-format}. +#' @param locale Localization to use, for exemple \code{"fr-FR"} for french, +#' see possible values here: \url{https://github.com/d3/d3-format/tree/master/locale}. +#' +#' @return a \code{JS} function +#' @export +#' +#' @importFrom htmlwidgets JS +#' +#' @example examples/format.R +format_num <- function(format, locale = "en-US") { + check_locale(locale) + path <- system.file(file.path("htmlwidgets/lib/d3-format/locale", paste0(locale, ".json")), package = "apexcharter") + if (path != "") { + locale <- paste(readLines(con = path, encoding = "UTF-8"), collapse = "") + } + JS(sprintf( + "function(value) {var locale = d3.formatLocale(JSON.parse('%s')); return locale.format('%s')(value);}", + locale, format + )) +} + + +check_locale <- function(x) { + json <- list.files(system.file("htmlwidgets/lib/d3-format/locale", package = "apexcharter")) + njson <- gsub("\\.json", "", json) + if (!x %in% njson) { + stop(paste( + "Invalid D3 locale, must be one of:", + paste(njson, collapse = ", ") + ), call. = FALSE) + } +} + diff --git a/examples/format.R b/examples/format.R new file mode 100644 index 0000000..ddecf20 --- /dev/null +++ b/examples/format.R @@ -0,0 +1,52 @@ +# Use SI prefix +dat <- data.frame( + labels = c("apex", "charts"), + values = c(1e4, 2e4) +) + +apex(dat, aes(labels, values), "column") %>% + ax_yaxis(labels = list( + formatter = format_num("~s") + )) + +apex(dat, aes(labels, values * 100), "column") %>% + ax_yaxis(labels = list( + formatter = format_num("~s") + )) + + +# Percentage +dat <- data.frame( + labels = c("apex", "charts"), + values = c(0.45, 0.55) +) + +apex(dat, aes(labels, values), "column") %>% + ax_yaxis(labels = list( + formatter = format_num(".0%") + )) + + +# Currency +dat <- data.frame( + labels = c("apex", "charts"), + values = c(570, 1170) +) + +apex(dat, aes(labels, values), "column") %>% + ax_yaxis(labels = list( + formatter = format_num("$,.2f") + )) + + +# Change locale +apex(dat, aes(labels, values), "column") %>% + ax_yaxis(labels = list( + formatter = format_num("$,.2f", "fr-FR") + )) + + + + + + diff --git a/inst/htmlwidgets/apexcharter.yaml b/inst/htmlwidgets/apexcharter.yaml index a367485..cf03818 100644 --- a/inst/htmlwidgets/apexcharter.yaml +++ b/inst/htmlwidgets/apexcharter.yaml @@ -3,7 +3,7 @@ dependencies: version: 3.10.1 src: htmlwidgets/lib/apexcharts-3.10 script: apexcharts.min.js - - name: numeral - version: 2.0.6 - src: htmlwidgets/lib/numeral - script: numeral.min.js + - name: d3-format + version: 1.4.2 + src: htmlwidgets/lib/d3-format + script: d3-format.min.js diff --git a/inst/htmlwidgets/lib/d3-format/d3-format.min.js b/inst/htmlwidgets/lib/d3-format/d3-format.min.js new file mode 100644 index 0000000..1820fdf --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/d3-format.min.js @@ -0,0 +1,2 @@ +// https://d3js.org/d3-format/ v1.4.2 Copyright 2019 Mike Bostock +!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t=t||self).d3=t.d3||{})}(this,function(t){"use strict";function n(t,n){if((i=(t=n?t.toExponential(n-1):t.toExponential()).indexOf("e"))<0)return null;var i,r=t.slice(0,i);return[r.length>1?r[0]+r.slice(2):r,+t.slice(i+1)]}function i(t){return(t=n(Math.abs(t)))?t[1]:NaN}var r,e=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function o(t){if(!(n=e.exec(t)))throw new Error("invalid format: "+t);var n;return new a({fill:n[1],align:n[2],sign:n[3],symbol:n[4],zero:n[5],width:n[6],comma:n[7],precision:n[8]&&n[8].slice(1),trim:n[9],type:n[10]})}function a(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function s(t,i){var r=n(t,i);if(!r)return t+"";var e=r[0],o=r[1];return o<0?"0."+new Array(-o).join("0")+e:e.length>o+1?e.slice(0,o+1)+"."+e.slice(o+1):e+new Array(o-e.length+2).join("0")}o.prototype=a.prototype,a.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var u={"%":function(t,n){return(100*t).toFixed(n)},b:function(t){return Math.round(t).toString(2)},c:function(t){return t+""},d:function(t){return Math.round(t).toString(10)},e:function(t,n){return t.toExponential(n)},f:function(t,n){return t.toFixed(n)},g:function(t,n){return t.toPrecision(n)},o:function(t){return Math.round(t).toString(8)},p:function(t,n){return s(100*t,n)},r:s,s:function(t,i){var e=n(t,i);if(!e)return t+"";var o=e[0],a=e[1],s=a-(r=3*Math.max(-8,Math.min(8,Math.floor(a/3))))+1,u=o.length;return s===u?o:s>u?o+new Array(s-u+1).join("0"):s>0?o.slice(0,s)+"."+o.slice(s):"0."+new Array(1-s).join("0")+n(t,Math.max(0,i+s-1))[0]},X:function(t){return Math.round(t).toString(16).toUpperCase()},x:function(t){return Math.round(t).toString(16)}};function c(t){return t}var f,h=Array.prototype.map,l=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function d(t){var n,e,a=void 0===t.grouping||void 0===t.thousands?c:(n=h.call(t.grouping,Number),e=t.thousands+"",function(t,i){for(var r=t.length,o=[],a=0,s=n[0],u=0;r>0&&s>0&&(u+s+1>i&&(s=Math.max(1,i-u)),o.push(t.substring(r-=s,r+s)),!((u+=s+1)>i));)s=n[a=(a+1)%n.length];return o.reverse().join(e)}),s=void 0===t.currency?"":t.currency[0]+"",f=void 0===t.currency?"":t.currency[1]+"",d=void 0===t.decimal?".":t.decimal+"",m=void 0===t.numerals?c:function(t){return function(n){return n.replace(/[0-9]/g,function(n){return t[+n]})}}(h.call(t.numerals,String)),p=void 0===t.percent?"%":t.percent+"",g=void 0===t.minus?"-":t.minus+"",v=void 0===t.nan?"NaN":t.nan+"";function M(t){var n=(t=o(t)).fill,i=t.align,e=t.sign,c=t.symbol,h=t.zero,M=t.width,y=t.comma,x=t.precision,b=t.trim,w=t.type;"n"===w?(y=!0,w="g"):u[w]||(void 0===x&&(x=12),b=!0,w="g"),(h||"0"===n&&"="===i)&&(h=!0,n="0",i="=");var S="$"===c?s:"#"===c&&/[boxX]/.test(w)?"0"+w.toLowerCase():"",j="$"===c?f:/[%p]/.test(w)?p:"",k=u[w],z=/[defgprs%]/.test(w);function A(t){var o,s,u,c=S,f=j;if("c"===w)f=k(t)+f,t="";else{var p=(t=+t)<0;if(t=isNaN(t)?v:k(Math.abs(t),x),b&&(t=function(t){t:for(var n,i=t.length,r=1,e=-1;r0){if(!+t[r])break t;e=0}}return e>0?t.slice(0,e)+t.slice(n+1):t}(t)),p&&0==+t&&(p=!1),c=(p?"("===e?e:g:"-"===e||"("===e?"":e)+c,f=("s"===w?l[8+r/3]:"")+f+(p&&"("===e?")":""),z)for(o=-1,s=t.length;++o(u=t.charCodeAt(o))||u>57){f=(46===u?d+t.slice(o+1):t.slice(o))+f,t=t.slice(0,o);break}}y&&!h&&(t=a(t,1/0));var A=c.length+t.length+f.length,N=A>1)+c+t+f+N.slice(A);break;default:t=N+c+t+f}return m(t)}return x=void 0===x?6:/[gprs]/.test(w)?Math.max(1,Math.min(21,x)):Math.max(0,Math.min(20,x)),A.toString=function(){return t+""},A}return{format:M,formatPrefix:function(t,n){var r=M(((t=o(t)).type="f",t)),e=3*Math.max(-8,Math.min(8,Math.floor(i(n)/3))),a=Math.pow(10,-e),s=l[8+e/3];return function(t){return r(a*t)+s}}}}function m(n){return f=d(n),t.format=f.format,t.formatPrefix=f.formatPrefix,f}m({decimal:".",thousands:",",grouping:[3],currency:["$",""],minus:"-"}),t.FormatSpecifier=a,t.formatDefaultLocale=m,t.formatLocale=d,t.formatSpecifier=o,t.precisionFixed=function(t){return Math.max(0,-i(Math.abs(t)))},t.precisionPrefix=function(t,n){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(i(n)/3)))-i(Math.abs(t)))},t.precisionRound=function(t,n){return t=Math.abs(t),n=Math.abs(n)-t,Math.max(0,i(n)-i(t))+1},Object.defineProperty(t,"__esModule",{value:!0})}); diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-001.json b/inst/htmlwidgets/lib/d3-format/locale/ar-001.json new file mode 100644 index 0000000..0376eb9 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-001.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", ""], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-AE.json b/inst/htmlwidgets/lib/d3-format/locale/ar-AE.json new file mode 100644 index 0000000..a827308 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-AE.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u062f\u002e\u0625\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-BH.json b/inst/htmlwidgets/lib/d3-format/locale/ar-BH.json new file mode 100644 index 0000000..5f4e5dd --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-BH.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u062f\u002e\u0628\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-DJ.json b/inst/htmlwidgets/lib/d3-format/locale/ar-DJ.json new file mode 100644 index 0000000..b893ff0 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-DJ.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["\u200f\u0046\u0064\u006a ", ""], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-DZ.json b/inst/htmlwidgets/lib/d3-format/locale/ar-DZ.json new file mode 100644 index 0000000..e1438af --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-DZ.json @@ -0,0 +1,6 @@ +{ + "decimal": "\u002c", + "thousands": "\u002e", + "grouping": [3], + "currency": ["\u062f\u002e\u062c\u002e ", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-EG.json b/inst/htmlwidgets/lib/d3-format/locale/ar-EG.json new file mode 100644 index 0000000..2b1ff3a --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-EG.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u062c\u002e\u0645\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-EH.json b/inst/htmlwidgets/lib/d3-format/locale/ar-EH.json new file mode 100644 index 0000000..b33c32a --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-EH.json @@ -0,0 +1,6 @@ +{ + "decimal": "\u002e", + "thousands": "\u002c", + "grouping": [3], + "currency": ["\u062f\u002e\u0645\u002e ", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-ER.json b/inst/htmlwidgets/lib/d3-format/locale/ar-ER.json new file mode 100644 index 0000000..b0f82bb --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-ER.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["\u004e\u0066\u006b ", ""], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-IL.json b/inst/htmlwidgets/lib/d3-format/locale/ar-IL.json new file mode 100644 index 0000000..ce15fb4 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-IL.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["\u20aa ", ""], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-IQ.json b/inst/htmlwidgets/lib/d3-format/locale/ar-IQ.json new file mode 100644 index 0000000..a6c9b3f --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-IQ.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u062f\u002e\u0639\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-JO.json b/inst/htmlwidgets/lib/d3-format/locale/ar-JO.json new file mode 100644 index 0000000..94df180 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-JO.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u062f\u002e\u0623\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-KM.json b/inst/htmlwidgets/lib/d3-format/locale/ar-KM.json new file mode 100644 index 0000000..84dd81a --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-KM.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u0641\u002e\u062c\u002e\u0642\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-KW.json b/inst/htmlwidgets/lib/d3-format/locale/ar-KW.json new file mode 100644 index 0000000..b4018ab --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-KW.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u062f\u002e\u0643\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-LB.json b/inst/htmlwidgets/lib/d3-format/locale/ar-LB.json new file mode 100644 index 0000000..c732df3 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-LB.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u0644\u002e\u0644\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-LY.json b/inst/htmlwidgets/lib/d3-format/locale/ar-LY.json new file mode 100644 index 0000000..431f230 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-LY.json @@ -0,0 +1,6 @@ +{ + "decimal": "\u002c", + "thousands": "\u002e", + "grouping": [3], + "currency": ["\u062f\u002e\u0644\u002e ", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-MA.json b/inst/htmlwidgets/lib/d3-format/locale/ar-MA.json new file mode 100644 index 0000000..abc0663 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-MA.json @@ -0,0 +1,6 @@ +{ + "decimal": "\u002c", + "thousands": "\u002e", + "grouping": [3], + "currency": ["\u062f\u002e\u0645\u002e ", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-MR.json b/inst/htmlwidgets/lib/d3-format/locale/ar-MR.json new file mode 100644 index 0000000..8d1f8c2 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-MR.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u0623\u002e\u0645\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-OM.json b/inst/htmlwidgets/lib/d3-format/locale/ar-OM.json new file mode 100644 index 0000000..04ad53a --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-OM.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u0631\u002e\u0639\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-PS.json b/inst/htmlwidgets/lib/d3-format/locale/ar-PS.json new file mode 100644 index 0000000..ce15fb4 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-PS.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["\u20aa ", ""], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-QA.json b/inst/htmlwidgets/lib/d3-format/locale/ar-QA.json new file mode 100644 index 0000000..94aef29 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-QA.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u0631\u002e\u0642\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-SA.json b/inst/htmlwidgets/lib/d3-format/locale/ar-SA.json new file mode 100644 index 0000000..4d64227 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-SA.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u0631\u002e\u0633\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-SD.json b/inst/htmlwidgets/lib/d3-format/locale/ar-SD.json new file mode 100644 index 0000000..1ae41ae --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-SD.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u062c\u002e\u0633\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-SO.json b/inst/htmlwidgets/lib/d3-format/locale/ar-SO.json new file mode 100644 index 0000000..143b46f --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-SO.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["\u200f\u0053 ", ""], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-SS.json b/inst/htmlwidgets/lib/d3-format/locale/ar-SS.json new file mode 100644 index 0000000..03ca5b4 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-SS.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["\u00a3 ", ""], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-SY.json b/inst/htmlwidgets/lib/d3-format/locale/ar-SY.json new file mode 100644 index 0000000..40263fb --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-SY.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u0644\u002e\u0633\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-TD.json b/inst/htmlwidgets/lib/d3-format/locale/ar-TD.json new file mode 100644 index 0000000..7bc3646 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-TD.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["\u200f\u0046\u0043\u0046\u0041 ", ""], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-TN.json b/inst/htmlwidgets/lib/d3-format/locale/ar-TN.json new file mode 100644 index 0000000..16829aa --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-TN.json @@ -0,0 +1,6 @@ +{ + "decimal": "\u002c", + "thousands": "\u002e", + "grouping": [3], + "currency": ["\u062f\u002e\u062a\u002e ", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ar-YE.json b/inst/htmlwidgets/lib/d3-format/locale/ar-YE.json new file mode 100644 index 0000000..ed9f48e --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ar-YE.json @@ -0,0 +1,7 @@ +{ + "decimal": "\u066b", + "thousands": "\u066c", + "grouping": [3], + "currency": ["", " \u0631\u002e\u0649\u002e"], + "numerals" : ["\u0660", "\u0661", "\u0662", "\u0663", "\u0664", "\u0665", "\u0666", "\u0667", "\u0668", "\u0669"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ca-ES.json b/inst/htmlwidgets/lib/d3-format/locale/ca-ES.json new file mode 100644 index 0000000..a249762 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ca-ES.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": ".", + "grouping": [3], + "currency": ["", "\u00a0€"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/cs-CZ.json b/inst/htmlwidgets/lib/d3-format/locale/cs-CZ.json new file mode 100644 index 0000000..7ff40eb --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/cs-CZ.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": "\u00a0", + "grouping": [3], + "currency": ["", "\u00a0Kč"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/de-CH.json b/inst/htmlwidgets/lib/d3-format/locale/de-CH.json new file mode 100644 index 0000000..874bb56 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/de-CH.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": "'", + "grouping": [3], + "currency": ["", "\u00a0CHF"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/de-DE.json b/inst/htmlwidgets/lib/d3-format/locale/de-DE.json new file mode 100644 index 0000000..a249762 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/de-DE.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": ".", + "grouping": [3], + "currency": ["", "\u00a0€"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/en-CA.json b/inst/htmlwidgets/lib/d3-format/locale/en-CA.json new file mode 100644 index 0000000..f075b86 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/en-CA.json @@ -0,0 +1,6 @@ +{ + "decimal": ".", + "thousands": ",", + "grouping": [3], + "currency": ["$", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/en-GB.json b/inst/htmlwidgets/lib/d3-format/locale/en-GB.json new file mode 100644 index 0000000..3d22d7a --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/en-GB.json @@ -0,0 +1,6 @@ +{ + "decimal": ".", + "thousands": ",", + "grouping": [3], + "currency": ["£", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/en-IE.json b/inst/htmlwidgets/lib/d3-format/locale/en-IE.json new file mode 100644 index 0000000..7d64415 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/en-IE.json @@ -0,0 +1,6 @@ +{ + "decimal": ".", + "thousands": ",", + "grouping": [3], + "currency": ["€", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/en-IN.json b/inst/htmlwidgets/lib/d3-format/locale/en-IN.json new file mode 100644 index 0000000..ada1510 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/en-IN.json @@ -0,0 +1,6 @@ +{ + "decimal": ".", + "thousands": ",", + "grouping": [3, 2, 2, 2, 2, 2, 2, 2, 2, 2], + "currency": ["₹", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/en-US.json b/inst/htmlwidgets/lib/d3-format/locale/en-US.json new file mode 100644 index 0000000..f075b86 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/en-US.json @@ -0,0 +1,6 @@ +{ + "decimal": ".", + "thousands": ",", + "grouping": [3], + "currency": ["$", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/es-BO.json b/inst/htmlwidgets/lib/d3-format/locale/es-BO.json new file mode 100644 index 0000000..98fe646 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/es-BO.json @@ -0,0 +1,7 @@ +{ + "decimal": ",", + "thousands": ".", + "grouping": [3], + "currency": ["Bs\u00a0", ""], + "percent": "\u202f%" +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/es-ES.json b/inst/htmlwidgets/lib/d3-format/locale/es-ES.json new file mode 100644 index 0000000..a249762 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/es-ES.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": ".", + "grouping": [3], + "currency": ["", "\u00a0€"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/es-MX.json b/inst/htmlwidgets/lib/d3-format/locale/es-MX.json new file mode 100644 index 0000000..f075b86 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/es-MX.json @@ -0,0 +1,6 @@ +{ + "decimal": ".", + "thousands": ",", + "grouping": [3], + "currency": ["$", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/fi-FI.json b/inst/htmlwidgets/lib/d3-format/locale/fi-FI.json new file mode 100644 index 0000000..e2218ec --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/fi-FI.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": "\u00a0", + "grouping": [3], + "currency": ["", "\u00a0€"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/fr-CA.json b/inst/htmlwidgets/lib/d3-format/locale/fr-CA.json new file mode 100644 index 0000000..0d927b9 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/fr-CA.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": "\u00a0", + "grouping": [3], + "currency": ["", "$"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/fr-FR.json b/inst/htmlwidgets/lib/d3-format/locale/fr-FR.json new file mode 100644 index 0000000..e0cf89d --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/fr-FR.json @@ -0,0 +1,7 @@ +{ + "decimal": ",", + "thousands": "\u00a0", + "grouping": [3], + "currency": ["", "\u00a0€"], + "percent": "\u202f%" +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/he-IL.json b/inst/htmlwidgets/lib/d3-format/locale/he-IL.json new file mode 100644 index 0000000..23926cb --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/he-IL.json @@ -0,0 +1,6 @@ +{ + "decimal": ".", + "thousands": ",", + "grouping": [3], + "currency": ["₪", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/hu-HU.json b/inst/htmlwidgets/lib/d3-format/locale/hu-HU.json new file mode 100644 index 0000000..1baff74 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/hu-HU.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": "\u00a0", + "grouping": [3], + "currency": ["", "\u00a0Ft"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/it-IT.json b/inst/htmlwidgets/lib/d3-format/locale/it-IT.json new file mode 100644 index 0000000..564ed46 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/it-IT.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": ".", + "grouping": [3], + "currency": ["€", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ja-JP.json b/inst/htmlwidgets/lib/d3-format/locale/ja-JP.json new file mode 100644 index 0000000..fdcba6c --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ja-JP.json @@ -0,0 +1,6 @@ +{ + "decimal": ".", + "thousands": ",", + "grouping": [3], + "currency": ["", "円"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ko-KR.json b/inst/htmlwidgets/lib/d3-format/locale/ko-KR.json new file mode 100644 index 0000000..d1d882c --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ko-KR.json @@ -0,0 +1,6 @@ +{ + "decimal": ".", + "thousands": ",", + "grouping": [3], + "currency": ["₩", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/mk-MK.json b/inst/htmlwidgets/lib/d3-format/locale/mk-MK.json new file mode 100644 index 0000000..33528b8 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/mk-MK.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": ".", + "grouping": [3], + "currency": ["", "\u00a0ден."] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/nl-NL.json b/inst/htmlwidgets/lib/d3-format/locale/nl-NL.json new file mode 100644 index 0000000..7176b37 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/nl-NL.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": ".", + "grouping": [3], + "currency": ["€\u00a0", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/pl-PL.json b/inst/htmlwidgets/lib/d3-format/locale/pl-PL.json new file mode 100644 index 0000000..12c673f --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/pl-PL.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": ".", + "grouping": [3], + "currency": ["", "zł"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/pt-BR.json b/inst/htmlwidgets/lib/d3-format/locale/pt-BR.json new file mode 100644 index 0000000..e6705f1 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/pt-BR.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": ".", + "grouping": [3], + "currency": ["R$", ""] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/ru-RU.json b/inst/htmlwidgets/lib/d3-format/locale/ru-RU.json new file mode 100644 index 0000000..3b0acf6 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/ru-RU.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": "\u00a0", + "grouping": [3], + "currency": ["", "\u00a0руб."] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/sv-SE.json b/inst/htmlwidgets/lib/d3-format/locale/sv-SE.json new file mode 100644 index 0000000..870eba3 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/sv-SE.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": "\u00a0", + "grouping": [3], + "currency": ["", " kr"] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/uk-UA.json b/inst/htmlwidgets/lib/d3-format/locale/uk-UA.json new file mode 100644 index 0000000..75cee2d --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/uk-UA.json @@ -0,0 +1,6 @@ +{ + "decimal": ",", + "thousands": "\u00a0", + "grouping": [3], + "currency": ["", "\u00a0₴."] +} diff --git a/inst/htmlwidgets/lib/d3-format/locale/zh-CN.json b/inst/htmlwidgets/lib/d3-format/locale/zh-CN.json new file mode 100644 index 0000000..1ffc7b6 --- /dev/null +++ b/inst/htmlwidgets/lib/d3-format/locale/zh-CN.json @@ -0,0 +1,6 @@ +{ + "decimal": ".", + "thousands": ",", + "grouping": [3], + "currency": ["¥", ""] +} diff --git a/inst/htmlwidgets/lib/numeral/numeral.min.js b/inst/htmlwidgets/lib/numeral/numeral.min.js deleted file mode 100644 index b721f54..0000000 --- a/inst/htmlwidgets/lib/numeral/numeral.min.js +++ /dev/null @@ -1,8 +0,0 @@ -/*! @preserve - * numeral.js - * version : 2.0.6 - * author : Adam Draper - * license : MIT - * http://adamwdraper.github.com/Numeral-js/ - */ -!function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof module&&module.exports?module.exports=b():a.numeral=b()}(this,function(){function a(a,b){this._input=a,this._value=b}var b,c,d="2.0.6",e={},f={},g={currentLocale:"en",zeroFormat:null,nullFormat:null,defaultFormat:"0,0",scalePercentBy100:!0},h={currentLocale:g.currentLocale,zeroFormat:g.zeroFormat,nullFormat:g.nullFormat,defaultFormat:g.defaultFormat,scalePercentBy100:g.scalePercentBy100};return b=function(d){var f,g,i,j;if(b.isNumeral(d))f=d.value();else if(0===d||"undefined"==typeof d)f=0;else if(null===d||c.isNaN(d))f=null;else if("string"==typeof d)if(h.zeroFormat&&d===h.zeroFormat)f=0;else if(h.nullFormat&&d===h.nullFormat||!d.replace(/[^0-9]+/g,"").length)f=null;else{for(g in e)if(j="function"==typeof e[g].regexps.unformat?e[g].regexps.unformat():e[g].regexps.unformat,j&&d.match(j)){i=e[g].unformat;break}i=i||b._.stringToNumber,f=i(d)}else f=Number(d)||null;return new a(d,f)},b.version=d,b.isNumeral=function(b){return b instanceof a},b._=c={numberToFormat:function(a,c,d){var e,g,h,i,j,k,l,m=f[b.options.currentLocale],n=!1,o=!1,p=0,q="",r=1e12,s=1e9,t=1e6,u=1e3,v="",w=!1;if(a=a||0,g=Math.abs(a),b._.includes(c,"(")?(n=!0,c=c.replace(/[\(|\)]/g,"")):(b._.includes(c,"+")||b._.includes(c,"-"))&&(j=b._.includes(c,"+")?c.indexOf("+"):0>a?c.indexOf("-"):-1,c=c.replace(/[\+|\-]/g,"")),b._.includes(c,"a")&&(e=c.match(/a(k|m|b|t)?/),e=e?e[1]:!1,b._.includes(c," a")&&(q=" "),c=c.replace(new RegExp(q+"a[kmbt]?"),""),g>=r&&!e||"t"===e?(q+=m.abbreviations.trillion,a/=r):r>g&&g>=s&&!e||"b"===e?(q+=m.abbreviations.billion,a/=s):s>g&&g>=t&&!e||"m"===e?(q+=m.abbreviations.million,a/=t):(t>g&&g>=u&&!e||"k"===e)&&(q+=m.abbreviations.thousand,a/=u)),b._.includes(c,"[.]")&&(o=!0,c=c.replace("[.]",".")),h=a.toString().split(".")[0],i=c.split(".")[1],k=c.indexOf(","),p=(c.split(".")[0].split(",")[0].match(/0/g)||[]).length,i?(b._.includes(i,"[")?(i=i.replace("]",""),i=i.split("["),v=b._.toFixed(a,i[0].length+i[1].length,d,i[1].length)):v=b._.toFixed(a,i.length,d),h=v.split(".")[0],v=b._.includes(v,".")?m.delimiters.decimal+v.split(".")[1]:"",o&&0===Number(v.slice(1))&&(v="")):h=b._.toFixed(a,0,d),q&&!e&&Number(h)>=1e3&&q!==m.abbreviations.trillion)switch(h=String(Number(h)/1e3),q){case m.abbreviations.thousand:q=m.abbreviations.million;break;case m.abbreviations.million:q=m.abbreviations.billion;break;case m.abbreviations.billion:q=m.abbreviations.trillion}if(b._.includes(h,"-")&&(h=h.slice(1),w=!0),h.length0;x--)h="0"+h;return k>-1&&(h=h.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+m.delimiters.thousands)),0===c.indexOf(".")&&(h=""),l=h+v+(q?q:""),n?l=(n&&w?"(":"")+l+(n&&w?")":""):j>=0?l=0===j?(w?"-":"+")+l:l+(w?"-":"+"):w&&(l="-"+l),l},stringToNumber:function(a){var b,c,d,e=f[h.currentLocale],g=a,i={thousand:3,million:6,billion:9,trillion:12};if(h.zeroFormat&&a===h.zeroFormat)c=0;else if(h.nullFormat&&a===h.nullFormat||!a.replace(/[^0-9]+/g,"").length)c=null;else{c=1,"."!==e.delimiters.decimal&&(a=a.replace(/\./g,"").replace(e.delimiters.decimal,"."));for(b in i)if(d=new RegExp("[^a-zA-Z]"+e.abbreviations[b]+"(?:\\)|(\\"+e.currency.symbol+")?(?:\\))?)?$"),g.match(d)){c*=Math.pow(10,i[b]);break}c*=(a.split("-").length+Math.min(a.split("(").length-1,a.split(")").length-1))%2?1:-1,a=a.replace(/[^0-9\.]+/g,""),c*=Number(a)}return c},isNaN:function(a){return"number"==typeof a&&isNaN(a)},includes:function(a,b){return-1!==a.indexOf(b)},insert:function(a,b,c){return a.slice(0,c)+b+a.slice(c)},reduce:function(a,b){if(null===this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof b)throw new TypeError(b+" is not a function");var c,d=Object(a),e=d.length>>>0,f=0;if(3===arguments.length)c=arguments[2];else{for(;e>f&&!(f in d);)f++;if(f>=e)throw new TypeError("Reduce of empty array with no initial value");c=d[f++]}for(;e>f;f++)f in d&&(c=b(c,d[f],f,d));return c},multiplier:function(a){var b=a.toString().split(".");return b.length<2?1:Math.pow(10,b[1].length)},correctionFactor:function(){var a=Array.prototype.slice.call(arguments);return a.reduce(function(a,b){var d=c.multiplier(b);return a>d?a:d},1)},toFixed:function(a,b,c,d){var e,f,g,h,i=a.toString().split("."),j=b-(d||0);return e=2===i.length?Math.min(Math.max(i[1].length,j),b):j,g=Math.pow(10,e),h=(c(a+"e+"+e)/g).toFixed(e),d>b-e&&(f=new RegExp("\\.?0{1,"+(d-(b-e))+"}$"),h=h.replace(f,"")),h}},b.options=h,b.formats=e,b.locales=f,b.locale=function(a){return a&&(h.currentLocale=a.toLowerCase()),h.currentLocale},b.localeData=function(a){if(!a)return f[h.currentLocale];if(a=a.toLowerCase(),!f[a])throw new Error("Unknown locale : "+a);return f[a]},b.reset=function(){for(var a in g)h[a]=g[a]},b.zeroFormat=function(a){h.zeroFormat="string"==typeof a?a:null},b.nullFormat=function(a){h.nullFormat="string"==typeof a?a:null},b.defaultFormat=function(a){h.defaultFormat="string"==typeof a?a:"0.0"},b.register=function(a,b,c){if(b=b.toLowerCase(),this[a+"s"][b])throw new TypeError(b+" "+a+" already registered.");return this[a+"s"][b]=c,c},b.validate=function(a,c){var d,e,f,g,h,i,j,k;if("string"!=typeof a&&(a+="",console.warn&&console.warn("Numeral.js: Value is not string. It has been co-erced to: ",a)),a=a.trim(),a.match(/^\d+$/))return!0;if(""===a)return!1;try{j=b.localeData(c)}catch(l){j=b.localeData(b.locale())}return f=j.currency.symbol,h=j.abbreviations,d=j.delimiters.decimal,e="."===j.delimiters.thousands?"\\.":j.delimiters.thousands,k=a.match(/^[^\d]+/),null!==k&&(a=a.substr(1),k[0]!==f)?!1:(k=a.match(/[^\d]+$/),null!==k&&(a=a.slice(0,-1),k[0]!==h.thousand&&k[0]!==h.million&&k[0]!==h.billion&&k[0]!==h.trillion)?!1:(i=new RegExp(e+"{2}"),a.match(/[^\d.,]/g)?!1:(g=a.split(d),g.length>2?!1:g.length<2?!!g[0].match(/^\d+.*\d$/)&&!g[0].match(i):1===g[0].length?!!g[0].match(/^\d+$/)&&!g[0].match(i)&&!!g[1].match(/^\d+$/):!!g[0].match(/^\d+.*\d$/)&&!g[0].match(i)&&!!g[1].match(/^\d+$/))))},b.fn=a.prototype={clone:function(){return b(this)},format:function(a,c){var d,f,g,i=this._value,j=a||h.defaultFormat;if(c=c||Math.round,0===i&&null!==h.zeroFormat)f=h.zeroFormat;else if(null===i&&null!==h.nullFormat)f=h.nullFormat;else{for(d in e)if(j.match(e[d].regexps.format)){g=e[d].format;break}g=g||b._.numberToFormat,f=g(i,j,c)}return f},value:function(){return this._value},input:function(){return this._input},set:function(a){return this._value=Number(a),this},add:function(a){function b(a,b,c,e){return a+Math.round(d*b)}var d=c.correctionFactor.call(null,this._value,a);return this._value=c.reduce([this._value,a],b,0)/d,this},subtract:function(a){function b(a,b,c,e){return a-Math.round(d*b)}var d=c.correctionFactor.call(null,this._value,a);return this._value=c.reduce([a],b,Math.round(this._value*d))/d,this},multiply:function(a){function b(a,b,d,e){var f=c.correctionFactor(a,b);return Math.round(a*f)*Math.round(b*f)/Math.round(f*f)}return this._value=c.reduce([this._value,a],b,1),this},divide:function(a){function b(a,b,d,e){var f=c.correctionFactor(a,b);return Math.round(a*f)/Math.round(b*f)}return this._value=c.reduce([this._value,a],b),this},difference:function(a){return Math.abs(b(this._value).subtract(a).value())}},b.register("locale","en",{delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===~~(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th"},currency:{symbol:"$"}}),function(){b.register("format","bps",{regexps:{format:/(BPS)/,unformat:/(BPS)/},format:function(a,c,d){var e,f=b._.includes(c," BPS")?" ":"";return a=1e4*a,c=c.replace(/\s?BPS/,""),e=b._.numberToFormat(a,c,d),b._.includes(e,")")?(e=e.split(""),e.splice(-1,0,f+"BPS"),e=e.join("")):e=e+f+"BPS",e},unformat:function(a){return+(1e-4*b._.stringToNumber(a)).toFixed(15)}})}(),function(){var a={base:1e3,suffixes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]},c={base:1024,suffixes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},d=a.suffixes.concat(c.suffixes.filter(function(b){return a.suffixes.indexOf(b)<0})),e=d.join("|");e="("+e.replace("B","B(?!PS)")+")",b.register("format","bytes",{regexps:{format:/([0\s]i?b)/,unformat:new RegExp(e)},format:function(d,e,f){var g,h,i,j,k=b._.includes(e,"ib")?c:a,l=b._.includes(e," b")||b._.includes(e," ib")?" ":"";for(e=e.replace(/\s?i?b/,""),h=0;h<=k.suffixes.length;h++)if(i=Math.pow(k.base,h),j=Math.pow(k.base,h+1),null===d||0===d||d>=i&&j>d){l+=k.suffixes[h],i>0&&(d/=i);break}return g=b._.numberToFormat(d,e,f),g+l},unformat:function(d){var e,f,g=b._.stringToNumber(d);if(g){for(e=a.suffixes.length-1;e>=0;e--){if(b._.includes(d,a.suffixes[e])){f=Math.pow(a.base,e);break}if(b._.includes(d,c.suffixes[e])){f=Math.pow(c.base,e);break}}g*=f||1}return g}})}(),function(){b.register("format","currency",{regexps:{format:/(\$)/},format:function(a,c,d){var e,f,g,h=b.locales[b.options.currentLocale],i={before:c.match(/^([\+|\-|\(|\s|\$]*)/)[0],after:c.match(/([\+|\-|\)|\s|\$]*)$/)[0]};for(c=c.replace(/\s?\$\s?/,""),e=b._.numberToFormat(a,c,d),a>=0?(i.before=i.before.replace(/[\-\(]/,""),i.after=i.after.replace(/[\-\)]/,"")):0>a&&!b._.includes(i.before,"-")&&!b._.includes(i.before,"(")&&(i.before="-"+i.before),g=0;g=0;g--)switch(f=i.after[g]){case"$":e=g===i.after.length-1?e+h.currency.symbol:b._.insert(e,h.currency.symbol,-(i.after.length-(1+g)));break;case" ":e=g===i.after.length-1?e+" ":b._.insert(e," ",-(i.after.length-(1+g)+h.currency.symbol.length-1))}return e}})}(),function(){b.register("format","exponential",{regexps:{format:/(e\+|e-)/,unformat:/(e\+|e-)/},format:function(a,c,d){var e,f="number"!=typeof a||b._.isNaN(a)?"0e+0":a.toExponential(),g=f.split("e");return c=c.replace(/e[\+|\-]{1}0/,""),e=b._.numberToFormat(Number(g[0]),c,d),e+"e"+g[1]},unformat:function(a){function c(a,c,d,e){var f=b._.correctionFactor(a,c),g=a*f*(c*f)/(f*f);return g}var d=b._.includes(a,"e+")?a.split("e+"):a.split("e-"),e=Number(d[0]),f=Number(d[1]);return f=b._.includes(a,"e-")?f*=-1:f,b._.reduce([e,Math.pow(10,f)],c,1)}})}(),function(){b.register("format","ordinal",{regexps:{format:/(o)/},format:function(a,c,d){var e,f=b.locales[b.options.currentLocale],g=b._.includes(c," o")?" ":"";return c=c.replace(/\s?o/,""),g+=f.ordinal(a),e=b._.numberToFormat(a,c,d),e+g}})}(),function(){b.register("format","percentage",{regexps:{format:/(%)/,unformat:/(%)/},format:function(a,c,d){var e,f=b._.includes(c," %")?" ":"";return b.options.scalePercentBy100&&(a=100*a),c=c.replace(/\s?\%/,""),e=b._.numberToFormat(a,c,d),b._.includes(e,")")?(e=e.split(""),e.splice(-1,0,f+"%"),e=e.join("")):e=e+f+"%",e},unformat:function(a){var c=b._.stringToNumber(a);return b.options.scalePercentBy100?.01*c:c}})}(),function(){b.register("format","time",{regexps:{format:/(:)/,unformat:/(:)/},format:function(a,b,c){var d=Math.floor(a/60/60),e=Math.floor((a-60*d*60)/60),f=Math.round(a-60*d*60-60*e);return d+":"+(10>e?"0"+e:e)+":"+(10>f?"0"+f:f)},unformat:function(a){var b=a.split(":"),c=0;return 3===b.length?(c+=60*Number(b[0])*60,c+=60*Number(b[1]),c+=Number(b[2])):2===b.length&&(c+=60*Number(b[0]),c+=Number(b[1])),Number(c)}})}(),b}); \ No newline at end of file diff --git a/man/format_num.Rd b/man/format_num.Rd new file mode 100644 index 0000000..90ce8b8 --- /dev/null +++ b/man/format_num.Rd @@ -0,0 +1,75 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/format.R +\name{format_num} +\alias{format_num} +\title{Format numbers (with D3)} +\usage{ +format_num(format, locale = "en-US") +} +\arguments{ +\item{format}{Format for numbers, currency, percentage, e.g. \code{".0\%"} for rounded percentage. +See online documentation : \url{https://github.com/d3/d3-format}.} + +\item{locale}{Localization to use, for exemple \code{"fr-FR"} for french, +see possible values here: \url{https://github.com/d3/d3-format/tree/master/locale}.} +} +\value{ +a \code{JS} function +} +\description{ +Format numbers (with D3) +} +\examples{ +# Use SI prefix +dat <- data.frame( + labels = c("apex", "charts"), + values = c(1e4, 2e4) +) + +apex(dat, aes(labels, values), "column") \%>\% + ax_yaxis(labels = list( + formatter = format_num("~s") + )) + +apex(dat, aes(labels, values * 100), "column") \%>\% + ax_yaxis(labels = list( + formatter = format_num("~s") + )) + + +# Percentage +dat <- data.frame( + labels = c("apex", "charts"), + values = c(0.45, 0.55) +) + +apex(dat, aes(labels, values), "column") \%>\% + ax_yaxis(labels = list( + formatter = format_num(".0\%") + )) + + +# Currency +dat <- data.frame( + labels = c("apex", "charts"), + values = c(570, 1170) +) + +apex(dat, aes(labels, values), "column") \%>\% + ax_yaxis(labels = list( + formatter = format_num("$,.2f") + )) + + +# Change locale +apex(dat, aes(labels, values), "column") \%>\% + ax_yaxis(labels = list( + formatter = format_num("$,.2f", "fr-FR") + )) + + + + + + +}