mirror of
https://github.com/konvajs/konva.git
synced 2026-01-22 03:11:53 +08:00
some bugs fixes
This commit is contained in:
@@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
## Fixed
|
||||
|
||||
* Fixed `Konva.Text` justify drawing for a text with decoration
|
||||
* Added methods `data()`,`setData()` and `getData()` methods to `Konva.TextPath`
|
||||
|
||||
|
||||
## [2.1.3][2018-05-17]
|
||||
|
||||
100
konva.js
100
konva.js
@@ -2,7 +2,7 @@
|
||||
* Konva JavaScript Framework v2.1.3
|
||||
* http://konvajs.github.io/
|
||||
* Licensed under the MIT
|
||||
* Date: Thu May 24 2018
|
||||
* Date: Tue Jun 05 2018
|
||||
*
|
||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
||||
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
||||
@@ -218,7 +218,9 @@
|
||||
? global
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: typeof WorkerGlobalScope !== 'undefined' ? self : {};
|
||||
: typeof WorkerGlobalScope !== 'undefined'
|
||||
? self
|
||||
: {};
|
||||
|
||||
Konva.UA = Konva._parseUA((glob.navigator && glob.navigator.userAgent) || '');
|
||||
|
||||
@@ -6333,14 +6335,14 @@
|
||||
vsw = v * s * Math.sin(h * Math.PI / 180);
|
||||
// (result spot)(source spot)
|
||||
var rr = 0.299 * v + 0.701 * vsu + 0.167 * vsw,
|
||||
rg = 0.587 * v - 0.587 * vsu + 0.330 * vsw,
|
||||
rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw,
|
||||
rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw;
|
||||
var gr = 0.299 * v - 0.299 * vsu - 0.328 * vsw,
|
||||
gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw,
|
||||
gb = 0.114 * v - 0.114 * vsu + 0.293 * vsw;
|
||||
var br = 0.299 * v - 0.300 * vsu + 1.250 * vsw,
|
||||
bg = 0.587 * v - 0.586 * vsu - 1.050 * vsw,
|
||||
bb = 0.114 * v + 0.886 * vsu - 0.200 * vsw;
|
||||
var br = 0.299 * v - 0.3 * vsu + 1.25 * vsw,
|
||||
bg = 0.587 * v - 0.586 * vsu - 1.05 * vsw,
|
||||
bb = 0.114 * v + 0.886 * vsu - 0.2 * vsw;
|
||||
|
||||
var r, g, b, a;
|
||||
|
||||
@@ -7535,7 +7537,7 @@
|
||||
);
|
||||
})();
|
||||
|
||||
(function (Konva) {
|
||||
(function(Konva) {
|
||||
'use strict';
|
||||
/**
|
||||
* Contrast Filter.
|
||||
@@ -7548,7 +7550,7 @@
|
||||
* node.contrast(10);
|
||||
*/
|
||||
|
||||
Konva.Filters.Contrast = function (imageData) {
|
||||
Konva.Filters.Contrast = function(imageData) {
|
||||
var adjust = Math.pow((parseInt(this.contrast()) + 100) / 100, 2);
|
||||
|
||||
var data = imageData.data,
|
||||
@@ -7584,9 +7586,9 @@
|
||||
blue += 0.5;
|
||||
blue *= 255;
|
||||
|
||||
red = (red < 0 ? 0 : (red > 255 ? 255 : red));
|
||||
green = (green < 0 ? 0 : (green > 255 ? 255 : green));
|
||||
blue = (blue < 0 ? 0 : (blue > 255 ? 255 : blue));
|
||||
red = red < 0 ? 0 : red > 255 ? 255 : red;
|
||||
green = green < 0 ? 0 : green > 255 ? 255 : green;
|
||||
blue = blue < 0 ? 0 : blue > 255 ? 255 : blue;
|
||||
|
||||
data[i] = red;
|
||||
data[i + 1] = green;
|
||||
@@ -7603,7 +7605,13 @@
|
||||
* @param {Number} contrast value between -100 and 100
|
||||
* @returns {Number}
|
||||
*/
|
||||
Konva.Factory.addGetterSetter(Konva.Node, 'contrast', 0, null, Konva.Factory.afterSetFilter);
|
||||
Konva.Factory.addGetterSetter(
|
||||
Konva.Node,
|
||||
'contrast',
|
||||
0,
|
||||
null,
|
||||
Konva.Factory.afterSetFilter
|
||||
);
|
||||
})(Konva);
|
||||
|
||||
(function() {
|
||||
@@ -11583,7 +11591,8 @@
|
||||
return null;
|
||||
},
|
||||
drawScene: function(can) {
|
||||
var layer = this.getLayer(), canvas = can || (layer && layer.getCanvas());
|
||||
var layer = this.getLayer(),
|
||||
canvas = can || (layer && layer.getCanvas());
|
||||
|
||||
if (this.getClearBeforeDraw()) {
|
||||
canvas.getContext().clear();
|
||||
@@ -11786,7 +11795,9 @@
|
||||
* @return {Bool} true if layer is added to animation, otherwise false
|
||||
*/
|
||||
addLayer: function(layer) {
|
||||
var layers = this.layers, len = layers.length, n;
|
||||
var layers = this.layers,
|
||||
len = layers.length,
|
||||
n;
|
||||
|
||||
// don't add the layer if it already exists
|
||||
for (n = 0; n < len; n++) {
|
||||
@@ -11857,7 +11868,10 @@
|
||||
this._handleAnimation();
|
||||
};
|
||||
Konva.Animation._removeAnimation = function(anim) {
|
||||
var id = anim.id, animations = this.animations, len = animations.length, n;
|
||||
var id = anim.id,
|
||||
animations = this.animations,
|
||||
len = animations.length,
|
||||
n;
|
||||
|
||||
for (n = 0; n < len; n++) {
|
||||
if (animations[n].id === id) {
|
||||
@@ -11949,7 +11963,8 @@
|
||||
* @memberof Konva.Base.prototype
|
||||
*/
|
||||
Konva.BaseLayer.prototype.batchDraw = function() {
|
||||
var that = this, Anim = Konva.Animation;
|
||||
var that = this,
|
||||
Anim = Konva.Animation;
|
||||
|
||||
if (!this.batchAnim) {
|
||||
this.batchAnim = new Anim(function() {
|
||||
@@ -12523,9 +12538,11 @@
|
||||
s = p / (2 * Math.PI) * Math.asin(c / a);
|
||||
}
|
||||
return (
|
||||
-(a *
|
||||
-(
|
||||
a *
|
||||
Math.pow(2, 10 * (t -= 1)) *
|
||||
Math.sin((t * d - s) * (2 * Math.PI) / p)) + b
|
||||
Math.sin((t * d - s) * (2 * Math.PI) / p)
|
||||
) + b
|
||||
);
|
||||
},
|
||||
/**
|
||||
@@ -13211,7 +13228,8 @@
|
||||
(function(Konva) {
|
||||
'use strict';
|
||||
// the 0.0001 offset fixes a bug in Chrome 27
|
||||
var PIx2 = Math.PI * 2 - 0.0001, CIRCLE = 'Circle';
|
||||
var PIx2 = Math.PI * 2 - 0.0001,
|
||||
CIRCLE = 'Circle';
|
||||
|
||||
/**
|
||||
* Circle constructor
|
||||
@@ -13368,7 +13386,8 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
// the 0.0001 offset fixes a bug in Chrome 27
|
||||
var PIx2 = Math.PI * 2 - 0.0001, ELLIPSE = 'Ellipse';
|
||||
var PIx2 = Math.PI * 2 - 0.0001,
|
||||
ELLIPSE = 'Ellipse';
|
||||
|
||||
/**
|
||||
* Ellipse constructor
|
||||
@@ -13469,7 +13488,8 @@
|
||||
this.sceneFunc(this._sceneFunc);
|
||||
},
|
||||
_sceneFunc: function(context) {
|
||||
var rx = this.getRadiusX(), ry = this.getRadiusY();
|
||||
var rx = this.getRadiusX(),
|
||||
ry = this.getRadiusY();
|
||||
|
||||
context.beginPath();
|
||||
context.save();
|
||||
@@ -14058,7 +14078,8 @@
|
||||
this.sceneFunc(this._sceneFunc);
|
||||
},
|
||||
_sceneFunc: function(context) {
|
||||
var angle = Konva.getAngle(this.angle()), clockwise = this.clockwise();
|
||||
var angle = Konva.getAngle(this.angle()),
|
||||
clockwise = this.clockwise();
|
||||
|
||||
context.beginPath();
|
||||
context.arc(0, 0, this.getOuterRadius(), 0, angle, clockwise);
|
||||
@@ -14322,7 +14343,8 @@
|
||||
}
|
||||
},
|
||||
_hitFunc: function(context) {
|
||||
var width = this.getWidth(), height = this.getHeight();
|
||||
var width = this.getWidth(),
|
||||
height = this.getHeight();
|
||||
|
||||
context.beginPath();
|
||||
context.rect(0, 0, width, height);
|
||||
@@ -15768,7 +15790,8 @@
|
||||
|
||||
if (image) {
|
||||
if (offsets) {
|
||||
var offset = offsets[anim], ix2 = index * 2;
|
||||
var offset = offsets[anim],
|
||||
ix2 = index * 2;
|
||||
context.drawImage(
|
||||
image,
|
||||
x,
|
||||
@@ -17487,6 +17510,26 @@
|
||||
Konva.Util.extend(Konva.TextPath, Konva.Shape);
|
||||
|
||||
// add setters and getters
|
||||
Konva.Factory.addGetterSetter(Konva.TextPath, 'data');
|
||||
|
||||
/**
|
||||
* set SVG path data string. This method
|
||||
* also automatically parses the data string
|
||||
* into a data array. Currently supported SVG data:
|
||||
* M, m, L, l, H, h, V, v, Q, q, T, t, C, c, S, s, A, a, Z, z
|
||||
* @name setData
|
||||
* @method
|
||||
* @memberof Konva.TextPath.prototype
|
||||
* @param {String} SVG path command string
|
||||
*/
|
||||
|
||||
/**
|
||||
* get SVG path data string
|
||||
* @name getData
|
||||
* @method
|
||||
* @memberof Konva.TextPath.prototype
|
||||
*/
|
||||
|
||||
Konva.Factory.addGetterSetter(Konva.TextPath, 'fontFamily', 'Arial');
|
||||
|
||||
/**
|
||||
@@ -17729,7 +17772,11 @@
|
||||
this.sceneFunc(this._sceneFunc);
|
||||
},
|
||||
_sceneFunc: function(context) {
|
||||
var sides = this.attrs.sides, radius = this.attrs.radius, n, x, y;
|
||||
var sides = this.attrs.sides,
|
||||
radius = this.attrs.radius,
|
||||
n,
|
||||
x,
|
||||
y;
|
||||
|
||||
context.beginPath();
|
||||
context.moveTo(0, 0 - radius);
|
||||
@@ -18124,7 +18171,8 @@
|
||||
return this.find('Tag')[0];
|
||||
},
|
||||
_addListeners: function(text) {
|
||||
var that = this, n;
|
||||
var that = this,
|
||||
n;
|
||||
var func = function() {
|
||||
that._sync();
|
||||
};
|
||||
|
||||
4
konva.min.js
vendored
4
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -521,6 +521,26 @@
|
||||
Konva.Util.extend(Konva.TextPath, Konva.Shape);
|
||||
|
||||
// add setters and getters
|
||||
Konva.Factory.addGetterSetter(Konva.TextPath, 'data');
|
||||
|
||||
/**
|
||||
* set SVG path data string. This method
|
||||
* also automatically parses the data string
|
||||
* into a data array. Currently supported SVG data:
|
||||
* M, m, L, l, H, h, V, v, Q, q, T, t, C, c, S, s, A, a, Z, z
|
||||
* @name setData
|
||||
* @method
|
||||
* @memberof Konva.TextPath.prototype
|
||||
* @param {String} SVG path command string
|
||||
*/
|
||||
|
||||
/**
|
||||
* get SVG path data string
|
||||
* @name getData
|
||||
* @method
|
||||
* @memberof Konva.TextPath.prototype
|
||||
*/
|
||||
|
||||
Konva.Factory.addGetterSetter(Konva.TextPath, 'fontFamily', 'Arial');
|
||||
|
||||
/**
|
||||
|
||||
@@ -700,7 +700,7 @@ suite('Caching', function() {
|
||||
cloneAndCompareLayer(layer, 150);
|
||||
});
|
||||
|
||||
test.only('test group with circle + buffer canvas usage', function() {
|
||||
test('test group with circle + buffer canvas usage', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
|
||||
@@ -1060,6 +1060,38 @@ suite('Stage', function() {
|
||||
assert.equal(stage.toDataURL(), layer.toDataURL());
|
||||
});
|
||||
|
||||
test('toCanvas with large size', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
var radius = stage.height() / 2 + 10;
|
||||
var circle = new Konva.Circle({
|
||||
x: stage.height() / 2,
|
||||
y: stage.height() / 2,
|
||||
fill: 'black',
|
||||
radius: radius
|
||||
});
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
|
||||
var stageCanvas = stage.toCanvas({
|
||||
x: -10,
|
||||
y: -10,
|
||||
width: stage.height() + 20,
|
||||
height: stage.height() + 20
|
||||
});
|
||||
|
||||
var canvas = createCanvas();
|
||||
canvas.width = radius * 2;
|
||||
canvas.height = radius * 2;
|
||||
var context = canvas.getContext('2d');
|
||||
context.beginPath();
|
||||
context.arc(radius, radius, radius, 0, 2 * Math.PI);
|
||||
context.fillStyle = 'black';
|
||||
context.fill();
|
||||
compareCanvases(stageCanvas, canvas, 100);
|
||||
});
|
||||
|
||||
test('check hit graph with stage listening property', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
@@ -286,6 +286,29 @@ suite('Line', function() {
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: FIX IT!!!
|
||||
test.skip('getClientRect rotated', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
var line = new Konva.Line({
|
||||
x: 20,
|
||||
y: 20,
|
||||
rotation: 45,
|
||||
points: [0, 0, 50, 50],
|
||||
closed: true,
|
||||
stroke: '#0f0'
|
||||
});
|
||||
layer.add(line);
|
||||
stage.add(layer);
|
||||
|
||||
var rect = line.getClientRect();
|
||||
assert.equal(rect.x, 19, 'check x');
|
||||
assert.equal(rect.y, 19, 'check y');
|
||||
// assert.equal(rect.width, 2, 'check width');
|
||||
assert.equal(rect.height, 52, 'check height');
|
||||
});
|
||||
|
||||
test('line caching', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
@@ -74,6 +74,28 @@ suite('TextPath', function() {
|
||||
stage.add(layer);
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('Check getter and setter', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Konva.Layer();
|
||||
|
||||
var c = 'M 50 50 l 250 0';
|
||||
var path = new Konva.TextPath({
|
||||
text: 'some text',
|
||||
stroke: 'red',
|
||||
strokeWidth: 1
|
||||
});
|
||||
|
||||
layer.add(path);
|
||||
stage.add(layer);
|
||||
|
||||
assert.equal(path.getData(), undefined);
|
||||
path.data(c);
|
||||
assert.equal(path.getData(), c);
|
||||
|
||||
layer.draw();
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('Render Text Along Vertical Line', function() {
|
||||
var stage = addStage();
|
||||
|
||||
Reference in New Issue
Block a user