Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 3832 Add toDatalessObject to Group class since it may contains pathGroups. #3863

Merged
merged 2 commits into from
Apr 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/shapes/group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,24 @@
});
},

/**
* Returns object representation of an instance, in dataless mode.
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
* @return {Object} object representation of an instance
*/
toDatalessObject: function(propertiesToInclude) {
var objsToObject = this.getObjects().map(function(obj) {
var originalDefaults = obj.includeDefaultValues;
obj.includeDefaultValues = obj.group.includeDefaultValues;
var _obj = obj.toDatalessObject(propertiesToInclude);
obj.includeDefaultValues = originalDefaults;
return _obj;
});
return extend(this.callSuper('toDatalessObject', propertiesToInclude), {
objects: objsToObject
});
},

/**
* Renders instance on a given context
* @param {CanvasRenderingContext2D} ctx context to render instance on
Expand Down
6 changes: 2 additions & 4 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1296,11 +1296,9 @@
/**
* Renders controls and borders for the object
* @param {CanvasRenderingContext2D} ctx Context to render on
* @param {Boolean} [noTransform] When true, context is not transformed
*/
_renderControls: function(ctx, noTransform) {
if (!this.active || noTransform
|| (this.group && this.group !== this.canvas.getActiveGroup())) {
_renderControls: function(ctx) {
if (!this.active || (this.group && this.group !== this.canvas.getActiveGroup())) {
return;
}

Expand Down
10 changes: 10 additions & 0 deletions test/unit/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,16 @@
equal(isTransparent(ctx, 11, 11, 0), false, '11,11 is opaque');
equal(isTransparent(ctx, 12, 12, 0), true, '12,12 is transparent');
});

test('group toDatalessObject', function() {
var rect1 = new fabric.Rect({ top: 1, left: 1, width: 2, height: 2, strokeWidth: 0, fill: 'red', opacity: 1, objectCaching: false}),
rect2 = new fabric.Rect({ top: 5, left: 5, width: 2, height: 2, strokeWidth: 0, fill: 'red', opacity: 1, objectCaching: false}),
pathGroup = new fabric.PathGroup([rect1, rect2], { sourcePath: 'sourcePath'}),
group = new fabric.Group([pathGroup]),
dataless = group.toDatalessObject();

equal(dataless.objects[0].paths, 'sourcePath', 'the paths have been changed with the sourcePath');
});
// asyncTest('cloning group with image', function() {
// var rect = new fabric.Rect({ top: 100, left: 100, width: 30, height: 10 }),
// img = new fabric.Image(_createImageElement()),
Expand Down