mouse up, down and wheel locks when creating heatmap with heatmap.js and fabric.js in the same div

I’m creating a drawing of a layout with the canvas and fabric.js library and in the same div I create a heatmap with the help of the heatmap.js library here. The problem is that when creating the heatmap, the mouse up, down and canvas wheel functionality stops working. Does anyone have an idea how to solve this or any other suggestions?

Currently my code looks like this:

<template>
  <section>
    <h1 class="title">Mapa de Calor do Centro de Distribuição</h1>
    <div class="box">
      <div class="heatmap-canvas">
        <canvas id="mycanvas"></canvas>
      </div>
    </div>
  </section>
</template>
.box {
  height: 100%;
  width: auto;
}
.heatmap-canvas {
  overflow: hidden;
  margin: auto;
  width: auto;
  height: 830px;
}
<script>
import { fabric } from "fabric";
import axios from "axios";
import h337 from "heatmapjs";
export default {
  layout: "collection_layout",
  data() {
    return {
      panning: false,
      data: {
        pallets: [],
        rulers: []
      },
      numbers: [],
      configs: {
        scale_factor: 18,
        font_size: 4,
        map_height: 50, // In meters
        map_width: 224 // In meters
      }
    };
  },
  mounted() {
    axios
      .get("/layoutCD.json")
      .then(response => {
        this.data.pallets = response.data.pallets;
        this.data.rulers = response.data.rulers;
        this.create_renderize(response.data);
      })
      .catch(error => {
        console.log(error);
      });
    axios
      .get("/array_endereco.json")
      .then(response => {
        this.numbers = response.data;
        this.create_renderize_heat(this.numbers, this.data);
      })
      .catch(error => {
        console.log(error);
      });
  },
  methods: {
    create_renderize(data) {
      // Create the canvas
      var canvas = new fabric.Canvas("mycanvas", { isDrawingMode: false });
      fabric.Object.prototype.objectCaching = false; // Avoids blurry text
      fabric.Object.prototype.selectable = false;

      // Set the width and height of the map canvas
      canvas.setWidth(this.scale(this.configs.map_width));
      canvas.setHeight(this.scale(this.configs.map_height));

      //Mouse press event
      canvas.on("mouse:down", function(e) {
        this.panning = true;
        canvas.selection = false;
      });
      //Mouse up event
      canvas.on("mouse:up", function(e) {
        this.panning = false;
        canvas.selection = true;
      });
      // Move the canvas event
      canvas.on("mouse:move", function(e) {
        if (this.panning && e && e.e) {
          var delta = new fabric.Point(e.e.movementX, e.e.movementY);
          canvas.relativePan(delta);
        }
      });

      canvas.on("mouse:wheel", function(e) {
        var delta = e.e.deltaY;
        var zoom = canvas.getZoom();
        zoom *= 0.999 ** delta;
        if (zoom > 20) zoom = 20;
        if (zoom < 0.01) zoom = 0.01;
        canvas.zoomToPoint({ x: e.e.offsetX, y: e.e.offsetY }, zoom);
        e.e.preventDefault();
        e.e.stopPropagation();
      });

      // Draw the distribution center map
      this.renderMap(data, canvas);
    },
    /* FUNCTION renderMap
        Renders the distribution center map
      */
    renderMap(data, canvas) {
      // Draw the pallets
      for (let i = 0; i < data.pallets.length; i++) {
        let pallet = data.pallets[i];
        this.drawPallet(pallet, canvas);
      }

      // Draw the rulers
      for (let i = 0; i < data.rulers.length; i++) {
        let ruler = data.rulers[i];
        this.drawRuler(ruler, canvas);
      }
    },
    /* FUNCTION drawRule
        Draws a single ruler
      */
    drawRuler(ruler, canvas) {
      // Find out how the ticks and the label should be aligned
      let align_tick_x = 0;
      let align_tick_y = 0;
      let left_label = scale(ruler.x_from + (ruler.x_to - ruler.x_from) / 2.0);
      let top_label = scale(ruler.y_from);
      let align_label_x = "center";
      let align_label_y = "center";
      let color = "#000";

      // Horizontal rule pointed up
      if (ruler.x_from < ruler.x_to) {
        align_tick_y -= 8;
        top_label += 10;
      }
      // Horizontal rule pointed down
      else if (ruler.x_from > ruler.x_to) {
        align_tick_y += 8;
        top_label -= 10;
      }

      // Vertical rule pointed left
      if (ruler.y_from < ruler.y_to) {
        align_tick_x -= 8;
        left_label += 8;
        top_label += scale((ruler.y_to - ruler.y_from) / 2.0);
        align_label_x = "left";
      }
      // Vertical rule pointed right
      else if (ruler.y_from > ruler.y_to) {
        align_tick_x += 8;
        left_label -= 8;
        top_label += scale((ruler.y_to - ruler.y_from) / 2.0);
        align_label_x = "right";
      }

      // Check if a color has been specified for the ruler
      if (typeof ruler.color != undefined) color = ruler.color;

      // Create the rule
      let ruler_main = new fabric.Line(
        [
          scale(ruler.x_from),
          scale(ruler.y_from),
          scale(ruler.x_to),
          scale(ruler.y_to)
        ],
        { stroke: color }
      );
      let ruler_tick_l = new fabric.Line(
        [
          scale(ruler.x_from) + align_tick_x,
          scale(ruler.y_from) + align_tick_y,
          scale(ruler.x_from),
          scale(ruler.y_from)
        ],
        { stroke: color }
      );
      let ruler_tick_r = new fabric.Line(
        [
          scale(ruler.x_to) + align_tick_x,
          scale(ruler.y_to) + align_tick_y,
          scale(ruler.x_to),
          scale(ruler.y_to)
        ],
        { stroke: color }
      );
      let label = new fabric.Text(ruler.label, {
        originX: align_label_x,
        originY: align_label_y,
        left: left_label,
        top: top_label,
        fontSize: configs.font_size,
        fill: color
      });

      // Add to the canvas
      canvas.add(ruler_main, ruler_tick_l, ruler_tick_r, label);
    },
    /* FUNCTION drawPallet
          Draws a single pallet
        */
    drawPallet(pallet, canvas) {
      let bg_color =
        typeof pallet.bg_color == "undefined" ? false : pallet.bg_color;
      let border_color =
        typeof pallet.border_color == "undefined"
          ? "#000"
          : pallet.border_color;
      let label_color =
        typeof pallet.label_color == "undefined" ? "#000" : pallet.label_color;
      let has_label = typeof pallet.label == "undefined" ? false : true;

      // Create the objects
      if (has_label) {
        let pallet_obj = new fabric.Rect({
          width: this.scale(pallet.width),
          height: this.scale(pallet.height),
          fill: bg_color,
          stroke: border_color
        });
        let label_obj = new fabric.Text(pallet.label, {
          originX: "center",
          originY: "center",
          left: this.scale(0.5 * pallet.width),
          top: this.scale(0.5 * pallet.height),
          fontSize: this.configs.font_size
        });

        // Create the group
        let group = new fabric.Group([pallet_obj, label_obj], {
          left: this.scale(pallet.x),
          top: this.scale(pallet.y),
          fill: label_color
        });

        // Add to the canvas
        canvas.add(group);
      } else {
        let pallet_obj = new fabric.Rect({
          width: this.scale(pallet.width),
          height: this.scale(pallet.height),
          left: this.scale(pallet.x),
          top: this.scale(pallet.y),
          fill: bg_color,
          stroke: border_color
        });

        // Add to the canvas
        canvas.add(pallet_obj);
      }
    },
    create_renderize_heat(numbers, layout) {
      // minimal heatmap instance configuration
      var heatmapInstance = h337.create({
        container: document.querySelector(".heatmap-canvas"),
        radius: 18,
        scaleRadius: true,
      });
      // now generate some random data
      var points = [];

      var arr = {
        keys: Object.keys(numbers),
        values: Object.values(numbers)
      };
      var max = 0;
      var i, j, flag = 0, pos = 0;
      for (i = 0; i < arr.keys.length; i++) {
        for (j = 0; j < layout.pallets.length; j++) {
          let str = layout.pallets[j].label.slice(0, 11);
          if (str == arr.keys[i]) {
            flag = 1;
            pos = j;
            break;
          }
          str = layout.pallets[j].label.slice(13, 24);
          if (str == arr.keys[i]) {
            flag = 1;
            pos = j;
            break;
          }
          str = layout.pallets[j].label.slice(26, 37);
          if (str == arr.keys[i]) {
            flag = 1;
            pos = j;
            break;
          }
        }
        if (flag == 1) {
          var val = arr.values[i];
          max = Math.max(max, val);
          var point = {
            x: Math.floor(
              this.scale(layout.pallets[pos].width / 2 + layout.pallets[pos].x)
            ),
            y: Math.floor(
              this.scale(layout.pallets[pos].height / 2 + layout.pallets[pos].y)
            ),
            value: val
          };
          points.push(point);
        }
        flag = 0;
      }
      // heatmap data format
      var data = {
        max: max,
        data: points
      };
      // if you have a set of datapoints always use setData instead of addData
      // for data initialization
      heatmapInstance.setData(data);
    },
    /* FUNCTION scale
         Scale the given value to convert metric units to pixels in the canvas according to
         the scale_factor defined in the configurations
      */
    scale(value) {
      return value * this.configs.scale_factor;
    }
  }
};
</script>

Page redirection and close the window are not working in firefox

I wrote the following code to redirect the user to different pages and close the window. While the following code works fine in chrome, but it does not work in firefox.

function OnRequestComplete(result) {
            if (result != null) {
                window.returnValue = true;
                var myhref = '';
                myhref = result;
                window.opener.top.location.href = myhref;
                window.close();
                }
        }

How can I get data from ajax and display to data in Chart.js

I have some problems need your help. I have a javascript connect to signalr and get data from database. Now I want to get this data and display in data of chart.js . Can you give me some example to do that. Pleas don’t ignore me, I really need your help!

This is code query in HomeController:

public JsonResult Get()
        {
            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ValueConnection"].ConnectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(@"SELECT [DeviceID],[Value] FROM [dbo].[Device1] WHERE [DeviceID]='PM1'", connection))
                {
                    command.Notification = null;

                    SqlDependency dependency = new SqlDependency(command);
                    dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

                    if (connection.State == ConnectionState.Closed)
                        connection.Open();

                    SqlDataReader reader = command.ExecuteReader();

                    var listCus = reader.Cast<IDataRecord>()
                        .Select(x => new
                        {
                            DeviceID = (string)x["DeviceID"],
                            Value = (double)x["Value"],
                        }).ToList();
                    return Json(new { listCus = listCus }, JsonRequestBehavior.AllowGet);
                }
            }
        }
private void dependency_OnChange(object sender, SqlNotificationEventArgs e)
        {
            CusHub.Show();
        }

Javascript connect to SignalR and get data from JsonResult :

<script type="text/javascript">
    $(function () {
        //Proxy created on the fly
        var cus = $.connection.cusHub;

        //Declare a function on the job hub so the server can invoke
        cus.client.displayValue = function () {
            getData();
        };

        //Start the connection
        $.connection.hub.start();
        getData();
    });

    function getData() {
        var $tbl = $('#tblValue');
        $.ajax({
            url: $("#Get").val(),
            type: 'GET',
            datatype: 'json',
            success: function (data) {
                $tbl.empty();
                $.each(data.listCus, function (i, model) {
                    $tbl.append
                        (
                            //'<tr>' +
                            //'<td>' + model.DeviceID + '</td>' +
                            //'<td>' + model.Value + '</td>' +
                            //'</tr>'
                             model.Value
                        );
                });
            }
        });
    }
</script>

And how can I get data from the above script and display in data of chart.js script :

<script>
    var ctx = document.getElementById("percent-chart2");
    function DynamicFunction() {
        var my_val = parseFloat(document.getElementById("tblValue").innerHTML);
        return my_val;
    }
        if (ctx) {
            ctx.height = 209;
            var myChart = new Chart(ctx, {
                type: 'doughnut',
                data: {
                    datasets: [
                        {
                            label: "My First dataset",
                            //data: [my_val1, my_val1, my_val1],
                            data: [my_val, my_val, my_val],
                            backgroundColor: [
                                '#00b5e9',
                                '#fa4251',
                                '#006400'
                            ],
                            hoverBackgroundColor: [
                                '#00b5e9',
                                '#fa4251',
                                '#006400'
                            ],
                            borderWidth: [
                                0, 0, 0
                            ],
                            hoverBorderColor: [
                                'transparent',
                                'transparent',
                                'transparent'
                            ]
                        }
                    ],
                    labels: [
                        'STATION 1',
                        'STATION 2',
                        'STATION 3'
                    ]
                },
                options: {
                    maintainAspectRatio: false,
                    responsive: true,
                    cutoutPercentage: 87,
                    animation: {
                        animateScale: true,
                        animateRotate: true
                    },
                    legend: {
                        display: false,
                        position: 'bottom',
                        labels: {
                            fontSize: 14,
                            fontFamily: "Poppins,sans-serif"
                        }

                    },
                    tooltips: {
                        titleFontFamily: "Poppins",
                        xPadding: 15,
                        yPadding: 10,
                        caretPadding: 0,
                        bodyFontSize: 16,
                    }
                }
            });
        }   
</script>

How to change default style of React Phone Number input field

How can i override the style of the react-phone-number-input component using https://www.npmjs.com/package/react-phone-number-input?

Along with this component, I’m using a react hook form and Tailwind CSS. Unfortunately, the background and border colors do not change, and the border width is too wide. I’m not sure how I can change the style.

Field Image

//React hook form
const {
    register,
    handleSubmit,
    watch,
    formState: { errors },
    control,
  } = useForm();


//Component
<PhoneInputWithCountry
              international
              name="phone"
              control={control}
              defaultCountry="BD"
              country="BD"
              id="phone"
              className="rounded rounded-full bg-gray-100 py-1 px-2 text-gray-700 shadow-sm border-green"
            />

why module exports not working in javascript?

I want to use module.exports to move User to another folder, but it is not working

The console give this error

script.js:542 Uncaught ReferenceError: module is not defined

class User {
  constructor(name, email) {
    this.name = name;
    this.email = email;
  }
  courseList = [];
  getInfo() {
    return {
      name: this.name,
      email: this.email
    };
  }

  enrollCourse(name) {
    this.courseList.push(name);
  }
  getCourseList() {
    return this.courseList;
  }
}

module.exports.User;

This in the new folder

import User from "./script";

const piyush = new User("piyush", "[email protected]");

console.log(piyush);

how input image canvas to excel (JS)

help with exporting convas image to excel file here is what i tried via bible jsPDF and via FileSaver:

html2canvas(document.getElementById("get_images")).then(function(canvas) {
var my_screen = canvas;
var dpf = new jsPDF();
saveAs(my_screen.toDataURL(), 'fdlfs.xlsx')
dpf.addImage(my_screen.toDataURL(), 'JPEG', 0, 0)
dpf.save("dowld.xlsx")

  });
}

Date axis labels with d3.js

The date axis of my d3 line chart contains a mixture of months and weekdays. I just want it to be the months and the day of the month (eg 15 Feb).

chart with weird axis

Does anyone know how to fix this?

Super new to d3.js so excuse me.

Thank you!

//create scales
const yScale = d3.scaleLinear()
    .domain(d3.extent(dataset,  yAccessor))
    .range([dimensions.boundedHeight, 0])


const xScale = d3.scaleTime()
    .domain(d3.extent(dataset, xAccessor))
    .range([0, dimensions.boundedWidth])

// draw data 
const lineGenerator = d3.line()
.x(d => xScale(xAccessor(d)))
.y(d => yScale(yAccessor(d)))

const line = bounds.append("path")
  .attr("d", lineGenerator(dataset))
  .attr("fill", "none")
  .attr("stroke", "#af9358")
  .attr("stroke-width", 2)

//draw peripherals
const yAxisGenerator = d3.axisLeft()
    .scale(yScale)

const yAxis = bounds.append("g")
    .call(yAxisGenerator)

const xAxisGenerator = d3.axisBottom()
    .scale(xScale)

const xAxis = bounds.append("g")
    .call(xAxisGenerator)
      .style("transform", `translateY(${
        dimensions.boundedHeight
      }px)`)

const xAxisLabel = xAxis.append("text")
    .attr("x", dimensions.boundedWidth / 2)
    .attr("y", dimensions.marginBottom -10)
    .attr("fill", "black")
    .style("font-size", "1.4em")
    //.html("Date")
    }
drawLineChart()

State in React Hook useEffect has a missing dependency

How can I remove warnings like this error srccomponentspagesbadgeBadgeScreen.tsx Line 87:6: React Hook useEffect has a missing dependency: 'loadData'. Either include it or remove the dependency array react-hooks/exhaustive-deps

Here is my code:

const location = useLocation();
  const { badge }: any = location.state;

    const [data, setData] = useState({
        id: "",
        badge_name: "",
        badge_description: "",
        imgBase64: "",
        img_icon: "",
      });
    
            useEffect(() => {
            setData(badge);
          }, [badge]);

Everything is working fine, but I am having a hard time fixing this issue.

Thank you!

How can I insert multiple text of different size into multiple svg rect using d3.js in Angular 11?

this.svg = d3
            .select(this.element.nativeElement)
            .append('svg')
            .attr('class', 'wordcloud-svg')
            .attr('width', 1200)
            .attr('height', 400)
            .append('g')
            .attr('transform', 'translate(' + (600) + ',' + (200) + ')');

var element=this.svg
                        .selectAll('text')
                        .data(words)
                        .enter()
                        .append('text')
                        .attr('id','word')
                        .style('font-size', (d) => d.size*5/6 + 'px')
                        .attr('text-anchor', 'middle')
                        .attr(
                            'transform',
                            (d) => 'translate(' + [d.x, d.y] + ')rotate(' + d.rotate + ')'
                        )
                        .text((d) => {
                            return d.text;
                        })
element.selectAll('word')
            .data(words)
            .enter()
            .append("rect")
            .attr("x", function(d) { return this.getBBox().x;})
            .attr("y", function(d) {return this.getBBox().y;})
            .attr("width", function(d) {return this.getBBox().width;})
            .attr("height", function(d) {return this.getBBox().height;})
            .style("fill", "grey");

**I have created a word cloud and I am trying to enclose each word of that word cloud inside a SVG rectangle but I am having trouble while doing that. Not sure how can i do that. **

JavaScript array is appending not, replacing element (NodeJS)

Hi I was trying to replace an item in an array, but instead it appends it to the array or something I have no idea what’s happening.

It’s meant to take in dice rolls from a array, take those input values and replace them with actual dice rolls and then replace the previous location with the new JSON that has the dice rolls and sum etc so that I can use them later.

function run_dice(dice){
  try{
    var valuesofdice = dice.value;
    var num;
    var size;
    var drop;
    var dcount = 0;
    var d1;
    var d2;
    for(i=0;i<(valuesofdice.length);i++){
      if(valuesofdice[i] === "d"){
        dcount+=1;
        if(dcount>2){
          return("error");
        }
      }
      if((valuesofdice[i] === "d") && dcount === 1){
        d1 = i;
        var num1 = (valuesofdice.substring(0,i));
        if (num1 == ""){
          num = 1;
        }else{
          num = Number(num1);
        }
      }else if((valuesofdice[i] === "d")&& dcount ===2){
        d2 = i;
        var num1 = (valuesofdice.substring(d1+1,d2));
        if(num1 === ""){
          return("error");
        }else{
          size = Number(num1);
        }
        var num2 = (valuesofdice.substring(d2+1));
        if (num2 == ""){
          return("error");
        }else{
          drop = Number(num2);
        }
      } 
      if((dcount === 1)&&(i == ((valuesofdice.length)-1))){
        var num1 = (valuesofdice.substring(d1+1,(valuesofdice.length)));
        if(num1 === ""){
          return("error");
        }else{
          size = Number(num1);
        }
      }
    }
    if(num == undefined && size == undefined && drop == undefined){
      return("error");
    }else if(drop == undefined){
      drop = 0;
    }
    if(drop>num){
      return("error");
    }
    if (num>1000 || size>1000000){
      return("error");
    }
    var arrayofrolls = [];
    var roll_sum = 0;
    for(i = 0;i<num;i++){
      var temp1 = 1 //LCG();
      arrayofrolls.push(((temp1)%size)+1);
    }
    arrayofrolls = quicksort(arrayofrolls);
    var drop_array = arrayofrolls.slice(0,drop);
    var sum_array = arrayofrolls.slice(drop,(arrayofrolls.length));
    for(i = 0;i<sum_array.length;i++){
      x = (sum_array[i]);
      roll_sum = roll_sum +x;
    }
    return({type:"dice",value:roll_sum,rolls:sum_array,drop:drop_array});
  }catch(e){
    return("error");
  }
}
var xz = [
  { type: 'dice', value: '2d6d1' },
  { type: '+' },
  { type: 'dice', value: '2d6' },
  { type: '*' },
  { type: 'dice', value: '8d6' }
];
for(i=0;i<(xz.length);i++){
  if((xz[i]).type === "dice"){
    console.log(i);
    var temp = (run_dice(xz[i]));
    //console.log(temp);
    xz[i] = temp;
  }
}
console.log(xz);

set data attribute to html elements from an array of strings

I have the following html structure

<div class="main">
    <div class="row">
        <div class="cell">one</div>
        <div class="cell">two</div>
        <div class="cell">three</div> 
        <div class="cell">four</div>
    </div>
    <div class="row">
        <div class="cell">one</div>
        <div class="cell">two</div>
        <div class="cell">three</div> 
        <div class="cell">four</div>
    </div>
    <div class="row">
        <div class="cell">one</div>
        <div class="cell">two</div>
        <div class="cell">three</div> 
        <div class="cell">four</div>
    </div>
    <div class="row">
        <div class="cell">one</div>
        <div class="cell">two</div>
        <div class="cell">three</div> 
        <div class="cell">four</div>
    </div>
    </div>

I’m trying to loop through each of the “cell’ class and set data attribute from an array of strings.

For ex. ["a", "b", "c", "d" ...]

The number of “cell” elements and number of elements in the array will always be the same

Expected output should be

<div class="main">
<div class="row">
    <div class="cell" data-label="a">one</div>
    <div class="cell" data-label="b">two</div>
    <div class="cell" data-label="c">three</div> 
    <div class="cell" data-label="d">four</div>
</div>
<div class="row">
    <div class="cell" data-label="a">one</div>
    <div class="cell" data-label="b">two</div>
    <div class="cell" data-label="c">three</div> 
    <div class="cell" data-label="d">four</div>
</div>
<div class="row">
    <div class="cell" data-label="a">one</div>
    <div class="cell" data-label="b">two</div>
    <div class="cell" data-label="c">three</div> 
    <div class="cell" data-label="d">four</div>
</div>
<div class="row">
    <div class="cell" data-label="a">one</div>
    <div class="cell" data-label="b">two</div>
    <div class="cell" data-label="c">three</div> 
    <div class="cell" data-label="d">four</div>
</div>    
</div>

I was able to loop through “rows” and convert it to an array of arrays and then got stuck on how to set data-attributes from another array. Do we need to iterate through each of “cell” elements in the “”row” and convert it into array or can we pass the data attribute through any other approach.

let phrases = ["a", "b", "c", "d"]
const rows = document.querySelectorAll(".row");
let cellArray = []
for (let i = 0; i < rows.length; i++) {
    const cells = rows[i].querySelectorAll(".cell")
    cellArray.push(cells)
}
for (let j = 0; j < cellArray.length; j++) {
    var value = parent[j];

    for (let k = 0; k < parent[j].length; k++) {
        var innerValue = parent[j][k];
    }
}

Making a table in react js without proper key values in json data

I am getting data from an API and it does not have proper key values and headers to use react-table. I am not sure how to generate table with the data

{
  "result": {
    "DB04571": {
      "CC1=CC2": -4.204354763031006
    },
    "DB00855": {
      "NCC(=O)": -3.666783332824707
    },
    "DB09536": {
      "O=[Ti]": -3.1173958778381348
    }
}}

The above is a sample of the data of 1000 entries. Below is the picture how i was expecting the table should be. as i am not having the headers for the json output i was unable to store them as a table as the value keeps on changing. while using react-table i should have to mention the headers but i cannot pull the data as the drug name keeps on changing in the data and their is no key attached to it.

enter image description here

UnhandledPromiseRejection error in React test

I am doing test on the React+Typescript using React Testing Library and Jest. This test could not run at all with the following error:

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason “TypeError: Cannot read properties of undefined (reading ‘json’)”.] {
code: ‘ERR_UNHANDLED_REJECTION’
}

Here is my test. Please help my to fix it.

const renderComponent = (): RenderResult => {
  return render(
      <List />,
    {}
  );
};

const { getByTestId, findByTestId, findByText } = screen;

const renderElements = (): any => {
  const component = renderComponent();
  return {
    deleteIcon: screen.getByTestId("delete-icon"),
    dialogPopup: screen.getByTestId("dialog-popup"),
    component,
  };
};

describe("When click on Delete icon", () => {
  it("should show Dialog Confirmation Popup", () => {
    const { deleteIcon, dialogPopup } = renderElements();
    userEvent.click(deleteIcon);
    expect(dialogPopup).toBeInTheDocument();
  });
});

How to change Html lang attribute from lang=”en” to lang=”ar” using JavaScript

welcome
I searched a lot here for a solution to my question and unfortunately I couldn’t find a definitive answer

I created language switch button between English as default and Arabic as second language and it works fine in changing the direction of my html page from left to right because the second language is Arabic, but the attribute (lang=”en”) in tag does not change to (lang=”ar”) When the page is turned to the right, assuming that the page content will be in Arabic.
Kindly Help me to implement this function.
please review the attribute lang on changing to RTL
I want when I press the converter button the value of attribute lang change from en to ar.
Thank You all,

(function ($) {
  "use strict";
  
$(".direction_switch button").click(function () {
    $("body").toggleClass(function () {
      return $(this).is(".rtl, .ltr") ? "rtl ltr" : "rtl";
    });
  });
  
  })(window.jQuery);
.ltr {
  direction: ltr;
}

.rtl {
  direction: rtl;
}
ul {
  list-style: none;
}
.menu {
  display: block;
}
.menu ul {
  display: inline-flex;
}
.menu ul li {
  padding: 0 10px;
}
body.ltr .demo-ltr {
  display: none;
}
body.ltr .demo-rtl {
  display: block;
}
body.ltr .demo-rtl button {
  background-color: transparent;
  color: #000;
  border: 1px solid;
  padding: 0px 10px;
}
body.rtl .demo-rtl {
  display: none;
}
body.rtl .demo-ltr {
  display: block;
}
body.rtl .demo-ltr button {
  background-color: transparent;
  color: #000;
  border: 1px solid;
  padding: 0px 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">

  <head>

  </head>

  <body class="ltr">
    <nav class="menu">
      <a href="">Logo</a>
      <ul>
        <li><a href="">Home</a></li>
        <li><a href="">Abou</a>t</li>
        <!-- page-direction -->
        <div class="page_direction">
          <div class="demo-rtl direction_switch"><button class="rtl">RTL</button>
          </div>
          <div class="demo-ltr direction_switch"><button class="ltr">LTR</button>
          </div>
        </div>
        <!-- page-direction end -->
      </ul>
    </nav>
  </body>

</html>

Different height on different screen sizes

I’m working on my website and I’m trying to use some waves to break up the background, however some errors occur when I resize my screen. The problem is that the wave start “flying” with a whitespace between the other wave when the screen is rezised, the error occurs since I need to adjust the waves height to 320px for it to be visible on a normal desktop view, since it is for some reason hidden behind the next div when the height is not set to 320px

Any ideas?

Code:

 <div class="feature" style="height: 320px;background: var(--primary-color);"><div><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 550"><path fill="var(--wave)" fill-opacity="1" d="M0,160L80,165.3C160,171,320,181,480,170.7C640,160,800,128,960,133.3C1120,139,1280,181,1360,202.7L1440,224L1440,320L1360,320C1280,320,1120,320,960,320C800,320,640,320,480,320C320,320,160,320,80,320L0,320Z"></path></svg></div></div>

What it looks like with 320px height on dekstop screen size:
https://cdn.discordapp.com/attachments/381547722374774784/943127798967566376/unknown.png

What it looks like with 320px height on small screen:
https://cdn.discordapp.com/attachments/381547722374774784/943127798694965288/unknown.png

If I set the height to 0px the wave is not visible on desktop since it hides under the next div, not sure why. Any help appreciated – thanks