Adjust c3 axis labels with css - css

I am using R's c3 package which is a wrapper for the C3 javascript charting library by Masayuki Tanaka.
My c3 chart below cuts off the last date on the x-axis.
Using Chrome Inspector I can manually adjust the text-anchor: middle to text-anchor: end
and that seems to work.
However, I do not understand how to do this with css.
Here's my R Script and related css though I don't think that R is relevant to the issue here.
R Script
library(shiny)
library(c3)
data <- data.frame(a = abs(rnorm(20) * 10),
b = abs(rnorm(20) * 10),
date = seq(as.Date("2014-01-01"), by = "month", length.out = 20))
ui <- fluidPage(
includeCSS("c3.css"),
c3Output("chart", height = "100%")
)
server <- function(input, output, session) {
output$chart <- renderC3({
data %>%
c3(x = 'date') %>%
tickAxis('x', count = 5, format = '%Y-%m-%d')
})
}
shinyApp(ui, server)
css
.c3-line {
stroke-width: 4px !important;
}
.c3-axis-x-label {
text-anchor: end;
}

You haven't pasted any actual code, but it's highly likely that the code below will help:
.c3-axis-x g.tick:nth-last-child(3) text {
transform:translateX(-5%);
}
You need to target the text correctly and adjust value to your needs.
Edit: Actually it's not :last-child - adjusted, based on some actual code. In essence you need to target your selector properly and apply the transform property.
Edit2: So it was actually the .c3-axis-x group that includes the tick texts. Code updated (yet again)

One thing that popps to my head immediately:
With your css you are only targeting the 'date' element.
You other 'text' element doesnt have a class, therefore the css for '.c3-axis-x-label' will only target the first text element.
Try adding 'c3-axis-x-label' class also to your other 'text' element.
Another thing:
The 'text' tag that you want to adjust has its styles written in the tag
When you set styles like this it will always override the applied CSS.
One solution i can think of, is to add !important in your CSS to override the style. I do not recommend using !important, but if its too difficult to actually change the css directly then this might be a solution.
If you can add a class to the other text element the try applying styles to 'text' in your css:
g > text {
text-anchor: end;
}
Let me know if any of that helped. Otherwise some code would come in handy to help you out

Related

RShiny Columns Overlap With Picture

I'm having problems with my RShiny when I resize the browser. I noticed there are several similar topics but those are when it is words and can be solved with the wrap words input. However mine is a picture and a bunch of words.
When browser is big
When resized
###codes above
output$img1 <-renderUI({
if(input$Category == "Cleanser"){
img(width = 175, height = 175, src = "Cleansers.png", style = "margin-left:15px; margin-top:10px")
}
### rest of codes
output$text1<-renderUI({
summary<-read_excel(paste0("Summary/",input$Category,".xlsx"),sheet = 1)
summary$Price<-as.integer(summary$Price)
dat<-calcul()
product=paste(dat[input$table1_cell_clicked$row,1])
w1=which(summary$`Product Name`==product)
###relevant part###
fluidRow(tags$head(tags$style(
"body { word-wrap: break-word; }"
)),
column(2,uiOutput("img1",inline = T))
,column(9,h3("Description",style = 'margin-left:10px'),
p(summary$Description[w1], style = "margin-left:10px"))
)
})
I used fluidRow() to make the columns, I tried using the word-wrap thing but it doesn't work still. Can someone help me out ? Thanks so much!

Distorted spacing between div elements after sorting with jqui_sortable

While building a very nice additional functionality into my shiny app where the user can reorganize the plots inside the page, I ran into 1 problem.
I noticed that the spacing between the div elements that are being relocated (sorted), changes while doing so, resulting in a misalignment of the plots afterwards.
I have tried to adjust margin values to nothing, 0 or a certain amount of pixels, but that doesn't seem to solve this.
The app that I made to test / illustrate the issue is posted below, where I left out the plots to simplify it:
require('shiny')
require('shinyjqui')
ui <- fluidPage(
div(uiOutput('multiobject'), style = 'width: 1200px')
)
server <- function(input, output, session) {
output$multiobject <- renderUI({
plot_output_list <- list();
for(i in 1:8) {
plot_output_list <- append(plot_output_list,list(
wellPanel(
actionButton('drag', label = icon('hand-point-up'), style = 'float: right; color: #339fff;'),
style = 'border-color:#339fff; border-width:1px; background-color: #fff;display: inline-block; margin:2px; width:290px; height:250px')
))
}
jqui_sortable(do.call(function(...) div(id="allplots", ...), plot_output_list), options = list(handle = '#drag', cancel = ""))
})
}
shinyApp(ui, server)
and this image shows the problem after sorting:
A second problem is the white space appearing when hovering a plot.
I tried to add the css from this "non-R-Shiny" question but could't make it work.
It is not perfect yet, but it should be better than before.
The spacing problem of the <div>s was caused by empty text knods. You can see them when inspecting the page in a browser. This means, changing the css margin arguments will not help. The empty text knods are present in the initial page and once you start dragging they disappear leading to said spacing problem. I got rid of them by not wrapping uiOutput('multiobject') in a div()-tag and instead defined its width using the .ui-sortable class in css.
Your second problem, the white space appearing when hovering a plot, can be mitigated by adding 'float: left; to the style = argument in the for loop of your plot_output_list. The css arguments from the SO post you linked won't work, since there are no classes named .sort-container and .item-wrapper this was specific to the original question. There is still a white space appearing when dragging, but it is much smaller than before.
Update I had some issues with the code, sometimes it's working sometimes not. I think there might be css confilcts. I now added !important to the changed css arguments and it seems to work. Will try it on a different machine later.
require('shiny')
require('shinyjqui')
require('stringr')
ui <- fluidPage(
# Custom CSS----------
tags$style(HTML(".ui-sortable {
width: 1200px !important;
} "
)),
uiOutput('multiobject')
)
server <- function(input, output, session) {
output$multiobject <- renderUI({
print(input$drag)
plot_output_list <- list();
for (i in 1:8) {
plot_output_list <- append(plot_output_list,list(
wellPanel(
actionButton('drag', label = icon('hand-point-up'), style = 'float: right; color: #339fff;'),
style = 'float:left !important; border-color:#339fff; border-width:1px; background-color: #fff;display: inline-block; margin:2px; width:290px; height:250px')
))
}
jqui_sortable(do.call(function(...) div(id = "allplots", ...), plot_output_list), options = list(handle = '#drag', cancel = ""))
})
}
shinyApp(ui, server)

Change font color of a column in rhandsontable

I have a table rendered using rhandsontable in R. I want to change the font color to red of a specific column. How can I do it ? I tried the following code, but it does not work
output$hot=renderRHandsontable({
rhandontable (table)%>%
hot_col("colum1", color = "red")
})
If you want to change the style of elements inside of your table (in your case it is the font color of each cell of a given column), you will need to use a bit of Javascript and write a renderer function that will do the job, like so:
# Toy data frame
table <- data.frame(a = 1:10, b = letters[1:10])
# Custom renderer function
color_renderer <- "
function(instance, td) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.style.color = 'red';
}
"
rhandsontable(table) %>%
hot_col("b", renderer = color_renderer)
The function color_renderer() is saved as a string and will be used as the renderer argument of the hot_col()-function. Note the argument td I am using refers to the cell object of your table. td has several attributes, one is the style, which in turn has the attribute color.
Also make certain that you are using the correct Handsontable renderer. In my case, it is a TextRenderer but you may use different renderers based on the data type your column has.
For more information, refer to the Handsontable documentation.
I hope this helps.
Cheers

Hiding grid columns change height of rows

I have quite annoying problem with hiding grid columns dynamically. After I hide columns (with long text in cells), the height of grid rows dramatically increases.
Before hide
and after hide operation
As You can see first row is definitely too high. Probably the reason of that behavior is the fact, that I use text wrap in grid cells.
.x-grid-cell-inner { white-space: normal; }
Is there any efficient way to make grid rows, not to change their height after hiding columns (and using textwrap ) ?
I've personally encountered this strange phenomenon before. The problem is caused by Ext JS "hiding" columns by setting the width to 0px.
My solution was to add event listeners to the grid header like this:
// me is the grid
me.headerCt.on({
columnhide: me.removeWordWrapOnHide,
columnshow: me.addWordWrapOnShow,
scope: me
});
Instead of using the existing x-grid-cell-inner class, make a new one like this:
<style type="text/css">
td.grid-cell-wordwrap > div {
white-space: normal; /* may need !important, not sure */
}
</style>
Then the implementation of these two functions did this:
removeWordWrapOnHide: function(headerCt, column){
var me = this,
wordWrapRe = /wordwrap/;
if(column.useWordWrap || wordWrapRe.test(column.tdCls)){
column.tdCls = column.tdCls.replace("grid-cell-wordwrap", "");
column.useWordWrap = true; // Flag to check on show
me.view.refresh();
}
},
addWordWrapOnShow: function(headerCt, column){
var me = this,
wordWrapRe = /wordwrap/;
if(column.useWordWrap && !wordWrapRe.test(column.tdCls)){
column.tdCls = "grid-cell-wordwrap " + column.tdCls;
me.view.refresh();
}
}
Might not be the most efficient way, but it gets the job done.

Autosize Text Area (Multiline asp:TextBox)

I have a MultiLine asp:Textbox (a standard html textarea for those non-asp people) that I want to be auto-sized to fit all it's content only through css. The reason for this is that I want it to be of a specified height in the web browser, with scrolling enabled.
I have implemented a print style sheet however and want all text located in the textarea to be displayed when printed with no overflow hidden.
I can manually specify the height of the textarea in the print.css file problem with this being that the fields are optional and a 350px blank box is not optimal and there is always the possibility of a larger amount of text than this...
I have tried using :
height: auto;
height: 100%;
In IE and Firefox respectively yet these seem to be overridden by the presence of a specified number of rows in the html mark-up for the form which must be generated by .NET when you do not specify a height on the asp:Textbox tag, this seems to only accept numercial measurements such as px em etc...
Any ideas?
What you are asking for (a css solution) is not possible.
The content of the textarea is not html elements, so it can not be used by css to calculate the size of the textarea.
The only thing that could work would be Javascript, e.g. reading the scrollHeight property and use that to set the height of the element. Still the scrollHeight property is non-standard, so it might not work in all browsers.
jQuery or a javascript function to find and make textboxes bigger might be the best solution - at least thats what i found
we use this set of functions and call clean form after the page is loaded (i know this isnt the best solution right here and am working to transfer to a jQuery solution that is more elegant) - one note make sure your textareas have rows and cols specified or it doesnt work right.
function countLines(strtocount, cols)
{
var hard_lines = 1;
var last = 0;
while (true)
{
last = strtocount.indexOf("\n", last + 1);
hard_lines++;
if (last == -1) break;
}
var soft_lines = Math.round(strtocount.length / (cols - 1));
var hard = eval("hard_lines " + unescape("%3e") + "soft_lines;");
if (hard) soft_lines = hard_lines; return soft_lines;
}
function cleanForm()
{
var the_form = document.forms[0];
for (var i = 0, il = the_form.length; i < il; i++)
{
if (!the_form[i]) continue;
if (typeof the_form[i].rows != "number") continue;
the_form[i].rows = countLines(the_form[i].value, the_form[i].cols) + 1;
}
setTimeout("cleanForm();", 3000);
}
If you set rows to be a ridiculously high number the CSS height rule should override it on the screen.
Then in the print stylesheet just set height to auto. This might result in some big blank space where all the available rows haven't been filled up, but at least all text will be visible.
give jQuery's autogrow() a go #
http://plugins.jquery.com/project/autogrow

Resources