Skip to content

Commit

Permalink
More customizable legend bar and axis labels (#29)
Browse files Browse the repository at this point in the history
[1] Added font.size.legend argument for all charts with legend bar applicable, to help users better customize the legend bar.

[2] Added arguments font.size.axis.x, font.size.axis.y, rotate.axis.x, and rotate.axis.y for line charts, bar charts, and scatter plots. These arguments can help users better customize the charts.
  • Loading branch information
XD-DENG authored Jul 27, 2016
1 parent d285372 commit 9693daf
Show file tree
Hide file tree
Showing 7 changed files with 341 additions and 250 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Type: Package
Title: Embedding Charts Generated with ECharts Library into Shiny
Applications
Depends: shiny,jsonlite
Version: 0.1.4
Date: 2016-07-05
Version: 0.1.5
Date: 2016-07-27
Author: Xiaodong Deng
Maintainer: Xiaodong Deng <xd_deng@hotmail.com>
Description: With this package, users can embed interactive charts to their Shiny applications. These charts will be generated by ECharts library developed by Baidu (http://echarts.baidu.com/). Current version support line charts, bar charts, pie charts, scatter plots and gauge.
Expand Down
59 changes: 44 additions & 15 deletions R/renderCharts.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ renderPieChart <- function(div_id,
radius = "50%",
center_x = "50%", center_y = "50%",
show.legend = TRUE, show.tools = TRUE,
font.size.legend = 12,
running_in_shiny = TRUE){

data <- isolate(data)
Expand Down Expand Up @@ -86,7 +87,9 @@ renderPieChart <- function(div_id,

ifelse(show.legend,
paste("legend:{orient: 'vertical', left: 'left', data:",
legend_data, "},",
legend_data,
", textStyle:{fontSize:", font.size.legend, "}",
"},",
sep=""),
""),
"series : [{type: 'pie', radius:'", radius, "', center :['", center_x, "','", center_y, "'],",
Expand Down Expand Up @@ -129,6 +132,9 @@ renderBarChart <- function(div_id,
direction = "horizontal",
grid_left = "3%", grid_right = "4%", grid_top = "16%", grid_bottom = "3%",
show.legend = TRUE, show.tools = TRUE,
font.size.legend = 12,
font.size.axis.x = 12, font.size.axis.y = 12,
rotate.axis.x = 0, rotate.axis.y = 0,
running_in_shiny = TRUE){

data <- isolate(data)
Expand Down Expand Up @@ -188,14 +194,16 @@ renderBarChart <- function(div_id,

ifelse(show.legend,
paste("legend:{data:",
legend_name, "},",
legend_name,
", textStyle:{fontSize:", font.size.legend, "}",
"},",
sep=""),
""),
"grid: {left:'", grid_left, "', right:'", grid_right, "', top:'", grid_top, "', bottom:'", grid_bottom, "', containLabel: true},",
direction_vector[1],
":[{type:'value'}], ",
":[{type:'value', axisLabel:{rotate:", rotate.axis.y, ",textStyle:{fontSize:", font.size.axis.y, "}}}], ",
direction_vector[2],
":[{type:'category', axisTick:{show:false}, data:",
":[{type:'category', axisTick:{show:false}, axisLabel:{rotate:", rotate.axis.x, ",textStyle:{fontSize:", font.size.axis.x, "}}, data:",
xaxis_name,
"}],series :",
series_data,
Expand Down Expand Up @@ -234,6 +242,9 @@ renderLineChart <- function(div_id,
point.size = 5, point.type = "emptyCircle",
stack_plot = FALSE, step = "null",
show.legend = TRUE, show.tools = TRUE,
font.size.legend =12,
font.size.axis.x = 12, font.size.axis.y = 12,
rotate.axis.x = 0, rotate.axis.y = 0,
running_in_shiny = TRUE){

data <- isolate(data)
Expand Down Expand Up @@ -358,10 +369,12 @@ renderLineChart <- function(div_id,
ifelse(show.legend,
paste("legend:{data:",
legend_name,
", textStyle:{fontSize:", font.size.legend, "}",
"},",
sep=""),
""),
"yAxis: { type: 'value'}, xAxis:{type:'category', boundaryGap: false, data:",
"yAxis: { type: 'value', axisLabel:{rotate:",rotate.axis.y,",textStyle:{fontSize:", font.size.axis.y, "}}}, ",
"xAxis:{type:'category', boundaryGap: false, axisLabel:{rotate:", rotate.axis.x, ",textStyle:{fontSize:", font.size.axis.x, "}}, data:",
xaxis_name,
"}, series:[",
series_data,
Expand Down Expand Up @@ -457,6 +470,9 @@ renderScatter <- function(div_id, data,
point.size = 10, point.type = "circle",
theme = "default", auto.scale = TRUE,
show.legend = TRUE, show.tools = TRUE,
font.size.legend = 12,
font.size.axis.x = 12, font.size.axis.y = 12,
rotate.axis.x = 0, rotate.axis.y = 0,
running_in_shiny = TRUE){

data <- isolate(data)
Expand Down Expand Up @@ -553,26 +569,36 @@ renderScatter <- function(div_id, data,

ifelse(show.legend,
paste("legend:{data:",
legend_name, "},",
legend_name,
", textStyle:{fontSize:", font.size.legend, "}",
"},",
sep=""),
""),

ifelse(auto.scale,
"xAxis:[{type : 'value',scale:true}],yAxis:[{type : 'value',scale:true}],",
paste("xAxis:[{gridIndex: 0, min: ",
# min(data$x) - 0.03 * diff(range(data$x)),

paste("xAxis:[{type : 'value',scale:true, axisLabel:{rotate:",
rotate.axis.x,
",textStyle:{fontSize:",
font.size.axis.x,
"}}}],",
"yAxis:[{type : 'value',scale:true,axisLabel:{rotate:",
rotate.axis.y,
",textStyle:{fontSize:",
font.size.axis.y,
"}}}],", sep=""),

paste("xAxis:[{gridIndex: 0, axisLabel:{rotate:", rotate.axis.x, ",textStyle:{fontSize:", font.size.axis.x, "}}, min: ",
round(min(data$x) - 0.03 * diff(range(data$x)), 1) - 0.1,
", max: ",
# max(data$x) + 0.03 * diff(range(data$x)),
round(max(data$x) + 0.03 * diff(range(data$x)), 1) + 0.1,
"}],yAxis:[{gridIndex: 0, min: ",
# min(data$y) - 0.03 * diff(range(data$y)),
"}],yAxis:[{gridIndex: 0, axisLabel:{rotate:", rotate.axis.y, ",textStyle:{fontSize:", font.size.axis.y, "}}, min: ",
round(min(data$y) - 0.03 * diff(range(data$y)), 1) - 0.1,
", max: ",
# max(data$y) + 0.03 * diff(range(data$y)),
round(max(data$y) + 0.03 * diff(range(data$y)), 1) + 0.1,
"}],",
sep="")),
sep="")
),

"series :",
series_data,
Expand Down Expand Up @@ -611,6 +637,7 @@ renderRadarChart <- function(div_id,
data, theme = "default",
shape = "default", line.width = 2,
show.legend = TRUE, show.tools = TRUE,
font.size.legend = 12,
running_in_shiny = TRUE){

data <- isolate(data)
Expand Down Expand Up @@ -669,7 +696,9 @@ renderRadarChart <- function(div_id,

ifelse(show.legend,
paste("legend:{orient: 'vertical', left: 'left', data:",
legend_data, "},",
legend_data,
", textStyle:{fontSize:", font.size.legend, "}",
"},",
sep=""),
""),
"radar:{",
Expand Down
20 changes: 19 additions & 1 deletion man/renderBarChart.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ renderBarChart() function helps render the bar chart into Shiny application.
\usage{
renderBarChart(div_id, data, theme, stack_plot, direction,
grid_left,grid_right, grid_top, grid_bottom,
show.legend, show.tools,
show.legend = TRUE, show.tools = TRUE,
font.size.legend = 12,
font.size.axis.x = 12, font.size.axis.y = 12,
rotate.axis.x = 0, rotate.axis.y = 0,
running_in_shiny)
}
%- maybe also 'usage' for other objects documented here.
Expand Down Expand Up @@ -47,6 +50,21 @@ If display the legends. The default value is TRUE.
}
\item{show.tools}{
If display the tool bar. The default value is TRUE.
}
\item{font.size.legend}{
The font size of legend bar. The default value is 12.
}
\item{font.size.axis.x}{
The font size of the labels on X axis. The default value is 12.
}
\item{font.size.axis.y}{
The font size of the labels on Y axis. The default value is 12.
}
\item{rotate.axis.x}{
The rotation degree of labels on X axis. The default value is 0.
}
\item{rotate.axis.y}{
The rotation degree of labels on Y axis. The default value is 0.
}
\item{running_in_shiny}{
If we're actually running this in a Shiny library, or we're simply doing testing. Default valus is "TRUE". If "FALSE", the function will print what it's supposed to evaluate.
Expand Down
Loading

0 comments on commit 9693daf

Please sign in to comment.