const step = ref(4)
const visibleCardItems = computed(() => {
return window.innerWidth < 768
? cardItems.slice(0, step.value / 2)
: cardItems.slice(0, step.value)
})
Vue3, I tried to give conditions by the innerWidth of windows. But the logic seems not working. What is the problem?
Related
I'm using Chartjs.Blazor, and I haven't been able to do the same as described here : How to change the color of Chart.js points depending on the label
I've got a list of colors (rgba, or color name, I can choose) under the form of List<String>.
colors = ["rgba(255,0,0,1)", "rgba(0,255,0,1)", "rgba(0,0,255,1)", "rgba(255,0,0,1)", "rgba(0,255,0,1)"];
I tried to specify colors using the LineDataset.PointBackgroundColor property :
var _linebarDataSet = new ChartJs.Blazor.ChartJS.LineChart.LineDataset<ChartJs.Blazor.ChartJS.Common.Point>
{
Label = lineSet.Title,
Hidden = false,
Fill = false,
PointBackgroundColor = colors,
BorderWidth = 3,
PointBorderWidth = 0,
LineTension = 0,
PointRadius = 0,
};
for (int i = 0; i < lineSet.XAxisData.Count; i++)
{
_linebarDataSet.Add(new ChartJs.Blazor.ChartJS.Common.Point(i, lineSet.YAxisData[i]));
}
and tried to pass RGB values as in the example or colors name. It seems only the first definition is applied to all points.
I also tried to use javascript as :
await JSRuntime.InvokeAsync<string>("colorizePoints.HideOtherDatasetsFunc", valuesPoints, this.m_ValuesDataset.Colors);
and this code :
HideOtherDatasetsFunc: function (reference, colors, barchart) {
let colorsCode = []
for (var i = 0, len = colors.length; i < len; i++) {
colorsCode.push(colors[i]);
}
for (var i = 1; i <= reference.data.length - 1; i++) {
reference.pointBackgroundColor[i] = colorsCode[i];
}
}
And think Javascript like this would interfer with the Blazor server side rendering.
My problem using the javascript is to get the 2d context, as it's done in the link using :
var ctx = document.getElementById('lineChart').getContext('2d');
I can't set a fixed id as the CharJS, and retrieve it from javascript, because blazor components cannot stand id properties.
Has anybody an idea how to achieve this goal ?
Thank you for your reading-
This bug concerned 1.0 version.
The problem has been solved using IndexedOptions of the 2.0 version, which has just been released.
What I'm trying to do is generate a grid with less:
.grid {
/**
* #link http://lesscss.org/functions/#list-functions-each
*/
#selectors: 2, 3, 4, 5;
each(#selectors, {
&.--cols-#{value} {
#width: if((#value < 3), 100% / #value, 50%); // of #value = 2 ?
.list {
flex-basis: ~"calc(#{width} - 1px)";
}
.item {
max-width: ~"calc(#{width} - 1px)";
width: 100%;
}
}
});
}
But somehow less is generating then calc(50% - 1px) for all columns. So the question is - what am I doing wrong?
P.S. You can test here: http://lesscss.org/less-preview/
It should have been: #width: if((#value < 3), 50%, 100% / #value);
Thanks to #seven-phases-max.
I've been tasked with implementing a Normal Distribution graph. I was wondering if Chart.js offers this functionality right out of the box or if I will need to extend it. The graph in question is here
Thank you
It is unfortunately not possible with Chart.js, except if you create it by yourself.
But, I found a library called ChartNew.js (Github) that provides a lot of functionalities that are not available on Chart.js :
Chart.js has been completely rewritten since ChartNew.js has been developed; Both code are now completely different. Most of the functionalities inserted in the new version of Chart.js are also available in ChartNew.js
And this library provides a Gaussian Function (also called Normal Distribution) :
To do it, take a look at the sample given in the Github.
I'm sure it will suit you if you change some data.
This Implementation has been done using React. The functions below can still be used in other programming languages built on top of Javascript.
The only two inputs required to plot a Normal Distribution curve will be Mean and Standard deviation
Defining states for mean and standard deviation & states for X and Y arrays
const [bellMean, setBellMean] = useState<number>(12.2036); //example
const [bellStdev, setBellStdev] = useState<number>(0.0008); //example
const [bellXValues, setBellXValues] = useState<(number)[]>([]);
const [bellYValues, setBellYValues] = useState<(number | null)[]>([]);
To Get X values for bell curve (if not using react can get rid of useEffect)
useEffect(() => {
// defining chart limits between which the graph will be plotted
let lcl = bellMean - bellStdev * 6;
let ucl = bellMean + bellStdev * 6;
let ticks = [lcl];
let steps = 100; // steps corresponds to the size of the output array
let stepSize = Math.round(((ucl - lcl) / steps) * 10000) / 10000;
let tickVal = lcl;
for (let i = 0; i <= steps; i++) {
ticks.push(Math.round(tickVal * 10000) / 10000); // rounding off to 4 decimal places
tickVal = tickVal + stepSize;
}
setBellXValues(ticks); //array for X values
}, [bellMean, bellStdev]);
To Get Y values for Bell curve (if not using react can get rid of useEffect)
useEffect(() => {
// Using PDF function from vega-statistics instead of importing the whole library
const densityNormal = (value: number, mean: number, stdev: number) => {
const SQRT2PI = Math.sqrt(2 * Math.PI);
stdev = (stdev == null) ? 1 : stdev;
const z = (value - (mean || 0)) / stdev;
return Math.exp(-0.5 * z * z) / (stdev * SQRT2PI);
};
let YValues = bellXValues.map((item: number) => {
if (bellMean === null || bellStdev === undefined) {
return null;
} else {
const pdfValue = densityNormal(item, bellMean, bellStdev);
return pdfValue === Infinity ? null : pdfValue;
}
});
setBellYValues(YValues); // array for Y values
}, [bellXValues]);
The arrays for X and Y can be fed to labels and data props of chartjs as it is.
Picture of the problem \\ I’m making a match 3 type of game and I now have the core game engine done, so I’m starting the UI part. Note that this is my first try with QT, although I’ve done it with Tkinter on python.
My problem is inside my 2 for loops, comment says //Drawing the Gems, to draw the gems on the screen. I'm going through my Gem object 6x6 array. As you can see on the image, it is not doing as intended, the 36 gems are not being drawed like it's supposed to. Only the first row and the first column is done, which is weird.
Thank you in advance for any help.
(Also, I tried changing the pen color so it changes depending on which type of gem the painter is trying to draw, but it didn't work and I’m pretty sure I’m not doing it the correct way)
void Interface::paintEvent(QPaintEvent *e)
{
QPainter painter(this);
// Pens
QPen linepen(Qt::black);
linepen.setWidth(2);
QPen gempen(Qt::red);
gempen.setWidth(4);
// Points
QPoint linepoint1;
linepoint1.setX(60);
linepoint1.setY(60);
QPoint linepoint2;
linepoint2.setX(420);
linepoint2.setY(60);
// Drawing the lines
painter.setPen(linepen);
for (int i = 1; i <= 7; i++)
{
painter.drawLine(linepoint1, linepoint2);
linepoint1.setY(60 + (60 * i));
linepoint2.setY(60 + (60 * i));
}
// Resetting the points
linepoint1.setX(60);
linepoint1.setY(60);
linepoint2.setX(60);
linepoint2.setY(420);
// Drawing the columnns
for (int i = 1; i <= 7; i++)
{
painter.drawLine(linepoint1, linepoint2);
linepoint1.setX(60 + (60 * i));
linepoint2.setX(60 + (60 * i));
}
QPoint gempoint1;
gempoint1.setX(75);
gempoint1.setY(75);
QPoint gempoint2;
gempoint2.setX(105);
gempoint2.setY(105);
QRect gem(gempoint1, gempoint2);
painter.setPen(gempen);
// Drawing the gems
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 6; j++)
{
QColor color;
if (m_gameBoard.getGem(i + 1, j + 1).getRepresentation() == "1")
{
color.blue();
}
else if (m_gameBoard.getGem(i + 1, j + 1).getRepresentation() == "2")
{
color.red();
}
else if (m_gameBoard.getGem(i + 1, j + 1).getRepresentation() == "3")
{
color.green();
}
else if (m_gameBoard.getGem(i + 1, j + 1).getRepresentation() == "4")
{
color.cyan();
}
else if (m_gameBoard.getGem(i + 1, j + 1).getRepresentation() == "5")
{
color.magenta();
}
else if (m_gameBoard.getGem(i + 1, j + 1).getRepresentation() == "6")
{
color.yellow();
}
else if (m_gameBoard.getGem(i + 1, j + 1).getRepresentation() == "7")
{
color.black();
}
else if (m_gameBoard.getGem(i + 1, j + 1).getRepresentation() == "8")
{
color.setNamedColor("orange");
}
else if (m_gameBoard.getGem(i, j).getRepresentation() == "0")
{
gem.setCoords(75 + (60 * (j + 1)), 75, 105 + (60 * (j + 1)), 105);
break;
}
painter.drawRect(gem);
gem.setCoords(75 + (60 * (j+1)), 75, 105 + (60 * (j+1)), 105);
}
gem.setCoords(75, 75 + (60 * (i+1)), 105, 105 + (60 * (i+1)));
}
}
P.S. : Sorry for engrish.
The problem is you're setting your coordinates at the wrong time, read comments in code:
...
painter.drawRect(gem);
//This only updates the top row (the y-coord never changes)
gem.setCoords(75 + (60 * (j+1)), 75, 105 + (60 * (j+1)), 105);
}
//This only updates the first column (the x-coord never changes)
gem.setCoords(75, 75 + (60 * (i+1)), 105, 105 + (60 * (i+1)));
}
Do something like:
...
painter.drawRect(gem);
//This now updates both x- and y-
gem.setCoords(75 + (60 * (j+1)), 75 + (60 * (i+1)), 105 + (60 * (j+1)), 105 + (60 * (i+1));
}
//This isn't needed
//gem.setCoords(75, 75 + (60 * (i+1)), 105, 105 + (60 * (i+1)));
}
Here your gem.setCoords(...) updates both the x- and y- coordinates at the same time. Also, you may want to put painter.drawRect(gem) after the gem.setCoords(...) call. One last thing, you may want to remove the + 1 for the j and i since your for loops start from 0.
Edit
This is in response to your comment about assigning color. I would clean it up a bit as follows (FYI: I don't know Qt and I'm assuming getRepresentation returns a QString):
QColor color;
int representation = m_gemBoard.getGem(i + 1, j + 1).getRepresentation.ToInt();
switch(representation)
{
case 1:
color.blue();
break;
case 2:
color.red();
break;
case 3:
color.green();
break;
// Fill the rest in here.
}
You may also want to use int for your colors instead of strings. You could use an enum like:
enum MyColors
{
Blue = 1,
Red = 2,
Orange = 3,
// Fill the rest in here.
// 0 will be a special case for you not handled in this enum.
}
Hope this helps.
I build my action for create image thumbs, and I want add to the end of action auto rotate to my thumb.
My question is: How add rotate with random angle from -45 to 45 degree?
You can rotate an image automatically via an Adobe Script:
if (!app.documents.length > 0) {
alert("No active document");
}
else {
var docRef = app.activeDocument;
var docWidth = docRef.width.as("px");
var docHeight = docRef.height.as("px");
if (docWidth > docHeight) {
docRef.rotateCanvas(90);
}
}
Random numbers can be generated with:
this.rawValue = Math.random() * (45 - 1) + 1;
I've not done enough Adobe Script to tell you how to put this all together, but I'm sure you are clever enough!
Helpful site: http://www.photoshopsupport.com/tutorials/jennifer/photoshop-scripts.html
Enjoi!
Sorry for another answer, I didn't want to make my other one massive and unreadable.
I have attempted (VERY BADLY) the script (and, for the record, it's not been tested or anything and I'm not great at this)
if (!app.documents.length > 0) {
alert("No active document"); //no document?! whats happening?!
} else {
var docRef = app.activeDocument;
var docWidth = docRef.width.as("px");
var docHeight = docRef.height.as("px");
if (docWidth > docHeight) { //if width is greater than height
PlusMinus.rawValue = Math.random() * (2 - 1) + 1; //GET 1 OR 2
if (PlusMinus.rawValue == 1) {
deLimit = "-"; //set minus if its a 1
} else {
deLimit = "+"; //set plus if its a 2
}
Angles.rawValue = Math.random() * (45 - 1) + 1; //GET NUMBER FROM 1-45
docRef.rotateCanvas(deLimit+Angles);
}
}
I'm sure you will get the idea from that!