Extendscript how do i align my text to be above listbox - extendscript

i want my text to be above each listbox however it seems not to align well
this is my text code
var t = Main.add("statictext", undefined, "Hello", {multiline:false});
t.text = "Solids with video co pilot";
t.graphics.foregroundColor = t.graphics.newPen (t.graphics.PenType.SOLID_COLOR, [0.0, 1.0, 1.0], 1);
t.graphics.font = ScriptUI.newFont ("Arial", "Bold", 30);
kindly assist me thank you.
var dialog = new Window("dialog");
dialog.text = "Dialog";
dialog.preferredSize.width = 380;
dialog.preferredSize.height = 520;
dialog.orientation = "column";
dialog.alignChildren = ["fill","top"];
dialog.spacing = 10;
dialog.margins = 16;
// TPANEL
// ======
var tpanel = dialog.add("tabbedpanel", undefined, undefined, {name: "tpanel"});
tpanel.alignChildren = "fill";
tpanel.preferredSize.width = 348;
tpanel.margins = 0;
// CLRTAB
// ======
var Main1 = tpanel.add("tab", undefined, undefined, {name: "clrTab"});
Main1.text = "Main1";
Main1.orientation = "column";
Main1.alignChildren = ["fill","top"];
Main1.spacing = 10;
Main1.margins = 30;
var Main = tpanel.add("tab", undefined, undefined, {name: "clrTab"});
Main.text = "Main";
Main.orientation = "column";
Main.alignChildren = ["fill","top"];
Main.spacing = 10;
Main.margins = 10;
// CLRTAB_LSTGRP
// =============
var clrTab_LstGrp = Main.add("group", undefined, {name: "clrTab_LstGrp"});
//clrTab_LstGrp.orientation = "row";
clrTab_LstGrp.alignChildren = ["left","center"];
clrTab_LstGrp.spacing = 10;
clrTab_LstGrp.margins = 0;
var t = clrTab_LstGrp.add("statictext", undefined, "Hello", {multiline:false});
t.text = "Create Solids";
t.graphics.foregroundColor = t.graphics.newPen (t.graphics.PenType.SOLID_COLOR, [0.0, 1.0, 1.0], 1);
t.graphics.font = ScriptUI.newFont ("Arial", "Bold", 30);
var listBoxxc_array = [
"Create 2 solids",
"Create Solid",
"Create Solid with fractual noise",
"Create Solid CC Particle World",
"Create Solid Particular",
"Solid With BCC Sphere",
"Solid With BCC Turbulence",
"Solid With BCC Bulge",
"Solid With BCC Tritone",
"Solid With BCC Fractal Noise",
"Solid With BCC Rays",
"Solid With BCC Rain",
"Solid With BCC Rock",
"Solid With BCC Snow",
"Solid With BCC Particle System",
"Solid With BCC Edge Lighting",
"Solid With BCC Light Zoom",
"Solid With BCC Rays Ring",
"Solid With BCC Rays Ripply",
"Solid With BCC Rays Streaky",
"Solid With BCC Rays Puffy",
"Solid With BCC Rays Wedge",
];
var listBoxxc = clrTab_LstGrp.add("listbox", undefined, undefined, {name: "listBoxxc", items: listBoxxc_array});
listBoxxc.preferredSize.width = 300;
listBoxxc.size = [340, 200];
var t = Main.add("statictext", undefined, "Hello", {multiline:false});
t.text = "Solids with video co pilot";
t.graphics.foregroundColor = t.graphics.newPen (t.graphics.PenType.SOLID_COLOR, [0.0, 1.0, 1.0], 1);
t.graphics.font = ScriptUI.newFont ("Arial", "Bold", 30);
var listBoxxb_array = [
"Create solid with element",
"Create solid with saber",
"Create solid with Vc orb",
"Create solid with Optical Flares",
"Create solid with Twitch",
"Create solid with heat Distortion",
];
var listBoxxb = Main.add("listbox", undefined, undefined, {name: "listBoxxb", items: listBoxxb_array});
listBoxxb.preferredSize.width = 300;
listBoxxb.size = [100, 130];
var listBoxxn_array = [
"Create Angle Control",
"Create Color Control",
"Create Checkbox Control",
"Create Layer Control",
"Create Point Control",
"Create Slider Control"
];
listBoxxb.size = [100, 130];
var listBoxxn = Main.add("listbox", undefined, undefined, {name: "listBoxxn", items: listBoxxn_array});
listBoxxn.preferredSize.width = 300;
// CLRTAB_BTNGRP
// =============
var clrTab_BtnGrp = Main.add("group", undefined, {name: "clrTab_BtnGrp"});
clrTab_BtnGrp.orientation = "row";
clrTab_BtnGrp.alignChildren = ["left","center"];
clrTab_BtnGrp.spacing = 10;
clrTab_BtnGrp.margins = 0;
var testBtn = Main.add("button", undefined, undefined, {name: "testBtn"});
testBtn.text = "Test";
var testBtn1 = Main.add("button", undefined, undefined, {name: "testBtn"});
testBtn1.text = "Test";
var testBtn2 = Main.add("button", undefined, undefined, {name: "testBtn"});
testBtn2.text = "Test";
var testBtn3 = Main.add("button", undefined, undefined, {name: "testBtn"});
testBtn3.text = "Test";
var testBtn4 = Main.add("button", undefined, undefined, {name: "testBtn"});
testBtn4.text = "Test";
var testBtn5 = Main.add("button", undefined, undefined, {name: "testBtn"});
testBtn5.text = "Test";
var testBtn6 = Main.add("button", undefined, undefined, {name: "testBtn"});
testBtn6.text = "Test";
// GENTAB
// ======
var genTab = tpanel.add("tab", undefined, undefined, {name: "genTab"});
genTab.text = "Solids";
genTab.orientation = "column";
genTab.alignChildren = ["left","top"];
genTab.spacing = 10;
genTab.margins = 10;
var clrTab = tpanel.add("tab", undefined, undefined, {name: "clrTab"});
clrTab.text = "Effects Fast";
clrTab.orientation = "column";
clrTab.alignChildren = ["fill","top"];
clrTab.spacing = 10;
clrTab.margins = 10;
var clrTab = tpanel.add("tab", undefined, undefined, {name: "clrTab"});
clrTab.text = "Comp Settings";
clrTab.orientation = "column";
clrTab.alignChildren = ["fill","top"];
clrTab.spacing = 10;
clrTab.margins = 10;
var clrTab = tpanel.add("tab", undefined, undefined, {name: "clrTab"});
clrTab.text = "Comp Settings2";
clrTab.orientation = "column";
clrTab.alignChildren = ["fill","top"];
clrTab.spacing = 10;
clrTab.margins = 10;
var clrTab = tpanel.add("tab", undefined, undefined, {name: "clrTab"});
clrTab.text = "More";
clrTab.orientation = "column";
clrTab.alignChildren = ["fill","top"];
clrTab.spacing = 10;
clrTab.margins = 10;
// TPANEL
// ======
//tpanel.selection = clrTab;
tpanel.selection = Main;
dialog.show();

It appears as though you just need to set orientation of clrTab_LstGrp to be column. Like so:
clrTab_LstGrp.orientation = "column";
I've also noticed that you have a bunch of tabs all with the same variable name, clrTab. You will want to give those separate names before you try to add contents to them. Otherwise, it you will only be able to add to the last one.
Another thing is that you've created a group called clrTab_BtnGrp. But you're still adding your buttons to Main. Did you want to add your buttons to this group? If so you need to do this:
var testBtn = clrTab_BtnGrp.add("button", undefined, undefined, {name: "testBtn"});
[EDIT]
I took a bit of time to clean up your code. A lot of what I've done is just for aesthetics or to align more properly with standard coding conventions. However, there were issues with your code that I would say needed some improvement. Such as reusing variable names, which shouldn't really be done unless the variable is no longer in use. An example of this is where you used the variable name t for each of your static-texts.
I also created groups that I thought made more sense.
var dialog = new Window("dialog");
dialog.text = "Dialog";
dialog.preferredSize.width = 380;
dialog.preferredSize.height = 520;
dialog.orientation = "column";
dialog.alignChildren = ["fill","top"];
dialog.spacing = 10;
dialog.margins = 16;
// TPANEL
// ======
var tpanel = dialog.add("tabbedpanel", undefined, undefined, {name: "tpanel"});
tpanel.alignChildren = "fill";
tpanel.preferredSize.width = 348;
tpanel.margins = 0;
// MAIN1 TAB
// ======
var Main1 = tpanel.add("tab", undefined, undefined, {name: "main_tab_1"});
Main1.text = "Main1";
Main1.orientation = "column";
Main1.alignChildren = ["fill","top"];
Main1.spacing = 10;
Main1.margins = 30;
// MAIN TAB
// ======
var Main = tpanel.add("tab", undefined, undefined, {name: "main_tab"});
Main.text = "Main";
Main.orientation = "column";
Main.alignChildren = ["fill","top"];
Main.spacing = 10;
Main.margins = 10;
// CREATE SOLIDS GROUP
var createSolidsGrp = Main.add("group", undefined, {name: "create_solids_group"});
createSolidsGrp.orientation = "column";
createSolidsGrp.alignChildren = ["fill","center"];
createSolidsGrp.spacing = 10;
createSolidsGrp.margins = 0;
var createSolidsTxt = createSolidsGrp.add("statictext", undefined, undefined, {multiline:false});
createSolidsTxt.text = "Create Solids";
createSolidsTxt.graphics.foregroundColor = createSolidsTxt.graphics.newPen (createSolidsTxt.graphics.PenType.SOLID_COLOR, [0.0, 1.0, 1.0], 1);
createSolidsTxt.graphics.font = ScriptUI.newFont ("Arial", "Bold", 30);
var listBoxxc_array = [
"Create 2 solids",
"Create Solid",
"Create Solid with fractual noise",
"Create Solid CC Particle World",
"Create Solid Particular",
"Solid With BCC Sphere",
"Solid With BCC Turbulence",
"Solid With BCC Bulge",
"Solid With BCC Tritone",
"Solid With BCC Fractal Noise",
"Solid With BCC Rays",
"Solid With BCC Rain",
"Solid With BCC Rock",
"Solid With BCC Snow",
"Solid With BCC Particle System",
"Solid With BCC Edge Lighting",
"Solid With BCC Light Zoom",
"Solid With BCC Rays Ring",
"Solid With BCC Rays Ripply",
"Solid With BCC Rays Streaky",
"Solid With BCC Rays Puffy",
"Solid With BCC Rays Wedge",
];
var listBoxxc = createSolidsGrp.add("listbox", undefined, undefined, {name: "listBoxxc", items: listBoxxc_array});
listBoxxc.size = [340, 200];
// SOLIDS WITH VIDEO COPILOT GROUP
var vidCopGrp = Main.add("group", undefined, {name: "create_solids_group"});
vidCopGrp.orientation = "column";
vidCopGrp.alignChildren = ["fill","center"];
vidCopGrp.spacing = 10;
vidCopGrp.margins = 0;
var vidCopTxt = vidCopGrp.add("statictext", undefined, undefined, {multiline:false});
vidCopTxt.text = "Solids with video co pilot";
vidCopTxt.graphics.foregroundColor = vidCopTxt.graphics.newPen (vidCopTxt.graphics.PenType.SOLID_COLOR, [0.0, 1.0, 1.0], 1);
vidCopTxt.graphics.font = ScriptUI.newFont ("Arial", "Bold", 30);
var listBoxxb_array = [
"Create solid with element",
"Create solid with saber",
"Create solid with Vc orb",
"Create solid with Optical Flares",
"Create solid with Twitch",
"Create solid with heat Distortion",
];
var listBoxxb = vidCopGrp.add("listbox", undefined, undefined, {name: "listBoxxb", items: listBoxxb_array});
listBoxxb.size = [100, 130];
// EXPRESSION CONTROLS GROUP
var expCtrlGrp = Main.add("group", undefined, {name: "create_solids_group"});
expCtrlGrp.orientation = "column";
expCtrlGrp.alignChildren = ["fill","center"];
expCtrlGrp.spacing = 10;
expCtrlGrp.margins = 0;
var expCtrlTxt = expCtrlGrp.add("statictext", undefined, undefined, {multiline:false});
expCtrlTxt.text = "Expression Controls";
expCtrlTxt.graphics.foregroundColor = expCtrlTxt.graphics.newPen (expCtrlTxt.graphics.PenType.SOLID_COLOR, [0.0, 1.0, 1.0], 1);
expCtrlTxt.graphics.font = ScriptUI.newFont ("Arial", "Bold", 30);
var listBoxxn_array = [
"Create Angle Control",
"Create Color Control",
"Create Checkbox Control",
"Create Layer Control",
"Create Point Control",
"Create Slider Control"
];
var listBoxxn = expCtrlGrp.add("listbox", undefined, undefined, {name: "listBoxxn", items: listBoxxn_array});
listBoxxn.size = [100, 130];
// CLRTAB_BTNGRP
// =============
var mainTab_BtnGrp = Main.add("group", undefined, {name: "main_tab_btn_group"});
mainTab_BtnGrp.orientation = "column";
mainTab_BtnGrp.alignChildren = ["fill","center"];
mainTab_BtnGrp.spacing = 10;
mainTab_BtnGrp.margins = 0;
var testBtn = mainTab_BtnGrp.add("button", undefined, undefined, {name: "testBtn"});
testBtn.text = "Test";
var testBtn1 = mainTab_BtnGrp.add("button", undefined, undefined, {name: "testBtn1"});
testBtn1.text = "Test";
var testBtn2 = mainTab_BtnGrp.add("button", undefined, undefined, {name: "testBtn2"});
testBtn2.text = "Test";
var testBtn3 = mainTab_BtnGrp.add("button", undefined, undefined, {name: "testBtn3"});
testBtn3.text = "Test";
var testBtn4 = mainTab_BtnGrp.add("button", undefined, undefined, {name: "testBtn4"});
testBtn4.text = "Test";
var testBtn5 = mainTab_BtnGrp.add("button", undefined, undefined, {name: "testBtn5"});
testBtn5.text = "Test";
var testBtn6 = mainTab_BtnGrp.add("button", undefined, undefined, {name: "testBtn6"});
testBtn6.text = "Test";
// SOLIDS TAB
var genTab = tpanel.add("tab", undefined, undefined, {name: "genTab"});
genTab.text = "Solids";
genTab.orientation = "column";
genTab.alignChildren = ["left","top"];
genTab.spacing = 10;
genTab.margins = 10;
var effFastTab = tpanel.add("tab", undefined, undefined, {name: "effects_fast_tab"});
effFastTab.text = "Effects Fast";
effFastTab.orientation = "column";
effFastTab.alignChildren = ["fill","top"];
effFastTab.spacing = 10;
effFastTab.margins = 10;
var compSet1Tab = tpanel.add("tab", undefined, undefined, {name: "comp_settings_1_tab"});
compSet1Tab.text = "Comp Settings";
compSet1Tab.orientation = "column";
compSet1Tab.alignChildren = ["fill","top"];
compSet1Tab.spacing = 10;
compSet1Tab.margins = 10;
var compSet2Tab = tpanel.add("tab", undefined, undefined, {name: "comp_settings_2_tab"});
compSet2Tab.text = "Comp Settings2";
compSet2Tab.orientation = "column";
compSet2Tab.alignChildren = ["fill","top"];
compSet2Tab.spacing = 10;
compSet2Tab.margins = 10;
var moreTab = tpanel.add("tab", undefined, undefined, {name: "more_tab"});
moreTab.text = "More";
moreTab.orientation = "column";
moreTab.alignChildren = ["fill","top"];
moreTab.spacing = 10;
moreTab.margins = 10;
tpanel.selection = Main;
dialog.show();

Related

extendscript cant align button or center button below listbox

My button is floating on top of the list box. I want it to sit right under the list box.
I will be adding more buttons and just want to know why this is not working.
If anybody can assist on this will be grateful.
var objDlg = new Window ("dialog", "パネル", [0,0,300,150]);
//var objDlg = new Window ("dialog", "Abas", [0,0,0,0]);
objDlgorientation = 'column';
// w.margins = 5;
// w.spacing = 10;
objDlg.alignChildren = ['fill', 'fill'];
objDlg.size = [380, 520]
var tpanel = objDlg.add ("tabbedpanel" ,[10,10,0,0],);
var general = tpanel.add ("tab", [0,0,0,0], "Color");
var general1 = tpanel.add ("tab", [0,0,0,0], "general");
var general2 = tpanel.add ("tab", [0,0,0,0], "playstation");
var general3 = tpanel.add ("tab", [0,0,0,0], "xbox 360");
var general4 = tpanel.add ("tab", [0,0,0,0], "xbox 360");
var general5 = tpanel.add ("tab", [0,0,0,0], "xbox 360");
var general6 = tpanel.add ("tab", [0,0,0,0], "xbox 360");
var general7 = tpanel.add ("tab", [0,0,0,0], "xbox 360");
var listBoxxc = general.add("listbox", [10,30,180,110], []);
listBoxxc.selection = 0;
listBoxxc.size = [340, 200];
listBoxxc.add("item", "Create Angle Control");
listBoxxc.add("item", "Create Color Control");
listBoxxc.add("item", "Create Checkbox Control");
listBoxxc.add("item", "Create Layer Control");
listBoxxc.add("item", "Create Point Control");
listBoxxc.add("item", "Create Slider Control");
testBtn = general.add( "button", [40,90,110,110], "Test" );
tpanel.size = [360,300];
objDlg.center();
objDlg.show();
I believe that you will need to group the Listbox and the Button separately. My code is a little different to yours, but this works:
var dialog = new Window("dialog");
dialog.text = "Dialog";
dialog.preferredSize.width = 380;
dialog.preferredSize.height = 520;
dialog.orientation = "column";
dialog.alignChildren = ["fill","top"];
dialog.spacing = 10;
dialog.margins = 16;
// TPANEL
// ======
var tpanel = dialog.add("tabbedpanel", undefined, undefined, {name: "tpanel"});
tpanel.alignChildren = "fill";
tpanel.preferredSize.width = 348;
tpanel.margins = 0;
// CLRTAB
// ======
var clrTab = tpanel.add("tab", undefined, undefined, {name: "clrTab"});
clrTab.text = "Color";
clrTab.orientation = "column";
clrTab.alignChildren = ["fill","top"];
clrTab.spacing = 10;
clrTab.margins = 10;
// CLRTAB_LSTGRP
// =============
var clrTab_LstGrp = clrTab.add("group", undefined, {name: "clrTab_LstGrp"});
clrTab_LstGrp.orientation = "row";
clrTab_LstGrp.alignChildren = ["left","center"];
clrTab_LstGrp.spacing = 10;
clrTab_LstGrp.margins = 0;
var listBoxxc_array = [
"Create Angle Control",
"Create Color Control",
"Create Checkbox Control",
"Create Layer Control",
"Create Point Control",
"Create Slider Control"
];
var listBoxxc = clrTab_LstGrp.add("listbox", undefined, undefined, {name: "listBoxxc", items: listBoxxc_array});
listBoxxc.preferredSize.width = 300;
// CLRTAB_BTNGRP
// =============
var clrTab_BtnGrp = clrTab.add("group", undefined, {name: "clrTab_BtnGrp"});
clrTab_BtnGrp.orientation = "row";
clrTab_BtnGrp.alignChildren = ["left","center"];
clrTab_BtnGrp.spacing = 10;
clrTab_BtnGrp.margins = 0;
var testBtn = clrTab_BtnGrp.add("button", undefined, undefined, {name: "testBtn"});
testBtn.text = "Test";
// GENTAB
// ======
var genTab = tpanel.add("tab", undefined, undefined, {name: "genTab"});
genTab.text = "General";
genTab.orientation = "column";
genTab.alignChildren = ["left","top"];
genTab.spacing = 10;
genTab.margins = 10;
// TPANEL
// ======
tpanel.selection = clrTab;
dialog.show();

Canvas and discord.js text is all "▯"

my code runs first perfectly but now not anymore.
its a welcome card for a discord server.
here's how it should have looked:
https://imgur.com/GEcULY5.png
and here's how it looks now:
https://imgur.com/cHLr2Bi.png
here is the code:
client.on("guildMemberAdd",async member => {
var name = member.displayName
var id = member.id
var membercount = member.guild.memberCount
var displayAvatarURL = member.user.displayAvatarURL({format:"jpg"})
var joinimage = Canvas.createCanvas(2000,1000)
var ctx = joinimage.getContext("2d")
var background = await Canvas.loadImage("./background.png")
ctx.drawImage(background,0,0,2000,1000)
ctx.textAlign = "center"
ctx.font = '120px Arial';
ctx.fillStyle = '#ffffff';
ctx.fillText("welkom",1400,400)
ctx.fillText(name,1400,550)
ctx.font = '60px Arial';
ctx.fillText(("Maak veel plezier in PixelKingdoms!"),1400,750)
const avatar = await Canvas.loadImage(displayAvatarURL)
ctx.beginPath();
ctx.arc(500, 500, 300, 0, 2 * Math.PI);
ctx.clip();
ctx.drawImage(avatar, 200, 200, 600, 600);
ctx.lineWidth = 20;
ctx.strokeStyle = "white";
ctx.stroke();
ctx.closePath()
const attachment = new discord.MessageAttachment(joinimage.toBuffer(), 'welcome-image.png');
member.guild.channels.cache.get("873169519881900033").send("Hey <#"+id+">Welkom in **"+member.guild.name+"**!",attachment)
var fanrole = member.guild.roles.cache.get("873163741276033084")
member.roles.add(fanrole)
})```
(sorry for bad english)

GetCursorPos Node FFI - How to get pointer return by ref

I wrote following code to set keyboard cursor position. But get garbage. Any clue, what am I missing?
var ffi = require('ffi');
var ref = require('ref');
var Struct = require('ref-struct');
var point = Struct({
'x': 'long',
'y': 'long'
});
var user32 = ffi.Library('user32.dll', {
GetCaretPos:['bool',[locPtr]]
});
var pbuf = new point();
caretpos = user32.GetCaretPos(pbuf);
console.log(":",pbuf.x );
Next, I tried the following, but that doesn't work as well.
var ffi = require('ffi');
var ref = require('ref');
var Struct = require('ref-struct');
var voidPtr = ref.refType(ref.types.void);
var user32 = ffi.Library('user32.dll', {
GetCaretPos:['bool',[voidPtr]]
});
var pbuf = new Buffer(2);
caretpos = user32.GetCaretPos(pbuf);
var cpos =(new Uint8Array(pbuf));
console.log(">",cpos ); //Doesn't work **> Uint8Array [ 0, 0, 0, 0 ]**
As the article heading states "GetCursorPos in Node FFI" and return pointer x,y
The code below works for me, its a hack to get the x,y pointer.
var ffi = require('ffi');
var repbuffer = new Buffer(16); // holder for windows structures
var user32 = ffi.Library('user32.dll', {
'GetCursorPos':['bool',['pointer']]
});
//Show mouse cords at console every sec
setInterval( function() { getmousepos();}, 1000);
function getmousepos(){
var p = user32.GetCursorPos(repbuffer);
var x= repbuffer[0]+ (repbuffer[1]*256);
var y= repbuffer[4]+(repbuffer[5]*256);
console.log(x + " " + y);
}
What worked for me:
var PointStruct = Struct({
x: ffi.types.long,
y: ffi.types.long,
});
var user32 = ffi.Library("user32", {
GetCursorPos: ["bool", [ref.refType(PointStruct)]],
SetCursorPos: ["long", ["long", "long"]],
});
export function GetMousePos() {
let mousePosBuffer = ref.alloc(PointStruct);
let success = user32.GetCursorPos(mousePosBuffer);
let mousePos = mousePosBuffer["deref"]() as {x: number, y: number};
return new Vector2i(mousePos.x, mousePos.y);
}
export function SetMousePos(x: number, y: number) {
user32.SetCursorPos(x, y);
}

Rotate and scale within fabricjs bounding box

I have a project that I'm working on, and am trying to get a Fabric.JS to allow me to rotate & scale items, but only to the max scale of a bounding box. I tried quite a few combinations on the object:scaling event, to no avail. I have left a portion of the scaling event commented out, but though all my tries (determining movingBox width and such), i was unable to constrain the proportions of the square to the box.
Notice, before transforming the box stays within the outer bounds... exactly the functionality I desire. I just need the same functionality during the rotate & resize methods... which I assume we'll need to tap into the rotating & scale methods. Any help in modifying/adding to this to make these things possible, would be incredibly helpful.
Thanks,
$(function () {
var canvas = new fabric.Canvas("c");
canvas.setHeight(600);
canvas.setWidth(400);
var boundingBox = new fabric.Rect({
fill: "rgba(255, 255, 255, 0.0)",
width: 98,
height: 200,
hasBorders: false,
hasControls: false,
lockMovementX: true,
lockMovementY: true,
evented: false,
stroke: "black"
});
var movingBox = new fabric.Rect({
width: 50,
height: 50,
hasBorders: false,
hasControls: true,
lockRotation: false
});
canvas.on("object:moving", function () {
var top = movingBox.top;
var bottom = top + movingBox.height;
var left = movingBox.left;
var right = left + movingBox.width;
var topBound = boundingBox.top;
var bottomBound = topBound + boundingBox.height;
var leftBound = boundingBox.left;
var rightBound = leftBound + boundingBox.width;
movingBox.setLeft(Math.min(Math.max(left, leftBound), rightBound - movingBox.width));
movingBox.setTop(Math.min(Math.max(top, topBound), bottomBound - movingBox.height));
});
//canvas.on("object:scaling", function () {
// var top = movingBox.top;
// var bottom = top + movingBox.height;
// var left = movingBox.left;
// var right = movingBox.width;
//
// var topBound = boundingBox.top;
// var bottomBound = topBound + boundingBox.height;
// var leftBound = boundingBox.left;
// var rightBound = leftBound + boundingBox.width;
//
// // movingBox.setWidth // need alg here
// //movingBox.setHeight // need alg here
//});
canvas.add(boundingBox);
canvas.add(movingBox);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.5.0/fabric.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div style="position: absolute; top: 149px; left: 151px;">
<canvas id="c"></canvas>
</div>
For the scale you can use the fiddle below to set the width and height when you are scaling and then you can limit the figure width and height
var canvas = new fabric.Canvas("c1");
reinit()
canvas.on({
'object:scaling': function(e) {
var obj = e.target,
w = obj.width * obj.scaleX,
h = obj.height * obj.scaleY,
s = obj.strokeWidth;
console.log(obj.width, obj.scaleX, h,w,s)
obj._objects[0].set({
'height' : obj.height,
'width' : obj.width,
'scaleX' : 1,
'scaleY' : 1,
h: h,
w: w
//top: 1,
//left: 1,
});
/*e.target.set({
'height' : h,
'width' : w,
'scaleX' : 1,
'scaleY' : 1
});*/
}
});
canvas.on({
'object:modified': function(e) {
console.log(e)
//e.target.set({scaleX:1, scaleY:1})
group = e.target
rect = e.target._objects[0]
rect.set({height:rect.h, width: rect.w})
console.log('r',rect.width, group.width)
text = group._objects[1]
canvas.remove(group)
canvas.add(new fabric.Group([rect,text], {
top: group.top,
left: group.left
}))
}
});
function reinit(){
var el = new fabric.Rect({
originX: "left",
originY: "top",
stroke: "rgb(0,0,0)",
strokeWidth: 1,
fill: 'transparent',
opacity: 1,
width: 200,
height: 200,
cornerSize: 6
});
var text = new fabric.IText('test', { fontSize: 16});
var group = new fabric.Group([ el, text ], {
width: 200,
height: 200,
left: 5,
top: 5,
});
canvas.add(group);
canvas.renderAll();
}
http://jsfiddle.net/davidtorroija/qs0ywh8k/

Flot tooltip hovering

I have an issue with the tooltip in flot. I'm passing a timestamp data and it will reflect as a number, e.g 1113340002003. What I want to do is that when I hover over a data point, it will reflect as the date: 01/04/2012 and not that number. Any help would be great! Stuck here for a few hours....
This is what I'm passing to plot:
var time = (new Date(dates[i]));
graph.push([time, demand[i]]);
This is the section that I used to plot my graph:
var options = {
series: {
lines: { show: true },
points: { show: true }
},
grid: { hoverable: true, clickable: true },
yaxis: { min: 0, max: 20000 },
xaxis: {
mode: "time", timeformat: "%d/%m/%y"}
var plot = $.plot($("#placeholder"),
[ { data: graph, label: "price" } ],
options);
function showTooltip(x, y, contents) {
$('<div id="tooltip">' + contents + '</div>').css( {
position: 'absolute',
display: 'none',
top: y + 5,
left: x + 5,
border: '1px solid #fdd',
padding: '2px',
'background-color': '#fee',
opacity: 0.80
}).appendTo("body").fadeIn(200);
}
var previousPoint = null;
$("#placeholder").bind("plothover", function (event, pos, item) {
$("#x").text(pos.x.toFixed(2));
$("#y").text(pos.y.toFixed(2));
if($("#enableTooltip:checked").length > 0) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
$("#tooltip").remove();
var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(2);
var td = x.split("/");
Just convert it to a javascript data object and then build the string yourself.
var d = new Date(item.datapoint[0]);
var someDay = d.getDate();
var someMonth = d.getMonth() + 1; //months are zero based
var someYear = d.getFullYear();
var stringDate = someMonth + "/" + someDay + "/" + someYear;
var x = stringDate;
var y = item.datapoint[1].toFixed(2);

Resources