JavaScript How to use Jointjs and SVG to draw element tools

I'm new to javascript and SVG and I have no graphical programming background and this is my first project using all of those. So I started to make a custom element just like Mike Goodwin answer proposed and I ended with this code after editing it:

joint.shapes.tools.tooledElement = joint.shapes.basic.Generic.extend({

    toolMarkup: [
        '<g class="element-tools">',
            '<g class="element-tool-remove"><circle fill="red" r="11" stroke="black" stroke-width="1"/>',
                '<path transform="scale(.7) translate(-16, -16)" stroke="black" stroke-width="1" d="M24.778,21.419 19.276,15.917 24.777,10.415 21.949,7.585 16.447,13.087 10.945,7.585 8.117,10.415 13.618,15.917 8.116,21.419 10.946,24.248 16.447,18.746 21.948,24.248z"/>',
                '<title>Remove this element from the model</title>',
            '</g>',
            '<g class="element-tool-link"><circle fill="green" r="11" cx="160" cy="40" stroke="black" stroke-width="1"/>',
                '<path transform="scale(.7) translate(-16, -16)"/>',
                '<title>creates a new link</title>',
            '</g>',
        '</g>'
    ].join(''),

    defaults: joint.util.deepSupplement({
        attrs: {
            text: { 'font-weight': 400, 'font-size': 'small', fill: 'black', 'text-anchor': 'middle', 'ref-x': .5, 'ref-y': .5, 'y-alignment': 'middle' }
        }
    }, joint.shapes.basic.Generic.prototype.defaults)

});

Which works properly. Now I would like to draw some line on the green circle and to make the red circle into a red square. To achieve this I looked at this tutorial on paths to draw and this tutorial on basic shapes. But if I try to make a line on the green circle like this:

'<path transform="scale(.7) translate(-16, -16)" stroke="black" stroke-width="1" d="x y L 10 10 " />' 

it won't draw anything. They do say " If your cursor already was somewhere on the page, no line is drawn to connect the two places." and that's why I omitted the "M" from path.

So here comes the first question: How can I draw the line on the center of the green circle without starting from the previous last point defined on any other path?

To make the red square I tried the exactly example from the second tutorial changing the fill (as a test):

//first line to test
<rect x="10" y="10" width="30" height="30" stroke="black" fill="red" stroke-width="5"/>

or

//second line to test
<rect x="60" y="10" rx="10" ry="10" width="30" height="30" stroke="black" fill="red" stroke-width="5"/>

The result of the first line would be the element at which the tools are being used to be draw again above itself like this:

First line test

And the second line would end up on nothing being show.

So here are the next questions:

Why did the results from the first line got like that? and How can I change the red circle into any other shape?

UPDATE: About the line draw:

'<path transform="scale(.7) translate(-16, -16)" stroke="black" stroke-width="1" d="M150 150 H 5 V 5 H 5 z" />'

If I use this code for example, this is the result:

enter image description here

'<path transform="scale(.7) translate(-16, -16)" stroke="black" stroke-width="1" d="M150 150 H 5 V 5 H 5 z" />'

If I use this other code then the result will be:

enter image description here

The tutorial led me to believe that M is defining the start point but changing the translate(-16, -16) to something else made the correct start point be possible. So its the translate attribute combined with M that set the starting point.

Answer:1

I want to make use of one html tag into my javascript but don't know how to make use of that. For ex: <p>An absolute URL: <a href="https://www.w3schools.com">W3Schools</a></p>...

I want to make use of one html tag into my javascript but don't know how to make use of that. For ex: <p>An absolute URL: <a href="https://www.w3schools.com">W3Schools</a></p>...

  1. html into javascript variable
  2. insert html into javascript
  3. import html into javascript
  4. html input into javascript variable
  5. convert html into javascript
  6. add html into javascript
  7. convert html into javascript string
  8. insert html into javascript variable
  9. embed html into javascript
  10. html into string javascript
  11. inject html into javascript
  12. turn html into javascript string
  13. html form into javascript variable
  14. turn html into javascript
  15. write html into javascript
  16. html code into javascript
  17. load html into javascript variable
  18. include html into javascript
  19. load html into javascript
  20. put html into javascript

I have developed and packaged an offline Cordova-based HTML5 App for Android. It works fine, and some of the resources are accessed locally without an internet connection while other require an ...

I have developed and packaged an offline Cordova-based HTML5 App for Android. It works fine, and some of the resources are accessed locally without an internet connection while other require an ...

I'm trying to prove that a simple function call such as window.alert(); is valid EcmaScript 2016 (7th Edition) grammar. Working backward, with the expectation this is an ExpressionStatement, I see ...

I'm trying to prove that a simple function call such as window.alert(); is valid EcmaScript 2016 (7th Edition) grammar. Working backward, with the expectation this is an ExpressionStatement, I see ...

  1. javascript function call itself
  2. javascript function call another function
  3. javascript function call vs apply
  4. javascript function call in html
  5. javascript function call overhead
  6. javascript function call method
  7. javascript function call not working
  8. javascript function call with parameters
  9. javascript function call performance
  10. javascript function call apply
  11. javascript function call failed null
  12. javascript function call stack
  13. javascript function call on load
  14. javascript function call syntax
  15. javascript function call by reference
  16. javascript function call two parentheses
  17. javascript function call on page load
  18. javascript function call on button click
  19. javascript function call without parentheses
  20. javascript function call inside function

I have a scrollable ul, and several li-items. My goal is to scroll to the li-item with certain id when the user presses a button. I have a code which seems to work, but there are two issues If I ...

I have a scrollable ul, and several li-items. My goal is to scroll to the li-item with certain id when the user presses a button. I have a code which seems to work, but there are two issues If I ...