Disallow particular cell to stretch - jgraph

How to disallow particular cell to stretch ?
"graph.setCellsResizable(false)" There are methods for all cells, how to apply it to a particular cell.

You need to add resizable=0; to the style of that cell.

By adding custom styles we can stop resizing and moving of vertex
First initialize style object
var style = new Object();
style[mxConstants.STYLE_RESIZABLE] = '0';
Then add style in graph stylesheet
graph.getStylesheet().putCellStyle('resizableLock', style);
Then plot vertex with the custom style name
var v1 = graph.insertVertex(parent,'1233','Hello',20,50,100,100,'resizableLock');

Related

Photoshop Scripting select contents of a layer & color

Using a javascript script in Photoshop 2022 (v 23.0.1), I am trying to change the color of a single item in one of my layers. I can access the layer, but I cannot change the color of it's contents.
var document = activeDocument;
var groupA = document.layers["Group"];
var layerA = groupA.layers["Layer In Group"];
var layerB = groupA.layers["Clipping Mask for layerA"];
The layerA contains a single item which is colored white. I'd like to change it's color.
I assume I need to select the contents of that layer, then apply a color to it. But I'm not sure this is the best way to do this.
I could also add a clipping mask for that layer, then fill that with color. Would this be easier/better?
Ideally I'd like to change it using a hex color code, but any way I can change it would be fine.
UPDATE: I was able to solve the problem by making the layer the activeLayer in the document.
// set the active layer to the layer requiring fill color
document.activeLayer = layerB;
// getBodyFillColor() is my method that returns the correct color
var color = getBodyFillColor();
// Once I set the active layer, it's automatically the selection layer?? (not sure how this works)
document.selection.fill(color);
You could just fill with a colour:
// Fill colour
var myRGBCol = [255, 0, 128]; //define your colour here
var col = new SolidColor;
col.rgb.red = myRGBCol[0];
col.rgb.green = myRGBCol[1];
col.rgb.blue = myRGBCol[2];
var blend = ColorBlendMode.NORMAL; // Normal
var op = 100; // opacity
document.selection.fill(col, blend, op, false);

Vis.js Gap between Node and its border

Using Vis.js I want to Generate something where in there is a gap between the Circular image and the Node border
Sample:
I cannot find anything at the Vis.js documentation for such a modification, can anyone guide me for it?
vis.js GitHub issue report
There's no way to achieve this unfortunelly. The color option only accepts one border and you can't make use of CSS since Vis is built using canvas, not SVG.
What you can do to achieve this is crop your image in a circular shape with some transparent padding to make the gap. And then vis would add the black border for you.
yes you can do that.do not add border option in node.you can add circular border in afterDrawing event.
network.on("afterDrawing", function (ctx) {
var imageSize= 21;
var nodeId = 1;
var nodePosition = network.getPositions([nodeId]);
ctx.strokeStyle = '#006bb3';
ctx.lineWidth = 4;
ctx.circle(nodePosition[nodeId].x, nodePosition[nodeId].y, imageSize+5);
ctx.stroke();
})

constrain proportions while resizing images

I implemented drag and drop of images and now i want to constrain proportions of images while resizing.
/**
* Variable: constrainChildrenOnResize
*
* Specifies if children should be constrained according to the <constrainChildren>
* switch if cells are resized (including via <foldCells>). Default is false for
* backwards compatiblity.
*/
mxGraph.prototype.constrainChildrenOnResize = false;
i set this to true but its not working :s
What API/property i need for this functionality..
constrainChildrenOnResize is responsible for positioning and size of the children of resized cell. It means that children should keep their position relatively to the parent-cell.
In your case I would suggest to extend mxVertexHandler using union method. In this example you can see how to implement min-width/min-height restrictions. Using this example you are able to write your own rules for constrain.
Here is my simple solution:
var vertexHandlerUnion = mxVertexHandler.prototype.union;
mxVertexHandler.prototype.union = function (bounds) {
var result = vertexHandlerUnion.apply(this, arguments);
var coff = bounds.width / bounds.height
result.width = result.height * coff;
return result;
};
So this function is called every time you move mouse during dragging the resizer.
bounds - object, always same and represent old geometry of the cell (before resizing)
result - object, represents new values, which are going to be applied. Between this line ad return statement you can place any code you need to modify result.
In my simple example I just get the initial relation between width and height of the cell (coff) and then set new width by multiplying coff and new height. It will work if you drag corner or top/bottom. In real project this logic should be slightly extended, or you should make visible only corner handlers.
By the way, this code will work for all resizable cells on your graph. If you want to apply it only to images or some other kind of cells - you can put condition and check the cell type before recalculating. You can get current cell or its state via this.state.cell or this.state inside of union function.
For example only for vertecies:
... ...
var result = vertexHandlerUnion.apply(this, arguments);
if (this.state.cell.isVertex()) {
//calculations here
}
return result;

adding textfield over movieclip images

I have several images, which are Symbols (movieClip) with Alpha parameter.
And i'm creating dynamic textfield from AS3 to be able change text every few seconds.
Problem is that everything worked good till i converted images to MovieClips. But after that my textfields are not visible.
Here is the code:
textFormat = new TextFormat();
textfield = new TextField();
textFormat.font = new customFonts().fontName;
textFormat.size = 16;
textFormat.align = "center";
textFormat.color = 0xFFFFFF;
textfield.defaultTextFormat = textFormat;
textfield.embedFonts = true;
textfield.width = 480;
textfield.height = 95;
textfield.x = 185;
textfield.y = 22;
textfield.wordWrap = true;
addChild (textfield);
So the question is - how to bring this textfield to the top so it would be visible?
You're adding your Text field after the movie clips are being initiated. Think of it as a layer, the text field is at the bottom layer, hence they will not be seen.
I would look at the container class
The Container class is an abstract base class for components that controls the layout characteristics of child components. You do not create an instance of Container in an application. Instead, you create an instance of one of Container's subclasses, such as Canvas or HBox.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/Container.html
You should be able to change what is displayed.
EDIT:
Anytime you add a clip it is added on top by default.
You should also look into Z-Index.
If you are coding with Flash Develop then it can get tricky, whilst using Flash Adobe CC can make your life so much easier!
Sorry if it's not that much of an answer.

iTextSharp Table Cell Spacing Possible?

Is it possible to have cell spacing within a table (PdfPTable) in iTextSharp? I can't see anywhere that it is possible. I did see one suggestion of using the iTextSharp.text.Table instead but that doesn't seem available on my version of iTextSharp (5.2.1).
If you're looking for true cell spacing like HTML's then no, the PdfPTable doesn't support that natively. However, the PdfPCell supports a property that takes a custom implementation of IPdfPCellEvent which will get called whenever a cell layout happens. Below is a simple implementation of one, you'll probably want to tweak it to your needs.
public class CellSpacingEvent : IPdfPCellEvent {
private int cellSpacing;
public CellSpacingEvent(int cellSpacing) {
this.cellSpacing = cellSpacing;
}
void IPdfPCellEvent.CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
//Grab the line canvas for drawing lines on
PdfContentByte cb = canvases[PdfPTable.LINECANVAS];
//Create a new rectangle using our previously supplied spacing
cb.Rectangle(
position.Left + this.cellSpacing,
position.Bottom + this.cellSpacing,
(position.Right - this.cellSpacing) - (position.Left + this.cellSpacing),
(position.Top - this.cellSpacing) - (position.Bottom + this.cellSpacing)
);
//Set a color
cb.SetColorStroke(BaseColor.RED);
//Draw the rectangle
cb.Stroke();
}
}
To use it:
//Create a two column table
PdfPTable table = new PdfPTable(2);
//Don't let the system draw the border, we'll do that
table.DefaultCell.Border = 0;
//Bind our custom event to the default cell
table.DefaultCell.CellEvent = new CellSpacingEvent(2);
//We're not changing actual layout so we're going to cheat and padd the cells a little
table.DefaultCell.Padding = 4;
//Add some cells
table.AddCell("Test");
table.AddCell("Test");
table.AddCell("Test");
table.AddCell("Test");
doc.Add(table);
The Table class has been removed from iText starting from 5.x, in favor of PdfPTable.
As for spacing, what you are looking for are the setPadding methods.
Have a look at iText's API for more information:
http://api.itextpdf.com/itext/com/itextpdf/text/pdf/PdfPCell.html
(It's for the Java version, but the C# port maintains the names of the methods)