I want to store data in sessionStorage or localStorage across domains, what should I do? Because the vue project needs to carry the data to the react project, my English is not very good, I hope you can understand what I mean
Category: javascript
Category Added in a WPeMatico Campaign
get x and y coordinates of eacg node react-graph-vis
When the graph gets rendered it gives each node its x and y coordinates.
My question is can I access the network and get each node coordinates.
I tried using ref in order to print out the network and get the nodes details but I couldn’t find anything about coordinates.
please note that I’m new to react-graph-vis so go easy on me.
import React from "react";
import ReactDOM from "react-dom";
import Graph from "react-graph-vis";
function App() {
const graph = {
nodes: [
{ id: 1, label: "Node 1", title: "node 1 tootip text" },
{ id: 2, label: "Node 2", title: "node 2 tootip text" },
{ id: 3, label: "Node 3", title: "node 3 tootip text" },
{ id: 4, label: "Node 4", title: "node 4 tootip text" },
{ id: 5, label: "Node 5", title: "node 5 tootip text" }
],
edges: [
{ from: 1, to: 2 },
{ from: 1, to: 3 },
{ from: 2, to: 4 },
{ from: 2, to: 5 }
]
};
const options = {
width: (window.innerWidth) + 'px',
height: (window.innerWidth) + 'px',
layout: {
hierarchical: false
},
edges: {
color: "#000000"
},
physics:false,
interaction: {
dragNodes: true,
zoomView: true,
dragView: true
}
};
return (
<Graph
graph={graph}
options={options}
events={events}
getNetwork={network => {
}}
/>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
How to find out large dips in Array values?
So I’m creating a boxing game based on pose detection.
Essentially every tick it takes out the angle between the shoulder, elbow and wrist and according to that it detects if it is a punch or not.
So when the angle is less the punch is loading up and when the angle is more the punch gets released.
So the low points in the data mean that the punch is loading up and the high points are the releases.
The data looks like this in graphical form
, where the blue curve is the left hand angle and the red is the right hand angle.
I also need to detect the speed at which the punch is thrown. Is there any way to do all of this?
Thanks in advance 🙂
How to fetch text from an website into the javascript
i am making a chrome extension.
i need a text from an open website in the active tab of browser to use in javascript of the extension. how to fetch it in there?
like in this website link
in this site i want the time fetched in the javascript.
i am 2 hours ago started new.
Please help with an example code if anyone can.
just show an example of how to store that text in a variable.
thank you
How to uncheck all the checkboxes in a list of checkbox programmatically in react hooks?
I have a list of 6 items and their respective checkboxes.for instance , i have selected 4 checkboxes out of 6. Now by a click of button i have to uncheck all the 4 checkboxes that are selected to unselected.Please anyone help me with the solution here.
why checkbox shows checked while I had checked previous page’s checkboxes?
I am using Alpine js with Tailwind CSS, There is an uncertain bug appearing below that is a checkbox selections issue. Actually, there are multiple selections type of questions, when I select one or more checkboxes and move to the next question then in next question’s checkbox shows selected the same checkbox which I had selected in the previous question until I select once any of them after that it has shown current selection.
Here is the code snippet
Javascript:- `export const model = () => {
return {
me: this,
type: null,
sections: [],
currentSection: {},
selections: [],
currentIndex: 0,
currentStep: ‘start’,
userValidator: {
isValid: true,
submitUser() {
this.userValidator.isValid = !Object.values(this.userValidator.user).some(
(field) => !field.isValid
);
console.log('over here', this.userValidator.isValid);
if (!this.userValidator.isValid) {
return this.userValidator.isValid;
}
console.log(this.submission.user);
this.currentStep = 'sections';
},
validationCallback(field) {
let { value, rules } = field;
let isValid = iodine.isValid(value, rules);
let errorMsg = isValid
? null
: iodine.getErrorMessage(iodine.is(value, rules));
return { isValid, errorMsg };
},
user: {
name: {
rules: ["required"],
validate(validator, submitted) {
let { isValid, errorMsg } = validator.validationCallback({...this, value: submitted.user.name});
this.isValid = isValid;
this.errorMsg = errorMsg;
},
isValid: null,
errorMsg: null
},
email: {
value: null,
rules: ["required", "email"],
validate(validator, submitted) {
let { isValid, errorMsg } = validator.validationCallback({...this, value: submitted.user.email});
this.isValid = isValid;
this.errorMsg = errorMsg;
},
isValid: null,
errorMsg: null
},
company: {
value: null,
rules: ["required"],
validate(validator, submitted) {
let { isValid, errorMsg } = validator.validationCallback({...this, value: submitted.user.company});
this.isValid = isValid;
this.errorMsg = errorMsg;
},
isValid: null,
errorMsg: null
},
phone: {
value: null,
rules: ["required"],
validate(validator, submitted) {
let { isValid, errorMsg } = validator.validationCallback({...this, value: submitted.user.phone});
this.isValid = isValid;
this.errorMsg = errorMsg;
},
isValid: null,
errorMsg: null
}
},
},
submission: {
user: {
name: null,
email: null,
company: null,
phone: null,
},
},
name: '',
async init() {
return new Promise((resolve) => {
this.type = data.type;
this.sections = data.sections;
this.currentSection = data.sections[0];
this.currentIndex = 0;
this.name = data.name;
resolve();
});
},
getValue(index) {
return `${this.currentIndex}:${this.currentSection.level}:${index}`;
},
moveNext(forward) {
console.log('current selections', this.selections);
let direction = 1;
let index = this.currentSection.level || 0;
if (index === -1) {
return;
}
if (!forward) {
direction = -1;
}
index = index + direction;
if (index < 0 || index === this.currentSection.levels.length) {
return;
}
this.currentSection.level = index;
}
};
};`
<div class="mt-4 mr-4 p-4 rounded-lg shadow-md bg-white">
<div class="px-4 bg-gradient-to-r from-gray-500 via-gray-900 to-gray-700 text-white rounded">
<h5 class="mb-1 text-base font-semibold text-white lg:text-xl inline-block"
x-text="currentSection.levels[currentSection.level || 0].name"></h5>
<h5 class="mb-1 text-base font-semibold text-white lg:text-xl inline-block"
x-text="currentSection.levels[currentSection.level || 0].subtitle"></h5>
</div>
<ul class="my-2 space-y-3">
<template x-for="(item, index) in currentSection.levels[currentSection.level || 0].items">
<li>
<label
class="flex items-center p-2 text-base text-gray-500 bg-gray-50 rounded-lg hover:bg-gray-100 group hover:shadow">
<input class="text-blue-500 w-4 h-4 mr-2 focus:ring-blue-400 focus:ring-opacity-25 border
gray-300 rounded" type="checkbox" x-model="selections" :value="getValue(index)" />
<span class="flex-1 ml-3" x-text="item.name"></span>
</label>
</li>
</template>
</ul>
<div class="text-left pt-4">
<a class="cursor-pointer border-2 border-pink-800 text-purple-700 bg-white px-3 py-2 w-2/4 rounded font-bold"
href="javascript:;;" @click="currentStep='levels';">
MAIN MENU
</a>
</div>
<div class="text-right">
<button
class="py-2 px-14 rounded bg-gradient-to-r from-purple-700 to-purple-500 text-white capitalize hover:bg-purple-600 focus:outline-none focus:shadow-outline"
@click="moveNext(false)">
« Previous
</button>
<button
class="py-2 px-14 rounded bg-gradient-to-r from-purple-700 to-purple-500 text-white capitalize hover:bg-purple-600 focus:outline-none focus:shadow-outline"
@click="moveNext(true)">
Next »
</button>
</div>
</div>
How to add/remove class on mouse hover in JavaScript?
I want to add class as I hover over an item and remove it as soon as the hover is removed in JavaScript. For now, my code is not removing the class until I hover over that item again.
myChart.on('mouseover', function(params){
var collapseItem = params.name + "-content"
var toCollapse = document.getElementById(collapseItem)
var collapseHeading = toCollapse.previousElementSibling
collapseHeading.classList.toggle("active")
})
Chart.js doughnut chart insufficient height
I was working on a dashboard which has a doughnut chart on the right side of the page. While I was successful at making the the itself i’ve been struggling with the height of the the chart. If canvas tag is set using attributes the the whole chart stretches and the height of the chart has a default size of of (128px).
Here is the code below:-
<input type="text" name="balance" value="42" id="balance" hidden>
<div class="chartWrapper">
<canvas id="myChart" height="180px"></canvas>
<div class="ChartContent">
<h2>84%</h2>
</div>
</div>
//START DOUGHNUT CHART
var balance = document.getElementById('balance').value;
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['Withdrawal Amount', 'Balance Amount'],
datasets: [{
data: [80, 124, balance],
backgroundColor: [
'#232c66',
'#ffa5a2',
],
borderColor: [
'#232c66',
'#ffa5a2',
],
borderWidth: 2,
hoverBorderWidth: 1,
weight: 2,
clip:
{
left: 5,
top: 5,
right: -2,
bottom: 0
}
}]
},
options: {
cutoutPercentage: 180,
rotation : 5,
animation: true,
legend: {
position: 'chartArea',
padding: 1
},
layout: {
padding: 20
}
}
});
//END DOUGHNUT CHART
Get All Values from Input Checkboxes to Display in Express Post Response?
So I have my express server that gets the order value based on the name of my checkbox
<input type="checkbox" name="item1" value="10" onClick="updatePrice()">
<label for="item1">12 piece wings $10</label>
So you can see the name of this checkbox is called item1 and I’m using an SDK for my function in express, but basically I get the order_value by targeting req.body then the name of my input checkbox
const response = await client.createDelivery(
{
order_value: req.body.item1,
tip: req.body.item1,
},
);
res.send(response)
Now my issue is my order value only calculates one checkbox. How do I get the values of all my checkboxes if I have 100 for example?
So it would look like this
<input type="checkbox" name="item1" value="10" onClick="updatePrice()">
<label for="item1">12 piece wings $10</label>
<input type="checkbox" name="item2" value="40" onClick="updatePrice()">
<label for="item1">20 piece wings $40</label>
<input type="checkbox" name="item3" value="60" onClick="updatePrice()">
<label for="item1">30 piece wings $60</label>
Because it doesn’t make sense to do
order_value: req.body.item1 + req.body.item2 .... etc to 100
Is it possible to map through the data in an express post function?
How would I accomplish this?
Bootstrap NavBar doesnt change the background color
Im trying to change all the background-color from navBar bootstrap component and idk why its not working:
Why is NW.SHELL only wokring in root DIR of app?
For some reason NW.SHELL fuctions are only working for files in root folder of my app. It wont let me use an absolute path or a relative path. Example “/relative/path/text.txt” or D:/relative/path/text.txt however text.txt will work with NW.SHELL function as long as the text file is in the same root DIR obviously.
This applies to both of these. What can i do to get relative or absolute paths to work? preferably relative paths. The nature of my program relative would be most functional.
nw.Shell.showItemInFolder('test.txt');
nw.Shell.openItem('test.txt');
open pdf in browser using javascript xmlhttprequest
So I’ve looking around a lot and try to see best way to open blob as pdf in browser. Closest stackoverflow question i was able to find was this one:
XMLHttpRequest to open PDF in browser
but this is 11 years old. Currently I have a program that looks like this:
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://localhost:8080/api/download', true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.status == 200) {
// Note: .response instead of .responseText
var blob = new Blob([this.response], {type: 'application/pdf'}),
url = URL.createObjectURL(blob);
window.open(url, '_blank');
}
};
xhr.send();
Now again Issue here is that it opens in chrome browser ( FYI: Version 102.0.5005.61 (Official Build) (arm64)) with a UUID. So url of new tab looks something like this:
blob:http://localhost:3000/f7c5571a-bf59-45d1-99ea-e495fe859008
Now when I click on download icon. File explorer opens up with UUID in it and I cannot download it in windows. When I try it says network error.
Question: What is best possible way to display just pdf in browser. While removing downloading icons if they are not going to work.
Oh i have also tried creating the link and then doing link.download = fileName; That works perfectly fine but I am not looking to download file just view it on browser. I have also tried content-disposition inline and attachment. Does not work. Result is same.
Thanks a lot!
how to make a point cloud viewer with webgl
I am trying to make a point cloud viewer with webgl, every tutorial i have found explain how the projection works with objects like a cube.
but that projection / perspective is not working with points because the point size is not changing.
How do i change my point size based on Z axis.
var vertCode =
'attribute vec3 coordinates;' +
'uniform mat4 rMatrix;' +
'void main(void) {' +
' gl_Position = rMatrix * vec4(coordinates, 1.0);' +
'gl_PointSize = 5.0;'+
'}';
[…]
const matrix = glMatrix.mat4.create();
const projectionMatrix = glMatrix.mat4.create();
const finalMatrix = glMatrix.mat4.create();
glMatrix.mat4.perspective(projectionMatrix,
75 * Math.PI/180, // vertical field of view ( angle in radian)
canvas.width/canvas.width, //aspect ratio
1e-4, // near cull distance ... aka null plane
1e4 // fat cull distance
);
//glMatrix.mat4.translate(matrix, matrix,[-.5,-.5,-.5]);
function animate(){
requestAnimationFrame(animate);
glMatrix.mat4.rotateY(matrix, matrix, Math.PI/6)
glMatrix.mat4.multiply(finalMatrix, projectionMatrix, matrix);
gl.uniformMatrix4fv(uniformLocations.matrix, false, matrix);
gl.drawArrays(gl.POINTS, 0, vertices.length/3);
}
sub question:
right now my code is a constant rotation, any ressource where to look on how to get the mouse event and create one or 2 rotation matrix based on the mouse drag( not quite sure if i can encode x and y rotation in the same matrix )
sub question 2:
any idea on how to have round points instead of square one ?
do i have to create small sphere ?
how to apply photoshop warp on web with webgl or canvas js or with php?
Basically, I want this effect on the web. I have saved psd with this warping effect and extracted the data on nodejs with the ag-psd library. The data looks like this.
[
{ x: 0, y: 0 },
{ x: 214, y: 0 },
{ x: 428, y: 0 },
{ x: 642, y: 0 },
{ x: 0, y: 118.66666666666666 },
{ x: 214, y: 118.66666666666666 },
{ x: 428, y: 118.66666666666666 },
{ x: 642, y: 118.66666666666666 },
{ x: 0, y: 237.33333333333331 },
{ x: 214, y: 237.33333333333331 },
{ x: 428, y: 237.33333333333331 },
{ x: 642, y: 237.33333333333331 },
{ x: 0, y: 356 },
{ x: 214, y: 356 },
{ x: 428, y: 356 },
{ x: 642, y: 356 }
]
It has 8 vertices. So I wanna apply the same vertices on another image (png or jpg) with nodejs or with php. Is there any way to do it?
how to get offset information of a crop/selection area in photoshop script?
When I use “DialogModes.ALL” to create a crop area,
How to get offset information after crop/selection action done by human in photoshop script ?
thanks 🙂
var idCrop = charIDToTypeID( "Crop" );
executeAction( idCrop, desc4, DialogModes.ALL );'
–> get offset information code ?

