Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
clear.canvas() draw2d function doesnt clear canvas exactly as needed

I have two radio buttons in my html code,

  <div>
    <h1>Select Your View</h1>
    <input type="radio"  id="first_view" name="first_view" value="first_view" onclick="CreateCanvas('first_view')">
    <label for="first_view">first_view</label>
    <input type="radio"  id="second_view" name="second_view" value="second_view" onclick="CreateCanvas('second_view')">
    <label for="second_view">second_view</label><br>
  </div>

Here is js code in another file. the canvas.clear doesn't clear the canvas.

function CreateCanvas(view){
    
    var canvas = new draw2d.Canvas("gfx_holder");

    if(view == "first_view")
        {
        canvas.clear();
        canvas.add(rect2);
    
    }
    else
    {
        canvas.clear();
        canvas.add(rect1);
    }
};

but if I add something like in the following code, clear canvas works perfectly.

function CreateCanvas(view){

var canvas = new draw2d.Canvas("gfx_holder");

if(view == "first_view")
    {
    canvas.add(rect1)
    canvas.clear();
    canvas.add(rect2);

}
else
{
    canvas.add(rect2)
    canvas.clear();
    canvas.add(rect1);
}

};

Why does adding something before clearing works in certain conditions? what is the right way to code here? I do not want to add unnecessary stuff to my canvas.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!