React-Plotly: Graph Not Displaying Data From Array

I’m using react-plotly for implementing a line graph inside a React functional component as shown in the code below. However, when I try to plot my data using an array of values, it won’t show anything. I’m using scattergl because I have a big set of data points to display. I need help with this issue. I’m using react.js version 17.0.2 and react-plotly version 2.5.1.

Here’s my code:

import React from 'react';
import Plot from 'react-plotly.js';
import mydata from '../data/allData.json';


const MyApp = () => {

    // Transform Data
    const transformData = mydata.map((d) => {
        let traces = [];
        let plot_data = [];
        let xx = [];
        let yy = [];
        let ss = [];
        ss.push(d.mydata_id)
        d.data.map((each) => {
            xx.push(each.datetime_read)
            yy.push(each.surge_count)
        });
        plot_data['x'] = xx;
        plot_data['y'] = yy;
        plot_data['s'] = ss;
        // console.log("Plot Data: ", plot_data)

        traces.push({
            x: plot_data['x'],
            y: plot_data['y'],
            type: 'scattergl',
            marker: {color: 'green'},
            name: plot_data['s']
        });

        return traces
    });

    return (
        <div>                
            <div>
                <Plot
                    data={transformData}
                    layout={{...}}                    
                />
            </div>
        </div>
    )
};

Here’s my data:

[
    {
        "mydata_id": "00175784",
        ...
        "data": [
            {
                "datetime_read": "2022-03-16 03:15:00",
                ...
                "surge_count": "240"
            },
            {
                ...
            }
        ]
    },
    {
        "mydata_id": "00161784",
        ...
        "data": [
            {
                "datetime_read": "2022-03-16 03:20:00",
                ...
                "surge_count": "194"
            },
            {
                "datetime_read": "2022-03-16 03:15:00",
                ...
                "surge_count": "342"
            },
            {
                ...
            }
        ]
    }
]

I would also like to note that when I try to display specific data in the array with data={transformData[2]}, it works just fine. But my goal is to display all data in the transformData array.

Can’t tab into Popper from material UI split button demo

I’m following the demo of the split button here But it looks like the demo itself isn’t accessible (you can’t tab from the button to the popper).

I’ve tried swapping/adding aria-controls for aria-owns but it’s not letting me move between the button and popper with a keyboard only.

How can I make this accessible? I’m presuming theres a good reason the demo doesn’t Menu (from a brief look, I don’t think it’s as easy to position perhaps??

Is there a safer alternative to eval? [duplicate]

Lately, I have been looking at web tutorials, and noticed that many calculators use eval() to calculate the results. I heard that eval can be used to do malicious things, so I was wondering, is there a safe way to use eval or a better alternative to eval?

I am not just looking for calculations, I want to know if eval can be safe if used and what alternatives there are.

Start animation from right when leaving screen

I want to have an animation that starts in the center but loops infinitely. As you can see in the snippet the cubes first start in the center, dispersed evenly across the width, but what I want is that the moment the cube leaves the screen on the left, it starts back at the right, so it is seamless. Anyone knows how to do this?

Here’s the code:

#skillIcon {
  animation: moveLeft 5s linear infinite;
  width:100px;
  height:100px;
  background-color:#444;
  align-items:center;
  position:relative;
}

@-webkit-keyframes moveLeft {
  from {
    right: -30%;
  }
  to {
    right: 100%;
  }
}

#parentDiv{
background-color:#222;
display:flex;
position:relative;
justify-content:space-between;
align-items:center;
}
<div id="parentDiv">
<div id="skillIcon">
</div>
<div id="skillIcon">
</div>
<div id="skillIcon">
</div>
</div>

REACT.js – Rendering an image

I am working on an ecommerce app using React(create-react-app). I am currently working on the product detail page. My issue is that the image won’t render on the website but the rest of the information on inside the return statement rendered. I have no errors on web dev tools, the app compiled successfully. Here is the code…

ProductScreen.js

import React from 'react';
import data from '../data';
import Rating from '../components/Rating';
import { Link, useParams } from 'react-router-dom';

function ProductScreen() {

  const { id } = useParams();
  // const params = useParams();
  // const { id: productId } = params;

  const product = data.products.find((x) => x._id === (id));

  if (!product) {
    return <div> Product Not Found </div>;
  }

  return (
    <div>

      <Link to="/">Back To Result</Link>

      <div className="row top">

        <div className="col-2">

          <img className="large" src={product.image} alt={product.name} ></img>

        </div>

The Main page did render all the images though. Just very confuse as I am new to React. Not sure how to find the issue especially when there is no error showing.

screen shot of terminal, web dev tools and the app

Panzoom JS very slow on initial load

I am using the panzoom.js library to pinch-zoom / wheel-zoom a map image. It works well. However, when the page loads with an empty cache and you attempt to zoom-in with either touch pinch or mouse wheel, there is a very noticeable lag and the image slowly catches up to the zoom. Once zoomed in, you can then very quickly zoom the image in and out and its very responsive. Is there anything I can do to achieve this fast zoom response right away. I have tried only displaying the image after page load and using smaller file size images etc. Nothing seems to work. Can anyone suggest a hack I might be able to try? As it is now, its very frustrating for the user, especially on touch.

Here is my test page: https://cryptopixel.app/testmap

The initial panzoom.js instance code is:

const elem = document.getElementById('map_inner_cont')
        
window.panzoom = panzoom(elem, {
        //zoomDoubleClickSpeed: 3,
        autocenter  : true,
        bounds      : true,
        initialZoom : pz_scale,
        animate     : true,
        minZoom     : 0.05,
        maxZoom     : 2,
        onClick(e)     {
            touch_feedback(e);
            map_click(e);
        }
})

Why is my js to create raining bowties not working?

I am making a project where I need to make an html canvas with raining bowtie images. Here is my js:

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");

var ok2animate = true;

function Drop() {
    this.x = Math.random() * (canvas.width - 20);
    this.y = -Math.random() * 20;
    this.fallRate = Math.random()*.5+.5;
}
//
Drop.prototype.draw = function () {
  //   this.x;
  // this.y;
  let img = new Image("images.png")
  ctx.drawImage(img, this.x, this.y)
    return (this);
}
//
Drop.prototype.fall = function () {
    this.y += this.fallRate;
    return (this);
}

function animate() {

    // request another animation frame
    if (ok2animate) {
        requestAnimationFrame(animate);
    }

  
        ctx.fillRect(0,0,canvas.width,canvas.height)
    //ctx.clearRect(0, 0, canvas.width, canvas.height);


    for (var i = 0; i < drops.length; i++) {
        drops[i].fall().draw();
    }

}





// an array of objects each representing 1 drop
var drops = [];

// add some test drops
for (var i = 0; i < 10; i++) {
    drops.push(new Drop());
}
setInterval(function(){requestAnimationFrame(animate)}, 1000)
requestAnimationFrame(animate)
<canvas id="canvas" width=300 height=300></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

How do I make it so the images rain down at 1 second intervals?
(I have included the image file in the same folder)
I have tried using an image file from the web, using a bigger canvas, uwing other versions of jquery, but none of those worked.

loop over a array of object Angular

i want to loop over this array of object but i don’t know why is don’t enter to this loop , i try foreach too but nothing

Component.ts

  cvs:Cv[]=[];

  CandidatAllInformation:any =
  {
    NOM:'',
    PRENOM:'',
    DATE_NAISSANCE:'',
    TELEPHONE:'',
    EMAIL:'',
    DIPLOME:'',
    INSTITUT:'',
    ANNEE_SCOLAIRE:'',
    MENTION:'',
    SPÉCIALITÉ:'',
    TYPE_EXPERIENCE:'',
    DATE_DEBUT:'',
    ENTREPRISE:'',
    DEPARTEMENT_SERVICE:'',

  };

  constructor(public cvService: CvService,public candidatService: CandidatService,public userService: UserService,public centreInteretService:CentreInteretService,public experienceService:ExperienceService,public formationService:FormationService,public langueService:LangueService,public specialiteService:SpecialiteService) { }


  ngOnInit(): void {
    
    this.cvService.getCvs().then((res:any)=>{
      console.log(res);
      this.cvs=res.data;
      console.log(this.cvs)
    }).catch((err:any)=>{
      console.log(err);
    })
    this.Afficher();
  }

  Afficher(){

    for (let element of this.cvs) {
      console.log("gfgf")
      this.candidatService.getCandidat(element.IDCANDIDAT).then((res:any)=>{
        this.myCandidat=res.data;
      }).catch((err)=>{
        console.log(err);
      })

      this.formationService.getFormation(element.IDFORMATION).then((res:any)=>{
        this.myFormation=res.data;
      }).catch((err)=>{
        console.log(err);
      })

      this.specialiteService.getSpecialite(element.IDSPECIALITE).then((res:any)=>{
        this.mySpecialite=res.data;
      }).catch((err)=>{
        console.log(err);
      })

      this.experienceService.getExperience(element.IDEXPERIENCE).then((res:any)=>{
        this.myExperience=res.data;
      }).catch((err)=>{
        console.log(err);
      })


      this.CandidatAllInformation =
      {
        NOM:this.myCandidat.NOM,
        PRENOM:this.myCandidat.PRENOM,
        DATE_NAISSANCE:this.myCandidat.DATENAISSANCE,
        TELEPHONE:this.myCandidat.TELEPHONE,
        EMAIL:this.myCandidat.EMAIL,
        DIPLOME:this.myFormation.DIPLOME,
        INSTITUT:this.myFormation.INSTITUT,
        ANNEE_SCOLAIRE:this.myFormation.ANNEESCOLAIRE,
        MENTION:this.myFormation.MENTION,
        SPÉCIALITÉ:this.mySpecialite.INTITULE,
        TYPE_EXPERIENCE:this.myExperience.TYPE,
        DATE_DEBUT:this.myExperience.DATEDEBUT,
        ENTREPRISE:this.myExperience.ENTREPRISE,
        DEPARTEMENT_SERVICE:this.myExperience.DEPARTEMENTSERVICE
      };
      this.resultCandidat=this.CANDIDATS=[this.CANDIDATS , ...this.CandidatAllInformation];
      

    }
    console.log("result");
    console.log(this.resultCandidat);
    
  }

}

Inserting an element prevents click event from firing

I have a simple form validator. When you click away from the input, it displays an error message (when necessary).

However, I have noticed a side effect. When the error message is inserted into the form, it shifts the submit button downward, which prevents the submit event from firing.

Take a look at the snippet below. This overly simplified example emulates the problem. Try clicking on the input and then the button. You’ll notice that the button’s click event won’t fire because it is shifted downwards.

function insert() {   
  var button = document.querySelector('button');
  document.body.insertBefore(document.createElement('div'), button);
}
div {
  width: 100px;
  height: 100px;
  background-color: red;
}
<input onblur="insert()" />
<button onclick="alert()">Click</button>

How can I resolve this problem? Keep in mind that for my form validator, the button is of type submit and the event that won’t fire is the form’s submit event, but the same concept can clearly be applied here.

How to pass parameters to the function called by chrome.scripting.executeScripts? – Chrome extension

I am trying to pass a parameter to the function called by chrome.scripting.executeScripts but it seems that the function can’t get parameters passed from the extension!

My extension contains several inputs, when one input is focused on, the extension should pass a certain parameter from the input dataset to the function executed by chrome scripting to set the value of an input in the page, author

let bookInputs = [...document.getElementsByClassName('book-input')];

bookInputs.forEach(bookInput=> {
    bookInput.addEventListener('focus', () => getBook(bookInput.dataset.author))
})

async function getBook(author) {
  let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
  chrome.scripting.executeScript({
    target: { tabId: tab.id },
    function:  () => enterBookAuthor(author)
  })
}

function enterBookAuthor(author) {
  const book= document.getElementById('book-author'); //an input in the page
  book.value = author;
}

But this code doesn’t manage to achieve the mission, so

Why can’t functions executed by chrome scripting receive parameters from the extension and what can i do to fix it??

Adding user input values into chart.js

I’m trying to build an expense tracker that takes in a name, date, category, and amount using javascript and charts.js. The issue is I’m not sure how to get the users inputted amount to got to a specific category on the chart. Like user adds $100 for rent and it increments the cart.

JS:


const ctx = document.getElementById("myChart").getContext("2d");
const myChart = new Chart(ctx, {
  type: "bar",
  data: {
    labels: [
      "Rent",
      "Utilities",
      "Food",
      "Transportation",
      "Insurance",
      "Clothing",
      "Personal",
    ],
    datasets: [
      {
        label: "Categories",
        data: [1, 7, 3, 5, 2, 3, 4],
      },
    ],
  },
  options: {
    scales: {},
  },
});

html:

      <form class="form">
        <div>
          <label for="name">Name:</label>
          <input
            type="text"
            id="name"
            name="name"
            placeholder="What did you buy?"
          />
        </div>
        <div>
          <label for="date">Date:</label>
          <input type="date" id="date" name="date" placeholder="mm/dd/yyyy" />
        </div>
        <div>
          <label for="categories">Pick a Category:</label>
          <select name="categories" id="categories">
            <option value="rent">Rent</option>
            <option value="utilities">Utilities</option>
            <option value="food">Food</option>
            <option value="transportation">Transportation</option>
            <option value="insurance">Insurance</option>
            <option value="clothing">Clothing</option>
            <option value="personal">Personal</option>
          </select>
        </div>
        <div>
          <label for="amount">Amount:</label>
          <input type="number" id="amount" name="number" placeholder="$$" />
        </div>
      </form>