Grid column autofill - css

I have a array which i want to be displayed within 3 columns.
Once the first column gets filled i want it to start populating the second row, so on to the third row.
My issue is that the current code the columns get an equal amount of (6x, 6x, 6x), but the desire is to populate the first column until max(100% height or x amount) then start populating the second and finally the third column if the array would be long enough.
JSX
export const Home = () => {
return (
<div className="container">
{
myArray.map((p, i) => {
return <div className="titleName" key={i}>{p.name}</div>
})
}
</div>
)
}
const myArray = [
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
{ name: "lol", age: 12 },
]
CSS
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
background-color: white;
}
Codepen:
https://codepen.io/Arasto/pen/PoZmoqy

You can use css column-count: 3; on the <div id="root"> This makes the text into 3 columns. column-fill: auto; populates the column fully and then goes on to the next column so they do not get an equal amount.
Woking example: https://codepen.io/Ajjarindahouse/pen/NWxjWaK

Related

How can I create error bars similar to Vega Lite in eCharts

I am trying to create error bars similar to the one in Vega Lite
Vega Lite Error Bar.
I would like to plot Q25, Q50, Q75 versus gender (as the first category) and age as the second.
I tried to organize my data in different ways, so Q is the same as Q25, Q50, Q75. I am having trouble achieving my goal.
// Generate data.
data = [
[
'jobId',
'Region',
'rid',
'ContributionLimit',
'Q25',
'Q50',
'Q75',
'entryNR',
'Gender',
'AgeCategory',
'Q'
],
[
2446,
'Baden-W\u00fcrttemberg',
9,
6900.0,
2330.0,
2628.0,
3032.0,
883,
'Gesamt',
'25 bis unter 55',
[2330.0, 2628.0, 3032.0]
],
[
2446,
'Baden-W\u00fcrttemberg',
9,
6900.0,
2330.0,
2628.0,
3032.0,
883,
'Gesamt',
'Gesamt',
[2330.0, 2628.0, 3032.0]
],
[
2446,
'Baden-W\u00fcrttemberg',
9,
6900.0,
2302.0,
2561.0,
2852.0,
777,
'Frauen',
'Gesamt',
[2302.0, 2561.0, 2852.0]
],
[
2446,
'Baden-W\u00fcrttemberg',
9,
6900.0,
2286.0,
2542.0,
2827.0,
528,
'Frauen',
'25 bis unter 55',
[2286.0, 2542.0, 2827.0]
]
];
option = {
dataset: [
{
id: 'raw',
source: data
},
{
id: 'rid_f',
fromDatasetId: 'raw',
transform: [
{
type: 'filter',
config: {
dimension: 'rid',
eq: 9
}
}
]
},
{
id: 'Gesamt',
fromDatasetId: 'rid_f',
transform: [
{
type: 'filter',
config: {
dimension: 'AgeCategory',
eq: 'Gesamt'
}
}
]
},
{
id: '25 bis unter 55',
fromDatasetId: 'rid_f',
transform: [
{
type: 'filter',
config: {
dimension: 'AgeCategory',
eq: '25 bis unter 55'
}
}
]
},
],
legend: {
top: '10%'
},
yAxis: {
type: 'category',
},
xAxis: {
type: 'value'
},
series: [
{
name: 'ab 55',
type: 'line',
datasetId: 'Gesamt',
symbolSize: 6,
encode: {
x: ['Q25', 'Q50', 'Q75'],
y: 'Gender',
label: 'Gender',
itemName: 'Gender'
}
},
{
name: '25 bis unter 55',
type: 'line',
datasetId: '25 bis unter 55',
symbolSize: 6,
encode: {
x: 'Q',
y: 'Gender',
label: 'Gender',
itemName: 'Gender'
}
}
]
};

Search input as option in Material UI Select component

I need to make Select component with Search input as first option in dropdown list. Something like this:
The main problem is that Search component acts as normal from input. I don't know how to make it focusable. Thank you.
Problem Explanation
This happens because MenuItem is a direct child of the Select component. It acts in the same way as described in Selected menu documentation. You can see that when Menu (or in our case Select) is opened, focus is automatically put onto the selected MenuItem. That's why TextField loses focus in the first place (even if we attach an autoFocus attribute to it).
Ok, so we can obviously simply hack this using the useRef hook on a TextField and then call the focus() method when Select opens. Something like this:
var inputRef = useRef(undefined);
...
<Select onAnimationEnd={() -> inputRef.current.focus()} ... >
...
<TextField ref={inputRef} ... />
...
</Select>
Well not so fast, there's a catch!
Here's where things break: You open your select and focus shifts to the input field as expected. Then you insert search text that would filter out the currently selected value. Now if you remove text with backspace until the currently selected item appears again, you would see that focus would automatically be placed from input field to the currently selected option. It might seem like a viable solution at first but you can see where UX suffers and we don't get expected stable behavior that we want.
Solution
I find your question a bit vague without any code and proper explanation, but I still find it useful since I was searching for the exact same solution as you: Searchable Select MUI Component with good UX. So please note that this is my assumption of what you wanted as a working solution.
Here's a CodeSandbox with my working solution. All the important bits are explained in code comments and here:
The most important change is adding MenuProps={{ autoFocus: false }} attribute to the Select component and autoFocus attribute to the TextField component.
I've put the search TextField into a ListSubheader so that it doesn't act as a selectable item in the menu. i.e. we can click the search input without triggering any selection.
I've added a custom renderValue function. This prevents rendering empty string in Select's value field if search text would exclude the currently selected option.
I've disabled event propagation on TextField with the onKeyDown function. This prevents auto selecting item while typing (which is default Select behavior)
[BONUS] You can easily extend this component with multi selection support, which was what I ended up making for my project, but I'll not include the details here since it's out of the scope of your question.
The MUI Autocomplete component might be just what you need
[https://mui.com/components/autocomplete/](MUI Autocomplete)
Auto Complete is a Component provided by the MUI Library. It has the same functionality like Select option, and in addition provides a search-option, along with other options improving developer experience. Here is a little snippet of the Autocomplete Component:
import * as React from 'react';
import TextField from '#mui/material/TextField';
import Autocomplete from '#mui/material/Autocomplete';
export default function ComboBox() {
return (
<Autocomplete
disablePortal
id="combo-box-demo"
options={top100Films}
sx={{ width: 300 }}
renderInput={(params) => <TextField {...params} label="Movie" />}
/>
);
}
// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994 },
{ label: 'The Godfather', year: 1972 },
{ label: 'The Godfather: Part II', year: 1974 },
{ label: 'The Dark Knight', year: 2008 },
{ label: '12 Angry Men', year: 1957 },
{ label: "Schindler's List", year: 1993 },
{ label: 'Pulp Fiction', year: 1994 },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
},
{ label: 'The Good, the Bad and the Ugly', year: 1966 },
{ label: 'Fight Club', year: 1999 },
{
label: 'The Lord of the Rings: The Fellowship of the Ring',
year: 2001,
},
{
label: 'Star Wars: Episode V - The Empire Strikes Back',
year: 1980,
},
{ label: 'Forrest Gump', year: 1994 },
{ label: 'Inception', year: 2010 },
{
label: 'The Lord of the Rings: The Two Towers',
year: 2002,
},
{ label: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ label: 'Goodfellas', year: 1990 },
{ label: 'The Matrix', year: 1999 },
{ label: 'Seven Samurai', year: 1954 },
{
label: 'Star Wars: Episode IV - A New Hope',
year: 1977,
},
{ label: 'City of God', year: 2002 },
{ label: 'Se7en', year: 1995 },
{ label: 'The Silence of the Lambs', year: 1991 },
{ label: "It's a Wonderful Life", year: 1946 },
{ label: 'Life Is Beautiful', year: 1997 },
{ label: 'The Usual Suspects', year: 1995 },
{ label: 'Léon: The Professional', year: 1994 },
{ label: 'Spirited Away', year: 2001 },
{ label: 'Saving Private Ryan', year: 1998 },
{ label: 'Once Upon a Time in the West', year: 1968 },
{ label: 'American History X', year: 1998 },
{ label: 'Interstellar', year: 2014 },
{ label: 'Casablanca', year: 1942 },
{ label: 'City Lights', year: 1931 },
{ label: 'Psycho', year: 1960 },
{ label: 'The Green Mile', year: 1999 },
{ label: 'The Intouchables', year: 2011 },
{ label: 'Modern Times', year: 1936 },
{ label: 'Raiders of the Lost Ark', year: 1981 },
{ label: 'Rear Window', year: 1954 },
{ label: 'The Pianist', year: 2002 },
{ label: 'The Departed', year: 2006 },
{ label: 'Terminator 2: Judgment Day', year: 1991 },
{ label: 'Back to the Future', year: 1985 },
{ label: 'Whiplash', year: 2014 },
{ label: 'Gladiator', year: 2000 },
{ label: 'Memento', year: 2000 },
{ label: 'The Prestige', year: 2006 },
{ label: 'The Lion King', year: 1994 },
{ label: 'Apocalypse Now', year: 1979 },
{ label: 'Alien', year: 1979 },
{ label: 'Sunset Boulevard', year: 1950 },
{
label: 'Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb',
year: 1964,
},
{ label: 'The Great Dictator', year: 1940 },
{ label: 'Cinema Paradiso', year: 1988 },
{ label: 'The Lives of Others', year: 2006 },
{ label: 'Grave of the Fireflies', year: 1988 },
{ label: 'Paths of Glory', year: 1957 },
{ label: 'Django Unchained', year: 2012 },
{ label: 'The Shining', year: 1980 },
{ label: 'WALL·E', year: 2008 },
{ label: 'American Beauty', year: 1999 },
{ label: 'The Dark Knight Rises', year: 2012 },
{ label: 'Princess Mononoke', year: 1997 },
{ label: 'Aliens', year: 1986 },
{ label: 'Oldboy', year: 2003 },
{ label: 'Once Upon a Time in America', year: 1984 },
{ label: 'Witness for the Prosecution', year: 1957 },
{ label: 'Das Boot', year: 1981 },
{ label: 'Citizen Kane', year: 1941 },
{ label: 'North by Northwest', year: 1959 },
{ label: 'Vertigo', year: 1958 },
{
label: 'Star Wars: Episode VI - Return of the Jedi',
year: 1983,
},
{ label: 'Reservoir Dogs', year: 1992 },
{ label: 'Braveheart', year: 1995 },
{ label: 'M', year: 1931 },
{ label: 'Requiem for a Dream', year: 2000 },
{ label: 'Amélie', year: 2001 },
{ label: 'A Clockwork Orange', year: 1971 },
{ label: 'Like Stars on Earth', year: 2007 },
{ label: 'Taxi Driver', year: 1976 },
{ label: 'Lawrence of Arabia', year: 1962 },
{ label: 'Double Indemnity', year: 1944 },
{
label: 'Eternal Sunshine of the Spotless Mind',
year: 2004,
},
{ label: 'Amadeus', year: 1984 },
{ label: 'To Kill a Mockingbird', year: 1962 },
{ label: 'Toy Story 3', year: 2010 },
{ label: 'Logan', year: 2017 },
{ label: 'Full Metal Jacket', year: 1987 },
{ label: 'Dangal', year: 2016 },
{ label: 'The Sting', year: 1973 },
{ label: '2001: A Space Odyssey', year: 1968 },
{ label: "Singin' in the Rain", year: 1952 },
{ label: 'Toy Story', year: 1995 },
{ label: 'Bicycle Thieves', year: 1948 },
{ label: 'The Kid', year: 1921 },
{ label: 'Inglourious Basterds', year: 2009 },
{ label: 'Snatch', year: 2000 },
{ label: '3 Idiots', year: 2009 },
{ label: 'Monty Python and the Holy Grail', year: 1975 },
];

How to get rid of the rows using sequelize

I am using sequelize.
const total = await models.parcel.findAndCountAll({ group: ['status'] });
And I got this response. But I want to only count not rows on response.
How can I make this? Thank you so much for reading my question.
{
"count": [
{
"status": null,
"count": 8
},
{
"status": "1",
"count": 5
},
{
"status": "2",
"count": 3
}
],
"rows": [
{
"id": 3,
"companyName": "hy",
"invoice": "904103",
"receiverName": "Rtrt",
},......
]
}
Just Change findAndCountAll to count:
await models.parcel.findAndCountAll({ group: ['status'] });
To :
await models.parcel.count({ group: ['status'] });

I can't subtract date with R

I try to subtract datetime (round 30mins). I can do it with Robo3T. But when I try to do this I am getting an error like below.
"Error: cant $subtract a string from a Date"
I can do it with robo3T but I couldn't do it with R.
Here is my R script;
datas3$aggregate(paste('[
{"$group": {
"_id": {
"AssetConnectDeviceKey":"$AssetConnectDeviceKey",
"Time": {"$add": [
{ "$subtract": [
{ "$subtract": [
{ "$add": [ "$CreateDate", ',1000 * 60 * 60 * 10 ,'] },
"new Date(0)"
]},
{ "$mod": [
{ "$subtract": [
{ "$add": [ "$CreateDate",', 1000 * 60 * 60 * 10 ,'] },
"new Date(0)"
]},',
1000 * 60 * 30,'
]}
]},
"new Date(0)"
]}
},
"Longitude": { "$avg": "$Longitude" },
"Latitude": { "$avg": "$Latitude" }
}}]'))
You can use the lubridate package to achieve this.
minutesLeftToday <- 1440 - hour(time)*60 - minute(time)

how can i show my custom (Day-Month-Year Hour:Min:Sec) time format on chartjs chart?

I want to show my custom (Day-Month-Year Hour:Min:Sec -->ex: 01-05-2019 14:06:47 PM) time format on chartjs chart
How Can i Show On chart xAxis Date Format Like This >>
Day-Month-Year Hour:Min:Sec -->ex: 01-05-2019 14:06:47 PM
time format is timeFormat = 'DD/MM/YYYY h:mm:ss a' but on chart only shows Month,Day,Year
This is my code below and:
Online Code On >>> https://codepen.io/sibche2013/pen/XQWWbb
var timeFormat = 'DD/MM/YYYY h:mm:ss a';
var config = {
type: 'line',
data: {
datasets: [
{
label: "UK Dates",
data: [{
x: "01-04-2014 02:15:50", y: 175
}, {
x: "12-04-2014 12:19:27", y: 177
}, {
x: "23-04-2014 22:25:47", y: 178
}, {
x: "28-04-2014 14:46:40", y: 182
}],
fill: false,
borderColor: 'blue'
}
]
},
options: {
responsive: true,
title: {
display: true,
text: "Chart.js Time Scale"
},
scales: {
xAxes: [{
type: "time",
time: {
format: timeFormat,
tooltipFormat: 'll'
},
scaleLabel: {
display: true,
labelString: 'Date'
}
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: 'value'
}
}]
}
}
};
window.onload = function () {
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx, config);
};

Resources