How to maintain chart area in chart.js?

I’m making a website where people can browse data by region. Basically, it shows a bar chart, and there’s a dropdown menu at the top that updates the data based on the selection.

One detail I’m having trouble with: I’d like the area of the chart to be identical regardless of the data shown. However, depending on the magnitude of the data, the area beside the y-axis will be wider or narrower. You can see what I mean in the simplified example below. The second image has more space to the left of the chart to accommodate the larger numbers, which slightly squishes the area of the actual chart. I would like the chart area to be identical between charts.

Chart with narrow border

Chart with wider border

I’ve looked into the “padding” option, but it just seems to add white space around the chart, which isn’t quite what I want. Here’s some sample code. Anyone have any ideas?

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <script src="https://cdn.jsdelivr.net/npm/d3@7"></script>
        <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    </head>

    <body>

        <select name="nation_select" id="nation_dropdown" onchange=update_plot()>
            <option value="nation_1">Nation 1</option>
            <option value="nation_2">Nation 2</option>
        </select>
        <div><canvas id="canvas_national_ts" width="1000" height="480"></canvas></div>

        <script>

            // Make plot
            function update_plot() {
                nation_selected = document.getElementById('nation_dropdown').value;

                // Set the data
                var time = [1,2,3,4,5];
                if (nation_selected == 'nation_1') {var data = [1,2,1,3,2];}
                if (nation_selected == 'nation_2') {var data = [1000000,1040000,970000,1200000,900000];}

                // Make a plot
                const ctx_national_ts = document.getElementById('canvas_national_ts');
                if (Chart.getChart(ctx_national_ts)) {
                    Chart.getChart(ctx_national_ts).destroy();
                };
                var chart_national_ts = new Chart(ctx_national_ts, {
                    type: 'bar',
                    data: {
                        labels: time,
                        datasets: [{
                            data: data,
                        }]
                    }
                })
            }

            // Initial plot
            update_plot();

        </script>
    </body>
</html>

How does asynchronous programming work in JavaScript and how can I use async/await?

I’m trying to understand how asynchronous programming works in JavaScript. Can someone explain how async/await works with a simple example?

For example:

function fetchData() {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve('Data loaded');
    }, 1000);
  });
}

async function main() {
  const result = await fetchData();
  console.log(result);
}

main();

How does the async/await syntax help with handling asynchronous operations compared to using plain promises?

I’m newbie here please someone explain me Dudu dududu [closed]

Please explain me how to do that

This site, i’m new here and i don’t know how its going.
I just try what i can trys
B

LA BLABla

blaBlabla
BLA blablabla

hAhahahah
I don’t know what im doing
Test test test
Testing testing

Add up to 5 tags to describe what your question is about. Start typing to see suggestions.

javascript

Review questions already on Stack
Heheh
Heheheh
Hehehhee
Hehehhehehehe
Hehhehehe
Ahahha ahahaha ahahah

How can I replace a JavaScript URL with the file data

So I’m trying to port a website to a .html, and I think I’m almost there, but I’m just lost on this one step. In a JavaScript portion of the file, it referenced a file called “+new URL(./manifest.webmanifest)” which is blocked by the CORS policy. Thankfully, I have the data for manifest.webmanifest, so how can I write the manifest file right into the JavaScript part? (TLDR; How can I replace a URL() argument with the file’s code)

I tried writing the file URL but it still got blocked by the CORS policy. And because this is a local file, I don’t think I can bypass that.

JOLT Transformation – Matching logic

I have this JSON payload.

{
  "firstPayload": {
    "contactNumber": [
      {
        "id": "1",
        "mobileNum": "+447665463628",
        "mobileMask": "+44******628",
        "contactType": "mobile"
      },
      {
        "id": "2",
        "mobileNum": "+447665463111",
        "mobileMask": "+44******111",
        "contactType": "mobile"
      },
      {
        "id": "3",
        "mobileNum": "+447665463333",
        "mobileMask": "+44******333",
        "contactType": "mobile"
      },
      {
        "id": "4",
        "mobileNum": "+440674232123",
        "mobileMask": "+44******123",
        "contactType": "landline"
      }
    ]
  },
  "secondPayload": {
    "contactNumber": [
      {
        "id": "1",
        "mobileMask": "+44******628",
        "contactType": "mobile"
      }
    ]
  }
}

I want the output to be like this –

{"mobileNum" : "+447665463628"}

The match is based on exact match between secondPayload”.contactNumber”.”id” and “id” value present in “firstPayload”

How to achieve this in JOLT.

Is it allowed in javascript to modify the handler after proxy has already been created?

I modify the handler object after proxy’s creation, and obtain intended result. But nowhere in mdn document such pattern, can i rely on this pattern to work consistently across browser/in future?

const tar = {};
const handler = {
  get(target, prop, receiver){
    return 3;
  }
}
const p = new Proxy(tar, handler)
let before = p.x;
handler.get = (target, prop, receiver) => 4;
let after = p.x;
console.log(before, after) // 3, 4

How to download Facebook comment video with broken MP4s?

Please read this carefully as the high complexity of the context of this question negates all answers to supposed “related” questions.

  1. On this FB URL: https://www.facebook.com/watch/?v=1462397605169872
  2. There is a video posted in a comment that I want to download the source for, here is the MP4’s direct URL (as far as I can determine):
    https://video-lax3-2.xx.fbcdn.net/o1/v/t2/f2/m366/AQMU0Ao7LC293XZsDBvu9s5ngryEpEFDpV5nnilYJv61Pb573R1hbdNWEoYgmOewdbY7A0GUPB6x6TgFuUUV8s17lRrVqwbm3WNS_to.mp4
    
  3. In the DOM here is the blob URL that I have not been able to match to any URL requests or ids in the DOM: blob:https://www.facebook.com/7c50854b-0533-4f78-adde-58f634e25c32.

Clarifications:

  1. In the developer network panel the mp4 files requested do not work if directly requested.
  2. In the developer network panel there are NO m3u8 files requested.
  3. In the developer network panel there are NO related media files requested.
  4. Using “download Facebook videos!” website services only work for the videos of dedicated URLs, not when someone uploads a video in a comment.
  5. I am well versed in JavaScript though I am not sure if/how the video files are obscured by the blob URL.

How do I download the video posted in a comment on Facebook?

How can I prevent OBS virtual camera injection on my website?

I have a website that uses navigator.mediaDevices.getUserMedia to access the device’s webcam. Still, I noticed that some users are using a virtual camera (like OBS Virtual Camera) and injecting images and videos into my website through the camera.

I tried some ways to block this, like blocking cameras with ‘virtual’ in their names, but it continues happening because the users change the virtual camera’s name to whatever. How can I prevent this from happening?

Is there a way to open a mobile keyboard that inputs into a canvas in html?

I have an html file with a with a canvas (whose js and wasm comes from trunk-compiled rust code, which has text input boxes based in notan and egui). The canvas has rust-based text input boxes. On desktop, I can input into these boxes perfectly using my keyboard, however on mobile, no mobile keyboard appears, so I cannot input into my canvas. How can I make some form of mobile keyboard appear, preferably only by changing the html and js in my index.html?

I tried to use the canvas input on my phone, and expected the mobile keyboard to appear, but it did not.

Visual Studio Professional & Community 2022 – CodeLens – JavaScript – Not showing on async Functions

I am seeing an issue with Visual Studio 2022 Pro and Community Version 17.14.0

See screen shot, CodeLens is showing that there is “1 references” for the “Testing” function, but for the “Testing_Async” function, it is not showing any references. This only appears to be a problem when you use the async key word in front of the function

I am sure people will say there is a better way to do it, but I still think this is an issue with Visual Studio

Async function not showing references

How can I set a javascript const to a value in a form element that could be either a dropdown select or a checked radio button?

I have an html form in a django site that is used for both add and update. If the form is for a new entry, I want the field estimateType to be radio buttons with three choices, one of which is checked by default. If the form is for an edit to an existing entry, I want the form widget to change to a select dropdown with additional choices to pick from.

In the javascript in the onchange event, I need to know what the value of the estimateType field is. I can get it to work for select, or radio input, but not both. For example, what I have right now is:

const estimateType = document.querySelector(input[name=estimateType]:checked).value;

That works for a radio button but not the select dropdown. How can I use the same const declaration but account for heterogeneous form input types?

Angular PrimeNG. Drag n drop prevents all scrolls on page

I encountered a problem that when using the PrimeNG drag n drop module, when dragging an element, all scrolls on the page are completely broken. The mousewheel event does not work, although there is a scroll on the page.

Simple example: in their documentation, using the example
https://primeng.org/dragdrop#datatable try to drag an element and start scrolling the page – the page cannot be scrolled

I don’t know what workarounds can be thought up?

PrimeNG version: 19.1.2

MiHoYo Resume Auto-fill: Strange Ant Design DatePicker Behavior: Different Results with and without Breakpoint

Problem Description

I’m developing an auto-fill feature for MiHoYo’s resume system enter link description here and need to programmatically trigger the Ant Design DatePicker. I’ve encountered a peculiar issue:

Phenomenon:

  1. Without Breakpoint: The DatePicker dropdown appears, but there’s no blue selection bar

enter image description here

  1. With Breakpoint: When setting a breakpoint at inputs[0].dispatchEvent(mousedownEvent);, not only does the dropdown appear, but a blue selection bar also appears, indicating proper selection

enter image description here

This blue selection bar is crucial for subsequent operations as it signifies a true “selection” state. Without it, further date selection operations cannot proceed normally.

Relevant Code

// Initialization
const rangePickerContainer = findAncestorWithClass(inputElement, "ant-picker-range");
const inputs = rangePickerContainer.querySelectorAll("input");

// Trigger events
const focusEvent = new FocusEvent("focus", {
  bubbles: true,
  cancelable: true,
  view: window
});
inputs[0].dispatchEvent(focusEvent);

const mousedownEvent = new MouseEvent("mousedown", {
  bubbles: true,
  cancelable: true,
  view: window
});

// When a breakpoint is set here, the blue selection bar appears and everything works
inputs[0].dispatchEvent(mousedownEvent);
inputs[0].click();

Analysis

It seems that setting a breakpoint changes the timing of event processing, giving the Ant Design component enough time to complete its internal state updates. This might be related to React’s event system or the specific implementation of Ant Design components.

Questions

  1. Why does the component behave differently with and without a breakpoint?
  2. How can I achieve the same effect as with a breakpoint, but in normal code execution?
  3. Is there a more reliable method to programmatically trigger the true selection state of the Ant Design DatePicker?