locales files for apexcharts

This commit is contained in:
pvictor 2019-11-26 14:44:59 +01:00
parent 4f2e8af93e
commit 2513bc5fdf
22 changed files with 436 additions and 33 deletions

View File

@ -1,5 +1,5 @@
Package: apexcharter
Version: 0.1.2.920
Version: 0.1.2.930
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.
@ -18,7 +18,8 @@ Imports:
magrittr,
rlang,
ggplot2,
scales
scales,
jsonlite
Suggests:
testthat,
dplyr,

View File

@ -2,7 +2,8 @@ apexcharter 0.1.3
==================
* Upgraded ApexCharts.js to 3.10.1
* New function `format_num()` to format labels on y-axis for example.
* New function `format_num()` to format labels on y-axis or tooltip for example.
* Added localization configs file, see `?ax_chart` for examples.

View File

@ -134,7 +134,12 @@ ax_annotations <- function(ax,
#' @param type Specify the chart type. Available Options: \code{"bar"}, \code{"column"}, \code{"line"},
#' \code{"pie"}, \code{"donut"}, \code{"radialBar"}, \code{"scatter"}, \code{"bubble"}, \code{"heatmap"}.
#' @param stacked Logical. Enables stacked option for axis charts.
#' @param stackType When stacked, should the stacking be percentage based or normal stacking. Available options: \code{"normal"} or \code{"100\%"}
#' @param stackType When stacked, should the stacking be percentage based or normal stacking.
#' Available options: \code{"normal"} or \code{"100\%"}.
#' @param defaultLocale Locale to use : \code{"de"}, \code{"el"}, \code{"en"}, \code{"es"}, \code{"fr"},
#' \code{"hi"}, \code{"hr"}, \code{"hy"}, \code{"id"}, \code{"it"}, \code{"ko"}, \code{"pt-br"},
#' \code{"ru"}, \code{"tr"}, \code{"ua"}.
#' @param locales Array of custom localizations paremeters.
#' @param animations A list of parameters.
#' @param background Background color for the chart area. If you want to set background with css, use \code{.apexcharts-canvas} to set it.
#' @param foreColor Sets the text color for the chart. Defaults to \code{#373d3f}.
@ -153,34 +158,14 @@ ax_annotations <- function(ax,
#' @return A \code{apexcharts} \code{htmlwidget} object.
#' @export
#'
#' @examples
#' library(dplyr)
#' data("diamonds", package = "ggplot2")
#'
#' # Stack bar type
#' apex(
#' data = count(diamonds, cut, color),
#' mapping = aes(x = cut, y = n, fill = color)
#' ) %>%
#' ax_chart(stacked = TRUE)
#'
#' apex(
#' data = count(diamonds, cut, color),
#' mapping = aes(x = cut, y = n, fill = color)
#' ) %>%
#' ax_chart(stacked = TRUE, stackType = "100%")
#'
#'
#' # Toolbar
#' apex(
#' data = count(diamonds, cut, color),
#' mapping = aes(x = cut, y = n, fill = color)
#' ) %>%
#' ax_chart(toolbar = list(show = FALSE))
#' @example examples/ax_chart.R
#' @example examples/localization.R
ax_chart <- function(ax,
type = NULL,
stacked = NULL,
stackType = NULL,
defaultLocale = NULL,
locales = NULL,
animations = NULL,
background = NULL,
foreColor = NULL,

View File

@ -14,7 +14,7 @@
#'
#' @example examples/apexchart.R
apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height = NULL, elementId = NULL) {
# forward options using x
x <- list(
ax_opts = ax_opts,
@ -29,6 +29,24 @@ apexchart <- function(ax_opts = list(), auto_update = TRUE, width = NULL, height
height = height,
package = 'apexcharter',
elementId = elementId,
preRenderHook = function(widget) {
if (!is.null(widget$x$ax_opts$chart$defaultLocale)) {
defaultLocale <- widget$x$ax_opts$chart$defaultLocale
defaultLocale <- match.arg(
arg = defaultLocale,
choices = c("de", "el", "en", "es", "fr", "hi", "hr", "hy", "id", "it",
"ko.js", "pt-br", "ru", "tr", "ua")
)
if (!is.null(widget$x$ax_opts$chart$locales)) {
warning("defaultLocale is used but will be ignored since a custom array for locales is provided.")
} else {
path <- system.file(file.path("htmlwidgets/lib/apexcharts-locales", paste0(defaultLocale, ".json")), package = "apexcharter")
locale <- jsonlite::fromJSON(txt = path)
widget$x$ax_opts$chart$locales <- list(locale)
}
}
widget
},
sizingPolicy = htmlwidgets::sizingPolicy(
defaultWidth = "100%",
defaultHeight = "100%",

26
examples/ax_chart.R Normal file
View File

@ -0,0 +1,26 @@
library(dplyr)
data("diamonds", package = "ggplot2")
# Stack bar type
apex(
data = count(diamonds, cut, color),
mapping = aes(x = cut, y = n, fill = color)
) %>%
ax_chart(stacked = TRUE)
apex(
data = count(diamonds, cut, color),
mapping = aes(x = cut, y = n, fill = color)
) %>%
ax_chart(stacked = TRUE, stackType = "100%")
# Toolbar
apex(
data = count(diamonds, cut, color),
mapping = aes(x = cut, y = n, fill = color)
) %>%
ax_chart(toolbar = list(show = FALSE))

30
examples/localization.R Normal file
View File

@ -0,0 +1,30 @@
# Use included localization config
dat <- data.frame(
x = Sys.Date() + 1:20,
y = sample.int(20, 20)
)
# French
apex(dat, aes(x, y), "line") %>%
ax_chart(defaultLocale = "fr")
# Italian
apex(dat, aes(x, y), "line") %>%
ax_chart(defaultLocale = "it")
# Custom config
apex(dat, aes(x, y), "line") %>%
ax_chart(locales = list(
list(
name = "en", # override en locale
options = list(
toolbar = list(
exportToSVG = "GET SVG",
exportToPNG = "GET PNG"
)
)
)
))

View File

@ -0,0 +1,20 @@
{
"name": "de",
"options": {
"months": ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
"shortMonths": ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
"days": ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
"shortDays": ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
"toolbar": {
"exportToSVG": "SVG speichern",
"exportToPNG": "PNG speichern",
"menu": "Menü",
"selection": "Auswahl",
"selectionZoom": "Auswahl vergrößern",
"zoomIn": "Vergrößern",
"zoomOut": "Verkleinern",
"pan": "Verschieben",
"reset": "Zoom zurücksetzen"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "el",
"options": {
"months": ["Ιανουάριος", "Φεβρουάριος", "Μάρτιος", "Απρίλιος", "Μάιος", "Ιούνιος", "Ιούλιος", "Αύγουστος", "Σεπτέμβριος", "Οκτώβριος", "Νοέμβριος", "Δεκέμβριος"],
"shortMonths": ["Ιαν", "Φευ", "Μαρ", "Απρ", "Μάι", "Ιουν", "Ιουλ", "Αυγ", "Σεπ", "Οκτ", "Νοε", "Δεκ"],
"days": ["Κυριακή", "Δευτέρα", "Τρίτη", "Τετάρτη", "Πέμπτη", "Παρασκευή", "Σάββατο"],
"shortDays": ["Κυρ", "Δευ", "Τρι", "Τετ", "Πεμ", "Παρ", "Σαβ"],
"toolbar": {
"exportToSVG": "Λήψη SVG",
"exportToPNG": "Λήψη PNG",
"menu": "Menu",
"selection": "Επιλογή",
"selectionZoom": "Μεγένθυση βάση επιλογής",
"zoomIn": "Μεγένθυνση",
"zoomOut": "Σμίκρυνση",
"pan": "Μετατόπιση",
"reset": "Επαναφορά μεγένθυνσης"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "en",
"options": {
"months": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
"shortMonths": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
"days": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
"shortDays": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
"toolbar": {
"exportToSVG": "Download SVG",
"exportToPNG": "Download PNG",
"menu": "Menu",
"selection": "Selection",
"selectionZoom": "Selection Zoom",
"zoomIn": "Zoom In",
"zoomOut": "Zoom Out",
"pan": "Panning",
"reset": "Reset Zoom"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "es",
"options": {
"months": ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"],
"shortMonths": ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"],
"days": ["Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"],
"shortDays": ["Dom", "Lun", "Mar", "Mie", "Jue", "Vie", "Sab"],
"toolbar": {
"exportToSVG": "Descargar SVG",
"exportToPNG": "Descargar PNG",
"menu": "Menu",
"selection": "Seleccionar",
"selectionZoom": "Seleccionar Zoom",
"zoomIn": "Aumentar",
"zoomOut": "Disminuir",
"pan": "Navegación",
"reset": "Reiniciar Zoom"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "fr",
"options": {
"months": ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"],
"shortMonths": ["janv.", "févr.", "mars", "avr.", "mai", "juin", "juill.", "août", "sept.", "oct.", "nov.", "déc."],
"days": ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
"shortDays": ["dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam."],
"toolbar": {
"exportToSVG": "Télécharger au format SVG",
"exportToPNG": "Télécharger au format PNG",
"menu": "Menu",
"selection": "Sélection",
"selectionZoom": "Sélection et zoom",
"zoomIn": "Zoomer",
"zoomOut": "Dézoomer",
"pan": "Navigation",
"reset": "Réinitialiser le zoom"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "hi",
"options": {
"months": ["जनवरी", "फ़रवरी", "मार्च", "अप्रैल", "मई", "जून", "जुलाई", "अगस्त", "सितंबर", "अक्टूबर", "नवंबर", "दिसंबर"],
"shortMonths": ["जनवरी", "फ़रवरी", "मार्च", "अप्रैल", "मई", "जून", "जुलाई", "अगस्त", "सितंबर", "अक्टूबर", "नवंबर", "दिसंबर"],
"days": ["रविवार", "सोमवार", "मंगलवार", "बुधवार", "गुरुवार", "शुक्रवार", "शनिवार"],
"shortDays": ["रवि", "सोम", "मंगल", "बुध", "गुरु", "शुक्र", "शनि"],
"toolbar": {
"exportToSVG": "निर्यात SVG",
"exportToPNG": "निर्यात PNG",
"menu": "सूची",
"selection": "चयन",
"selectionZoom": "ज़ूम करना",
"zoomIn": "ज़ूम इन",
"zoomOut": "ज़ूम आउट",
"pan": "पैनिंग",
"reset": "फिर से कायम करना"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "hr",
"options": {
"months": ["Siječanj", "Veljača", "Ožujak", "Travanj", "Svibanj", "Lipanj", "Srpanj", "Kolovoz", "Rujan", "Listopad", "Studeni", "Prosinac"],
"shortMonths": ["Sij", "Velj", "Ožu", "Tra", "Svi", "Lip", "Srp", "Kol", "Ruj", "Lis", "Stu", "Pro"],
"days": ["Nedjelja", "Ponedjeljak", "Utorak", "Srijeda", "Četvrtak", "Petak", "Subota"],
"shortDays": ["Ned", "Pon", "Uto", "Sri", "Čet", "Pet", "Sub"],
"toolbar": {
"exportToSVG": "Preuzmi SVG",
"exportToPNG": "Preuzmi PNG",
"menu": "Izbornik",
"selection": "Odabir",
"selectionZoom": "Odabirno povećanje",
"zoomIn": "Uvećajte prikaz",
"zoomOut": "Umanjite prikaz",
"pan": "Pomicanje",
"reset": "Povratak na zadani prikaz"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "hy",
"options": {
"months": ["Հունվար", "Փետրվար", "Մարտ", "Ապրիլ", "Մայիս", "Հունիս", "Հուլիս", "Օգոստոս", "Սեպտեմբեր", "Հոկտեմբեր", "Նոյեմբեր", "Դեկտեմբեր"],
"shortMonths": ["Հնվ", "Փտվ", "Մրտ", "Ապր", "Մյս", "Հնս", "Հլիս", "Օգս", "Սեպ", "Հոկ", "Նոյ", "Դեկ"],
"days": ["Կիրակի", "Երկուշաբթի", "Երեքշաբթի", "Չորեքշաբթի", "Հինգշաբթի", "Ուրբաթ", "Շաբաթ"],
"shortDays": ["Կիր", "Երկ", "Երք", "Չրք", "Հնգ", "Ուրբ", "Շբթ"],
"toolbar": {
"exportToSVG": "Բեռնել SVG",
"exportToPNG": "Բեռնել PNG",
"menu": "Մենյու",
"selection": "Ընտրված",
"selectionZoom": "Ընտրված հատվածի խոշորացում",
"zoomIn": "Խոշորացնել",
"zoomOut": "Մանրացնել",
"pan": "Տեղափոխում",
"reset": "Բերել սկզբնական վիճակի"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "id",
"options": {
"months": ["Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"],
"shortMonths": ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des"],
"days": ["Minggu", "Senin", "Selasa", "Rabu", "kamis", "Jumat", "Sabtu"],
"shortDays": ["Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"],
"toolbar": {
"exportToSVG": "Unduh SVG",
"exportToPNG": "Unduh PNG",
"menu": "Menu",
"selection": "Pilihan",
"selectionZoom": "Perbesar Pilihan",
"zoomIn": "Perbesar",
"zoomOut": "Perkecil",
"pan": "Geser",
"reset": "Atur Ulang Zoom"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "it",
"options": {
"months": ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"],
"shortMonths": ["Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"],
"days": ["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato"],
"shortDays": ["Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"],
"toolbar": {
"exportToSVG": "Scarica SVG",
"exportToPNG": "Scarica PNG",
"menu": "Menu",
"selection": "Selezione",
"selectionZoom": "Seleziona Zoom",
"zoomIn": "Zoom In",
"zoomOut": "Zoom Out",
"pan": "Sposta",
"reset": "Reimposta Zoom"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "ko",
"options": {
"months": ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"],
"shortMonths": ["1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"],
"days": ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"],
"shortDays": ["일", "월", "화", "수", "목", "금", "토"],
"toolbar": {
"exportToSVG": "SVG 다운로드",
"exportToPNG": "PNG 다운로드",
"menu": "메뉴",
"selection": "선택",
"selectionZoom": "선택영역 확대",
"zoomIn": "확대",
"zoomOut": "축소",
"pan": "패닝",
"reset": "원래대로"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "pt-br",
"options": {
"months": ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
"shortMonths": ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"],
"days": ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"],
"shortDays": ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"],
"toolbar": {
"exportToSVG": "Baixar SVG",
"exportToPNG": "Baixar PNG",
"menu": "Menu",
"selection": "Selecionar",
"selectionZoom": "Selecionar Zoom",
"zoomIn": "Aumentar",
"zoomOut": "Diminuir",
"pan": "Navegação",
"reset": "Reiniciar Zoom"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "ru",
"options": {
"months": ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
"shortMonths": ["Янв", "Фев", "Мар", "Апр", "Май", "Июн", "Июл", "Авг", "Сен", "Окт", "Ноя", "Дек"],
"days": ["Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота"],
"shortDays": ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"],
"toolbar": {
"exportToSVG": "Сохранить SVG",
"exportToPNG": "Сохранить PNG",
"menu": "Меню",
"selection": "Выбор",
"selectionZoom": "Выбор с увеличением",
"zoomIn": "Увеличить",
"zoomOut": "Уменьшить",
"pan": "Перемещение",
"reset": "Сбросить увеличение"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "tr",
"options": {
"months": ["Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"],
"shortMonths": ["Oca", "Şub", "Mar", "Nis", "May", "Haz", "Tem", "Ağu", "Eyl", "Eki", "Kas", "Ara"],
"days": ["Pazar", "Pazartesi", "Salı", "Çarşamba", "Perşembe", "Cuma", "Cumartesi"],
"shortDays": ["Paz", "Pzt", "Sal", "Çar", "Per", "Cum", "Cmt"],
"toolbar": {
"exportToSVG": "SVG İndir",
"exportToPNG": "PNG İndir",
"menu": "Menü",
"selection": "Seçim",
"selectionZoom": "Seçim Yakınlaştır",
"zoomIn": "Yakınlaştır",
"zoomOut": "Uzaklaştır",
"pan": "Kaydır",
"reset": "Yakınlaştırmayı Sıfırla"
}
}
}

View File

@ -0,0 +1,20 @@
{
"name": "ua",
"options": {
"months": ["Січень", "Лютий", "Березень", "Квітень", "Травень", "Червень", "Липень", "Серпень", "Вересень", "Жовтень", "Листопад", "Грудень"],
"shortMonths": ["Січ", "Лют", "Бер", "Кві", "Тра", "Чер", "Лип", "Сер", "Вер", "Жов", "Лис", "Гру"],
"days": ["Неділя", "Понеділок", "Вівторок", "Середа", "Четвер", "П'ятниця", "Субота"],
"shortDays": ["Нд", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"],
"toolbar": {
"exportToSVG": "Зберегти SVG",
"exportToPNG": "Зберегти PNG",
"menu": "Меню",
"selection": "Вибір",
"selectionZoom": "Вибір із збільшенням",
"zoomIn": "Збільшити",
"zoomOut": "Зменшити",
"pan": "Переміщення",
"reset": "Скинути збільшення"
}
}
}

View File

@ -9,6 +9,8 @@ ax_chart(
type = NULL,
stacked = NULL,
stackType = NULL,
defaultLocale = NULL,
locales = NULL,
animations = NULL,
background = NULL,
foreColor = NULL,
@ -33,7 +35,14 @@ ax_chart(
\item{stacked}{Logical. Enables stacked option for axis charts.}
\item{stackType}{When stacked, should the stacking be percentage based or normal stacking. Available options: \code{"normal"} or \code{"100\%"}}
\item{stackType}{When stacked, should the stacking be percentage based or normal stacking.
Available options: \code{"normal"} or \code{"100\%"}.}
\item{defaultLocale}{Locale to use : \code{"de"}, \code{"el"}, \code{"en"}, \code{"es"}, \code{"fr"},
\code{"hi"}, \code{"hr"}, \code{"hy"}, \code{"id"}, \code{"it"}, \code{"ko"}, \code{"pt-br"},
\code{"ru"}, \code{"tr"}, \code{"ua"}.}
\item{locales}{Array of custom localizations paremeters.}
\item{animations}{A list of parameters.}
@ -77,13 +86,13 @@ data("diamonds", package = "ggplot2")
apex(
data = count(diamonds, cut, color),
mapping = aes(x = cut, y = n, fill = color)
) \%>\%
) \%>\%
ax_chart(stacked = TRUE)
apex(
data = count(diamonds, cut, color),
mapping = aes(x = cut, y = n, fill = color)
) \%>\%
) \%>\%
ax_chart(stacked = TRUE, stackType = "100\%")
@ -91,6 +100,39 @@ apex(
apex(
data = count(diamonds, cut, color),
mapping = aes(x = cut, y = n, fill = color)
) \%>\%
) \%>\%
ax_chart(toolbar = list(show = FALSE))
# Use included localization config
dat <- data.frame(
x = Sys.Date() + 1:20,
y = sample.int(20, 20)
)
# French
apex(dat, aes(x, y), "line") \%>\%
ax_chart(defaultLocale = "fr")
# Italian
apex(dat, aes(x, y), "line") \%>\%
ax_chart(defaultLocale = "it")
# Custom config
apex(dat, aes(x, y), "line") \%>\%
ax_chart(locales = list(
list(
name = "en", # override en locale
options = list(
toolbar = list(
exportToSVG = "GET SVG",
exportToPNG = "GET PNG"
)
)
)
))
}