JavaScript resize the cell on cell in jointjs

I have a jointjs demo code, which has basic shapes on paper, i want to increase the size of the shape, or highlight the shape on pointer click or cursor moved on the shape,
sample demo code goes here

var graph = new joint.dia.Graph;

var paper = new joint.dia.Paper({

el: $('#paper'),
width: 650,
height: 400,
gridSize: 20,
model: graph
});

var rb = new joint.shapes.basic.Rect({
position: { x: 50, y: 50 },
size: { width: 100, height: 40 },
attrs: { text: { text: 'basic.Rect' } }
});
graph.addCell(rb);

var tb = new joint.shapes.basic.Text({
position: { x: 170, y: 50 },
size: { width: 100, height: 30 },
attrs: { text: { text: 'basic.Text' } }
});
graph.addCell(tb);

 var cb = new joint.shapes.basic.Circle({
position: { x: 300, y: 70 },
size: { width: 100, height: 40 },
attrs: { text: { text: 'basic.Circle' } }
});
graph.addCell(cb);

var ib = new joint.shapes.basic.Image({
position: { x: 450, y: 50 },
size: { width: 40, height: 40 },
attrs: {
    text: { text: 'basic.Image' },
    image: { 'xlink:href': 'https://cdn3.iconfinder.com/data/icons/betelgeuse/96/224386-folder-image-48.png', width: 48, height: 48 }
}
});
graph.addCell(ib);

var pb = new joint.shapes.basic.Path({
position: { x: 50, y: 150 },
size: { width: 40, height: 40 },
attrs: {
    path: { d: 'M25.979,12.896 19.312,12.896 19.312,6.229 12.647,6.229 12.647,12.896 5.979,12.896 5.979,19.562 12.647,19.562 12.647,26.229 19.312,26.229 19.312,19.562 25.979,19.562z' },
    text: { text: 'basic.Path' }
}
});
graph.addCell(pb);

var rh = new joint.shapes.basic.Rhombus({
position: { x: 50, y: 250 },
size: { width: 70, height: 70 },
attrs: { text: { text: 'basic.Rhombus', 'font-size': 8 } }
});
graph.addCell(rh);

var tbl = new joint.shapes.basic.TextBlock({
position: { x: 400, y: 180 },
size: { width: 180, height: 100 },
content: "Lorem ipsum dolor sit amet,\n consectetur adipiscing elit. Nulla vel porttitor est."
});
graph.addCell(tbl);


// An example of a custom element.
// -------------------------------

var MyElementWithPorts = joint.shapes.basic.Generic.extend({

  defaults: joint.util.deepSupplement({

   markup: [
       '<g class="rotatable">',
       '<g class="scalable">',
       '<rect/>',
       '</g>',
       '<g class="inPorts">',
       '<g class="port1"><circle/><text/></g>',
       '<g class="port2"><circle/><text/></g>',
       '</g>',
       '<g class="outPorts">',
       '<g class="port3"><circle/><text/></g>',
       '<g class="port4"><circle/><text/></g>',
       '</g>',
       '</g>'
   ].join(''),

   type: 'basic.Generic',
   attrs: {
       '.': { magnet: false },
       rect: {
           width: 150, height: 250,
           stroke: 'black'
       },
       circle: {
           r: 5,
           magnet: true,
           stroke: 'black'
       },
       text: {
           fill: 'black',
           'pointer-events': 'none'
       },
       '.label': { text: 'Model', dx: 5, dy: 5 },
       '.inPorts text': { dx:-15, 'text-anchor': 'end' },
       '.outPorts text':{ dx: 15 },
       '.inPorts circle': { fill: 'PaleGreen' },
       '.outPorts circle': { fill: 'Tomato' }
   }

 }, joint.shapes.basic.Generic.prototype.defaults)
});

var d = new MyElementWithPorts({
position: { x: 250, y: 150 },
size: { width: 80, height: 80 },
attrs: {
    '.port1 text': { text: 'port1' },
    '.port2 text': { text: 'port2' },
    '.port3 text': { text: 'port3' },
    '.port4 text': { text: 'port4' },
    '.port1': { ref: 'rect', 'ref-y': .2 },
    '.port2': { ref: 'rect', 'ref-y': .4 },
    '.port3': { ref: 'rect', 'ref-y': .2, 'ref-dx': 0 },
    '.port4': { ref: 'rect', 'ref-y': .4, 'ref-dx': 0 }        
}
});

graph.addCell(d);


// An example showing auto-resize of the joint.shapes.basic.Rect element based on the size of the text in it:

rb.on('change:attrs', function(element) {

var text = rb.attr(' /text');
var fontSize = parseInt(rb.attr('text/font-size'), 10);

var svgDocument = V('svg').node;
var textElement = V('<text><tspan></tspan></text>').node;
var textSpan = textElement.firstChild;
var textNode = document.createTextNode('');

textSpan.appendChild(textNode);
svgDocument.appendChild(textElement);
document.body.appendChild(svgDocument);

var lines = text.split('\n');
var width = 0;

// Find the longest line width.
_.each(lines, function(line) {

    textNode.data = line;
    var lineWidth = textSpan.getComputedTextLength();

    width = Math.max(width, lineWidth);
});

var height = lines.length * (fontSize * 1.2);

V(svgDocument).remove();

element.resize(width + 10, height);
});

paper.on('cell:pointerdown', 
function(cellView, evt, x, y) { 
//cellView.model.resize(cellView.model.height+2, cellView.model.width+2);
    cellView.model.resize(width + 10, height);  
    //rb.scale(rb.x+10,rb.y+10);        
    cellView.highlight(cellView.model.id);


}

);
paper.on('cell:pointerup', 
function(cellView, evt, x, y) {  
                //element.resize(width + 10, height);
    //          cellView.model.resize(cellView.model.width-2, cellView.model.height-2);
    cellView.unhighlight(cellView.model.id);    
}

);

I am new bee to jointjs.

i tried to resize the shape but it is not working

paper.on('cell:pointerdown', 
function(cellView, evt, x, y) { 
    alert('cell view ' + cellView.model.id + ' was clicked'); 
        var bbox = cellView.getBBox();
var strokeWidth = cellView.model.attr('rect/stroke-width') || 1;
console.log(isBorderClicked(bbox, x, y, strokeWidth))
    //cellView.model.id.resize(width + 10, height);

}

highlighting is happening by the click on the cell:

paper.on('cell:pointerdown', 
function(cellView, evt, x, y) { 
   // alert('cell view ' + cellView.model.id + ' was clicked' ); 
    cellView.highlight(cellView.model.id)    
        //element.resize(width + 10, height);

}

);
paper.on('cell:pointerup', 
function(cellView, evt, x, y) { 
    //alert('cell view ' + cellView.model.id + ' was released' ); 
    cellView.unhighlight(cellView.model.id)    
        //element.resize(width + 10, height);

}

But i want to resize the cell. when i click on the cell i should be able to resize the cell

please help me out solving this problem.

Answer:1

Let's say I have a row of divs like here: jsfiddle.net/AlphaCrack/veuc80he/1/ I wan't to animate them separately but keeping the same id because I may have to create tons of divs like those and I don'...

Let's say I have a row of divs like here: jsfiddle.net/AlphaCrack/veuc80he/1/ I wan't to animate them separately but keeping the same id because I may have to create tons of divs like those and I don'...

  1. apply same company different job
  2. apply same job different recruiters
  3. apply same css to different classes
  4. apply same formula to different cells
  5. apply same formula to different rows

I am using bootstrap validator v3.1.1 and I am trying to add regexp validation for a text box. I want to don't allow the user to introduce the space ' ', but alow to introduce letters, numers and ...

I am using bootstrap validator v3.1.1 and I am trying to add regexp validation for a text box. I want to don't allow the user to introduce the space ' ', but alow to introduce letters, numers and ...

  1. bootstrap validator regex example
  2. bootstrap validator regex
  3. bootstrap validator regex email
  4. bootstrap validator password regex
  5. bootstrap form validation regex
  6. bootstrap input validation regex
  7. bootstrap 4 validation regex

Hey everybody¡ I'm trying to paint a screen with multiple models and associated views in backbone. For this, I have respestive ajax calls to the server, to get data for this vies. First I considered ...

Hey everybody¡ I'm trying to paint a screen with multiple models and associated views in backbone. For this, I have respestive ajax calls to the server, to get data for this vies. First I considered ...

  1. render multiple views razor
  2. revit render multiple views
  3. express render multiple views
  4. yii2 render multiple views
  5. solidworks render multiple views
  6. rails render multiple views
  7. django render multiple views
  8. backbone render multiple views
  9. render multiple partial views
  10. laravel render multiple views
  11. angularjs render multiple views
  12. cakephp render multiple views
  13. how to render multiple views based on condition
  14. node.js render multiple views
  15. express js render multiple views
  16. how to render multiple views based on condition in mvc
  17. mvc render multiple partial views
  18. codeigniter render multiple views

Basically, I want to know if Collections work more like folders (they “physically contain” Models), or playlists (they contain a reference to Models). If they work like folders, is there a convention ...

Basically, I want to know if Collections work more like folders (they “physically contain” Models), or playlists (they contain a reference to Models). If they work like folders, is there a convention ...