A way to scroll a layout's widgets using mouse? - widget

Can you help me on how to scroll a layout's content using mouse? Or is it possible?
I created this notification-center widget and I used wibox.layout.fixed.vertical() to act the storage of the widgets/notifications. My problem is having too many widgets will consume all the space and there will be no enough space to display the other widgets. So I've been trying to make the widget inside the wibox.layout.fixed.vertical() scrollable but I'm always reaching a dead end. I also tried the wibox.container.scroll but as the documentation says:
Please note that mouse events do not propagate to widgets inside of the scroll container.
This is the simple code I'm using:
-- Layout
local notifbox_layout = wibox.layout.fixed.vertical()
-- Add these textbox widgets to layout
-- Make this widgets scrollable if there's too many of them
notifbox_layout:insert(1, wibox.widget.textbox('String 1'))
notifbox_layout:insert(1, wibox.widget.textbox('String 2'))
notifbox_layout:insert(1, wibox.widget.textbox('String 3'))
notifbox_layout:insert(1, wibox.widget.textbox('String 4'))
notifbox_layout:insert(1, wibox.widget.textbox('String 5'))
-- Mouse event
notifbox_layout:buttons(
gears.table.join(
awful.button(
{},
4,
nil,
function()
-- some magic here to scroll up
end
),
awful.button(
{},
5,
nil,
function()
-- some magic here to scroll down
end
)
)
)
This is the notification center with no enough space to show the other widgets
Sorry if I explained this bad. I'm not really that good in english.

Nevermind. I tried Uli Schlachter's answer here. And it works perfectly. I modified it a bit and then it looks like this.
local w = wibox{ x = 100, y = 100, width = 100, height = 20, visible = true }
my_wiget = function()
return some_widget
end
local own_widget = wibox.widget.base.make_widget()
local offset_x, offset_y = -20, 0
function own_widget:layout(context, width, height)
-- No idea how to pick good widths and heights for the inner widget.
return { wibox.widget.base.place_widget_at(my_widget(), offset_x, offset_y, 200, 40) }
end
own_widget:buttons(
awful.util.table.join(
awful.button(
{},
4,
function()
if offset_y <= 490 then
offset_y = offset_y + 5
end
own_widget:emit_signal("widget::layout_changed")
end
),
awful.button(
{},
5,
function()
if offset_y >= 5 then
offset_y = offset_y - 5
end
own_widget:emit_signal("widget::layout_changed")
end
)
)
)
w:set_widget(own_widget)

Related

Dash Unable to Center Table Horizontally

My code below reads in a small CSV file, defines the styles, and displays the output.
The H1 tag is centred, as expected.
But for some reason, my table is not centered horizontally.
What am I doing wrong?
df = pd.read_csv('myfile.csv')
app = Dash(__name__)
hdg_style = {'color': '#055d9c', 'text-align': 'center'}
tblh_style = {'backgroundColor': 'Linen', 'fontWeight': 'semi-bold'}
tbl_style = {'textAlign': 'center', 'maxWidth': '1000px', 'border': 'thin #055d9c solid'}
app.layout = html.Div([
html.H1(children="My Project", style=hdg_style),
dash_table.DataTable(
data = df.to_dict('records'),
columns = [{'id': c, 'name': c} for c in df.columns],
style_cell = {'textAlign': 'center'},
style_header = tblh_style,
style_table = tbl_style)])
if __name__ == '__main__':
app.run_server(debug=True)
I tried the CSS below to center the table horizontally, but it did not work.
style={'margin-left': 'auto', 'margin-right': 'auto'}
If you include the margin attributes in your tbl_style definition, it'll center the table - it did for me in my test case:
tbl_style = {'textAlign': 'center', 'maxWidth': '1000px', 'border': 'thin #055d9c solid', 'marginLeft': 'auto', 'marginRight': 'auto'}
I suspect your attempts with CSS modifications get caught up in the vagaries of Dash configuration of serving static css files.
app.layout = dbc.Container(). In that, you put multiple dbc.Row. Then, dbc.Col in them. In these columns you put objects (your datatable). You can then align anything you wish moving objects by defining size and offset. Check official dash bootstrap components doc for the detail

Remove spacing between bar in bar graph( react-chart-js)

issue that i am facing is, i have my bar graph made using react-chart-js. i want to remove space between the bar and center align the bar's . The bar's should have Thickness equal to 50
I try using dummy data ,that way i got the desired output but that is not the correct way of doing . Also I try using barPercentage , categoryPercentage option but didnt get the desired output
Link for CodeSandbox
I don't know if this actually works out of the box. There is nothing in the documentation about this use case either.
You could do it with ghost values to extend the chart in general.
This is not really a solution, but it may be an option.
const labels = ["","","January", "February", "March","",""];
export const data = {
labels,
datasets: [
{
label: "Dataset 1",
data: labels.map((elem, index) => {
if (index > 1 && index < 5)
return faker.datatype.number({ min: 0, max: 1000 })
}),
backgroundColor: "rgba(255, 99, 132, 0.5)",
barThickness: 50
}
]
};

How to effectively adjust graph margin or padding in dash plotly

I have plotted two graphs using plotly dash. But when the y-axis / x-axis tick size is more it gets cut off.
Y-axis :
Code :
data = [go.Scatter(x = df[df['S2PName-Category']==category]['S2BillDate'],
y = df[df['S2PName-Category']==category]['totSale'],
mode = 'markers+lines',
name = category) for category in df['S2PName-Category'].unique()]
layout = go.Layout(title='Category Trend',
xaxis = dict(title = 'Time Frame', tickformat = '%d-%b-%y'),
yaxis = dict(tickprefix= '₹', tickformat=',.2f',type='log'),
hovermode = 'closest',
plot_bgcolor = colors['background'],
paper_bgcolor = colors['background'],
font = dict(color = colors['text'])
)
X-Axis :
Code :
data = [go.Scatter(x = df[df['S2PName']==item]['S2BillDate'],
y = df[df['S2PName']==item]['totSale'],
mode = 'markers+lines',
name = item) for item in items]
layout = go.Layout(title='Category Trend',
xaxis = dict(title = 'Time Frame' , tickformat = '%d-%b'),
yaxis = dict(tickprefix= '₹', tickformat=',.2f',type='log',autorange = True),
hovermode = 'closest',
plot_bgcolor = colors['background'],
paper_bgcolor = colors['background'],
font = dict(color = colors['text'])
)
In the above 2 graphs , as the length of the tick value increases, it gets cut off . Is there a better way to handle this ?
Credit for #Flavia Giammarino in comments for the reference to the docs. I'm posting the answer for completeness.
https://plotly.com/python/setting-graph-size/
From that link the example below shows how to set margin:
fig.update_layout(
margin=dict(l=20, r=20, t=20, b=20),
)
Where l r t b correspond to left, right, top, bottom.
I had a similar problem with some Dash/Plotly charts and long y axis labels being truncated or hidden. There didn't seem to be much information or documentation on this issue, so it took a while to solve.
Solution: add this code to the layout settings to prevent truncation of the y axes labels:
fig.update_layout(
yaxis=dict(
automargin=True
)
)
or you can update the yaxes setting specifically:
fig.update_yaxes(automargin=True)
Update: I tried another version of Plotly (5.10 or above) which mentions setting the automargin setting to any combination of automargin=['left+top+right+bottom'] with similar results. This still seems a bit unstable and doesn't solve all possible scenarios or corner cases, but works fine in most cases, especially when the browser window is maximized.

barplot xlim shifts axis -> offset to axis at=midpoints missing

I have the following problem – it is purely an ascetic one but it bothers me that it is not looking nicely:
I generate a simple sideways barplot with ticks at the bottom of the bars. The default setting generates an x-axis which is shorter than my bars (figure 1). To solve this I included xlim. Once I do that the x-axis is slightly shifted to the left so the y-axis is touching the bars (figure 2). This does not look nice at all. I guess xlim somehow overwrite a default parameter but I could not find which. I would be grateful for any suggestions!
rm(list=ls())
data<-c(69,500,597)
names(data)<-c("text1", "text2", "text3")
midpoints<-barplot(data, beside=T, space=1, xlim=c(0,600))
filename=paste("orig.pdf", sep="")
pdf(file=filename, width=10, height =5)
par(mar=c(4,9,1,4))
barplot(data, beside=T, xlab=expression(paste("Text")),
axes=T, cex.lab=2, cex.axis=2, cex.names=2, font.axis = 2,
col=c("grey"), horiz=T, las=1, font.lab=2, space=1,
names.arg=colnames(data))
axis(side = 2, at = midpoints , labels = F, cex.axis=1.5)
dev.off()
filename=paste("with_limit.pdf", sep="")
pdf(file=filename, width=10, height =5)
lim<-c(0,600)
par(mar=c(4,9,1,4))
barplot(data, beside=T, xlab=expression(paste("Text")),
axes=T, cex.lab=2, cex.axis=2, cex.names=2, font.axis = 2,
col=c("grey"), horiz=T, las=1, font.lab=2, space=1,
names.arg=colnames(data), xlim=lim)
axis(side = 2, at = midpoints , labels = F, cex.axis=1.5)
dev.off()
Figure 1
Figure 2
Meanwhile I did find two possible answers both not perfect but working.
The first one is to work with xaxs="r" but for my taste now the offset is too large.
filename=paste("solution1.pdf", sep="")
pdf(file=filename, width=10, height =5)
lim<-c(0,600)
par(mar=c(4,9,1,4))
barplot(data, beside=T, xlab=expression(paste("Text")),
axes=T, cex.lab=2, cex.axis=2, cex.names=2, font.axis = 2,
col=c("grey"), horiz=T, las=1, font.lab=2, space=1,
names.arg=colnames(data), xlim=lim, xaxs="r")
axis(side = 2, at = midpoints , labels = F, cex.axis=1.5)
dev.off()
Solution1
The second option is to have xlim starting in the negative. This has the disadvantage of tuning the offset by hand. In my case I had multiple figures and I wanted it always to be the same so I used (here) 2% of the maximum 600 -> 12. For all others I also used 2% of the maximum. That worked nicely in the end.
filename=paste("solution2.pdf", sep="")
pdf(file=filename, width=10, height =5)
lim<-c(-12,600)
par(mar=c(4,9,1,4))
barplot(data, beside=T, xlab=expression(paste("Text")),
axes=T, cex.lab=2, cex.axis=2, cex.names=2, font.axis = 2,
col=c("grey"), horiz=T, las=1, font.lab=2, space=1,
names.arg=colnames(data), xlim=lim)
axis(side = 2, at = midpoints , labels = F, cex.axis=1.5)
dev.off()
Solution2

Get the default height of a scroll bar

What is the default height of a scroll bar(Horizontal)?
I couldn't find the document online.
UPDATED: Can we write a javascript function to get it? Please don't down vote it. It is hard to get it.
Thank you.
Found this here: How can I get the browser's scrollbar sizes?
function getScrollBarWidth () {
var inner = document.createElement('p');
inner.style.width = "100%";
inner.style.height = "200px";
var outer = document.createElement('div');
outer.style.position = "absolute";
outer.style.top = "0px";
outer.style.left = "0px";
outer.style.visibility = "hidden";
outer.style.width = "200px";
outer.style.height = "150px";
outer.style.overflow = "hidden";
outer.appendChild (inner);
document.body.appendChild (outer);
var w1 = inner.offsetWidth;
outer.style.overflow = 'scroll';
var w2 = inner.offsetWidth;
if (w1 == w2) w2 = outer.clientWidth;
document.body.removeChild (outer);
return (w1 - w2);
};
alert( getScrollBarWidth () );
That's going to depend on the clients screen resolution and browser. If you explain why your asking then I might be able to give a better answer.
Whatever the user's computer is set to. There is no hard-and-fast rule on this. For example, on my Ubuntu machine, the default scroll bar size is 0 - instead of a conventional scrollbar, it has a scroll line with arrows that appear when the mouse moves near it, and it takes no space on the document. However, on my Windows installation, the scrollbar size is 14 pixels, but I could set it from anything between about 8 and over 500...
Interesting question. My thought is: when a property you are interested in is not readily available, test.
One DOM property I can think of that would be affected by the scrollbar height is the clientHeight of the body (or whatever box has the scrollbar) if you set it to 100%. This is maybe a dumb approach, and not sure how useful it really is, but check it out:
get clientHeight before
expand width of an internal element, wide enough to cause a scrollbar
get clientHeight after
subtract
I made a fiddle of this. Like I said, not sure how useful this approach could be in real life, but maybe it's a start on something.
http://jsfiddle.net/brico/t6zMN/