mirror of
https://github.com/konvajs/konva.git
synced 2026-01-23 05:14:58 +08:00
Fix correct rendering of Konva.Label when heigh of text is changed
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
* Fix correct rendering of `Konva.Label` when heigh of text is changed
|
||||||
|
|
||||||
## 7.2.0
|
## 7.2.0
|
||||||
|
|
||||||
* New property `fillAfterStrokeEnabled` for `Konva.Shape`. See API docs for more information.
|
* New property `fillAfterStrokeEnabled` for `Konva.Shape`. See API docs for more information.
|
||||||
|
|||||||
11
konva.js
11
konva.js
@@ -8,7 +8,7 @@
|
|||||||
* Konva JavaScript Framework v7.2.0
|
* Konva JavaScript Framework v7.2.0
|
||||||
* http://konvajs.org/
|
* http://konvajs.org/
|
||||||
* Licensed under the MIT
|
* Licensed under the MIT
|
||||||
* Date: Mon Nov 23 2020
|
* Date: Wed Nov 25 2020
|
||||||
*
|
*
|
||||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
||||||
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
||||||
@@ -11272,7 +11272,8 @@
|
|||||||
'padding',
|
'padding',
|
||||||
'lineHeight',
|
'lineHeight',
|
||||||
'text',
|
'text',
|
||||||
'width'
|
'width',
|
||||||
|
'height',
|
||||||
], CHANGE_KONVA = 'Change.konva', NONE = 'none', UP = 'up', RIGHT = 'right', DOWN = 'down', LEFT = 'left',
|
], CHANGE_KONVA = 'Change.konva', NONE = 'none', UP = 'up', RIGHT = 'right', DOWN = 'down', LEFT = 'left',
|
||||||
// cached variables
|
// cached variables
|
||||||
attrChangeListLen = ATTR_CHANGE_LIST.length;
|
attrChangeListLen = ATTR_CHANGE_LIST.length;
|
||||||
@@ -11411,11 +11412,11 @@
|
|||||||
x: -1 * x,
|
x: -1 * x,
|
||||||
y: -1 * y,
|
y: -1 * y,
|
||||||
width: width,
|
width: width,
|
||||||
height: height
|
height: height,
|
||||||
});
|
});
|
||||||
text.setAttrs({
|
text.setAttrs({
|
||||||
x: -1 * x,
|
x: -1 * x,
|
||||||
y: -1 * y
|
y: -1 * y,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -11510,7 +11511,7 @@
|
|||||||
x: x,
|
x: x,
|
||||||
y: y,
|
y: y,
|
||||||
width: width,
|
width: width,
|
||||||
height: height
|
height: height,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return Tag;
|
return Tag;
|
||||||
|
|||||||
4
konva.min.js
vendored
4
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -3,7 +3,10 @@ import { Factory } from '../Factory';
|
|||||||
import { Shape, ShapeConfig } from '../Shape';
|
import { Shape, ShapeConfig } from '../Shape';
|
||||||
import { Group } from '../Group';
|
import { Group } from '../Group';
|
||||||
import { ContainerConfig } from '../Container';
|
import { ContainerConfig } from '../Container';
|
||||||
import {getNumberOrArrayOfNumbersValidator, getNumberValidator} from '../Validators';
|
import {
|
||||||
|
getNumberOrArrayOfNumbersValidator,
|
||||||
|
getNumberValidator,
|
||||||
|
} from '../Validators';
|
||||||
import { _registerNode } from '../Global';
|
import { _registerNode } from '../Global';
|
||||||
|
|
||||||
import { GetSet } from '../types';
|
import { GetSet } from '../types';
|
||||||
@@ -18,7 +21,8 @@ var ATTR_CHANGE_LIST = [
|
|||||||
'padding',
|
'padding',
|
||||||
'lineHeight',
|
'lineHeight',
|
||||||
'text',
|
'text',
|
||||||
'width'
|
'width',
|
||||||
|
'height',
|
||||||
],
|
],
|
||||||
CHANGE_KONVA = 'Change.konva',
|
CHANGE_KONVA = 'Change.konva',
|
||||||
NONE = 'none',
|
NONE = 'none',
|
||||||
@@ -70,7 +74,7 @@ var ATTR_CHANGE_LIST = [
|
|||||||
export class Label extends Group {
|
export class Label extends Group {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
super(config);
|
super(config);
|
||||||
this.on('add.konva', function(evt) {
|
this.on('add.konva', function (evt) {
|
||||||
this._addListeners(evt.child);
|
this._addListeners(evt.child);
|
||||||
this._sync();
|
this._sync();
|
||||||
});
|
});
|
||||||
@@ -99,7 +103,7 @@ export class Label extends Group {
|
|||||||
_addListeners(text) {
|
_addListeners(text) {
|
||||||
var that = this,
|
var that = this,
|
||||||
n;
|
n;
|
||||||
var func = function() {
|
var func = function () {
|
||||||
that._sync();
|
that._sync();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -157,12 +161,12 @@ export class Label extends Group {
|
|||||||
x: -1 * x,
|
x: -1 * x,
|
||||||
y: -1 * y,
|
y: -1 * y,
|
||||||
width: width,
|
width: width,
|
||||||
height: height
|
height: height,
|
||||||
});
|
});
|
||||||
|
|
||||||
text.setAttrs({
|
text.setAttrs({
|
||||||
x: -1 * x,
|
x: -1 * x,
|
||||||
y: -1 * y
|
y: -1 * y,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,11 +199,11 @@ export interface TagConfig extends ShapeConfig {
|
|||||||
export class Tag extends Shape<TagConfig> {
|
export class Tag extends Shape<TagConfig> {
|
||||||
_sceneFunc(context) {
|
_sceneFunc(context) {
|
||||||
var width = this.width(),
|
var width = this.width(),
|
||||||
height = this.height(),
|
height = this.height(),
|
||||||
pointerDirection = this.pointerDirection(),
|
pointerDirection = this.pointerDirection(),
|
||||||
pointerWidth = this.pointerWidth(),
|
pointerWidth = this.pointerWidth(),
|
||||||
pointerHeight = this.pointerHeight(),
|
pointerHeight = this.pointerHeight(),
|
||||||
cornerRadius = this.cornerRadius();
|
cornerRadius = this.cornerRadius();
|
||||||
|
|
||||||
let topLeft = 0;
|
let topLeft = 0;
|
||||||
let topRight = 0;
|
let topRight = 0;
|
||||||
@@ -208,9 +212,9 @@ export class Tag extends Shape<TagConfig> {
|
|||||||
|
|
||||||
if (typeof cornerRadius === 'number') {
|
if (typeof cornerRadius === 'number') {
|
||||||
topLeft = topRight = bottomLeft = bottomRight = Math.min(
|
topLeft = topRight = bottomLeft = bottomRight = Math.min(
|
||||||
cornerRadius,
|
cornerRadius,
|
||||||
width / 2,
|
width / 2,
|
||||||
height / 2
|
height / 2
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
||||||
@@ -230,12 +234,12 @@ export class Tag extends Shape<TagConfig> {
|
|||||||
|
|
||||||
context.lineTo(width - topRight, 0);
|
context.lineTo(width - topRight, 0);
|
||||||
context.arc(
|
context.arc(
|
||||||
width - topRight,
|
width - topRight,
|
||||||
topRight,
|
topRight,
|
||||||
topRight,
|
topRight,
|
||||||
(Math.PI * 3) / 2,
|
(Math.PI * 3) / 2,
|
||||||
0,
|
0,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
if (pointerDirection === RIGHT) {
|
if (pointerDirection === RIGHT) {
|
||||||
@@ -246,12 +250,12 @@ export class Tag extends Shape<TagConfig> {
|
|||||||
|
|
||||||
context.lineTo(width, height - bottomRight);
|
context.lineTo(width, height - bottomRight);
|
||||||
context.arc(
|
context.arc(
|
||||||
width - bottomRight,
|
width - bottomRight,
|
||||||
height - bottomRight,
|
height - bottomRight,
|
||||||
bottomRight,
|
bottomRight,
|
||||||
0,
|
0,
|
||||||
Math.PI / 2,
|
Math.PI / 2,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
if (pointerDirection === DOWN) {
|
if (pointerDirection === DOWN) {
|
||||||
@@ -262,12 +266,12 @@ export class Tag extends Shape<TagConfig> {
|
|||||||
|
|
||||||
context.lineTo(bottomLeft, height);
|
context.lineTo(bottomLeft, height);
|
||||||
context.arc(
|
context.arc(
|
||||||
bottomLeft,
|
bottomLeft,
|
||||||
height - bottomLeft,
|
height - bottomLeft,
|
||||||
bottomLeft,
|
bottomLeft,
|
||||||
Math.PI / 2,
|
Math.PI / 2,
|
||||||
Math.PI,
|
Math.PI,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
if (pointerDirection === LEFT) {
|
if (pointerDirection === LEFT) {
|
||||||
@@ -277,13 +281,7 @@ export class Tag extends Shape<TagConfig> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
context.lineTo(0, topLeft);
|
context.lineTo(0, topLeft);
|
||||||
context.arc(
|
context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
|
||||||
topLeft,
|
|
||||||
topLeft,
|
|
||||||
topLeft,
|
|
||||||
Math.PI,
|
|
||||||
(Math.PI * 3) / 2,
|
|
||||||
false);
|
|
||||||
|
|
||||||
context.closePath();
|
context.closePath();
|
||||||
context.fillStrokeShape(this);
|
context.fillStrokeShape(this);
|
||||||
@@ -313,7 +311,7 @@ export class Tag extends Shape<TagConfig> {
|
|||||||
x: x,
|
x: x,
|
||||||
y: y,
|
y: y,
|
||||||
width: width,
|
width: width,
|
||||||
height: height
|
height: height,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,6 +372,11 @@ Factory.addGetterSetter(Tag, 'pointerHeight', 0, getNumberValidator());
|
|||||||
* tag.cornerRadius([0, 10, 20, 30]);
|
* tag.cornerRadius([0, 10, 20, 30]);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Factory.addGetterSetter(Tag, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
Factory.addGetterSetter(
|
||||||
|
Tag,
|
||||||
|
'cornerRadius',
|
||||||
|
0,
|
||||||
|
getNumberOrArrayOfNumbersValidator(4)
|
||||||
|
);
|
||||||
|
|
||||||
Collection.mapMethods(Tag);
|
Collection.mapMethods(Tag);
|
||||||
|
|||||||
@@ -277,6 +277,9 @@ suite('Label', function () {
|
|||||||
|
|
||||||
layer.draw();
|
layer.draw();
|
||||||
assert.equal(tag.width(), text.width());
|
assert.equal(tag.width(), text.width());
|
||||||
|
|
||||||
|
text.height(200);
|
||||||
|
assert.equal(tag.height(), text.height());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('tag cornerRadius', function () {
|
test('tag cornerRadius', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user