mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Add labelLocation options to node
This commit is contained in:
parent
b11c8c5b15
commit
936576e7d9
@ -21,7 +21,7 @@ module.exports = function(RED) {
|
|||||||
const defaultStroke = n.stroke || "#ffC000";
|
const defaultStroke = n.stroke || "#ffC000";
|
||||||
const defaultLineWidth = parseInt(n.lineWidth) || 5;
|
const defaultLineWidth = parseInt(n.lineWidth) || 5;
|
||||||
const defaultFontSize = n.fontSize || 24;
|
const defaultFontSize = n.fontSize || 24;
|
||||||
const defaultFontColor = n.fontColor || "#ffC000"
|
const defaultFontColor = n.fontColor || "#ffC000";
|
||||||
loadFont();
|
loadFont();
|
||||||
|
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
@ -83,7 +83,46 @@ module.exports = function(RED) {
|
|||||||
ctx.fillStyle = annotation.fontColor || defaultFontColor;
|
ctx.fillStyle = annotation.fontColor || defaultFontColor;
|
||||||
ctx.textBaseline = "top";
|
ctx.textBaseline = "top";
|
||||||
ctx.textAlign = "left";
|
ctx.textAlign = "left";
|
||||||
ctx.fillText(annotation.label, x+2,y)
|
//set offset value so txt is above or below image
|
||||||
|
if (annotation.labelLocation)
|
||||||
|
{
|
||||||
|
if (annotation.labelLocation === "top")
|
||||||
|
{
|
||||||
|
y = y - (20+((defaultLineWidth*0.5)+(Number(defaultFontSize))));
|
||||||
|
if (y < 0)
|
||||||
|
{
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (annotation.labelLocation === "bottom")
|
||||||
|
{
|
||||||
|
y = y + (10+h+(((defaultLineWidth*0.5)+(Number(defaultFontSize)))));
|
||||||
|
ctx.textBaseline = "bottom";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//if not user defined make best guess for top or bottom based on location
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//not enought room above imagebox, put label on the bottom
|
||||||
|
if (y < 0 + (20+((defaultLineWidth*0.5)+(Number(defaultFontSize)))))
|
||||||
|
{
|
||||||
|
y = y + (10+h+(((defaultLineWidth*0.5)+(Number(defaultFontSize)))));
|
||||||
|
ctx.textBaseline = "bottom";
|
||||||
|
}
|
||||||
|
//else put the label on the top
|
||||||
|
else
|
||||||
|
{
|
||||||
|
y = y - (20+((defaultLineWidth*0.5)+(Number(defaultFontSize))));
|
||||||
|
if (y < 0)
|
||||||
|
{
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ctx.fillText(annotation.label, x,y);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'circle':
|
case 'circle':
|
||||||
@ -114,6 +153,8 @@ module.exports = function(RED) {
|
|||||||
const bufferOutput = getWritableBuffer();
|
const bufferOutput = getWritableBuffer();
|
||||||
pureimage.encodeJPEGToStream(c,bufferOutput.stream,90).then(() => {
|
pureimage.encodeJPEGToStream(c,bufferOutput.stream,90).then(() => {
|
||||||
msg.payload = bufferOutput.getBuffer();
|
msg.payload = bufferOutput.getBuffer();
|
||||||
|
msg.defaultFontSize = defaultFontSize;
|
||||||
|
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
})
|
})
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user