This PR includes changes to the dia.Cell.toJSON(), now accepting two new options.
opt.ignoreDefaults (default['attrs']) - accepts an array of attribute names to be compared to the defaults, additionally setting this option to false will result in returning all of the attributes without comparing them, while setting it to true results in a comparison of all the attributes with defaults
opt.ignoreEmptyAttributes (defaultfalse) - determines if the result should include empty attributes
These two options are also applicable to dia.Graph.toJSON() method.
This PR also includes a new util.objectDifference function used to determine the difference between two provided objects.
Return a copy of the cell's attributes for JSON serialization. This can be used for persistance or serialization. Note that this method doesn't return a JSON string but rather an object that can be then serialized to JSON with JSON.stringify().
By default, opt.ignoreDefaults is set to ['attrs']. This setting ensures that only non-default attributes in the attrs object are returned, as it compares the attrs object to its defaults. To include all attributes of dia.Cell without filtering out defaults, set opt.ignoreDefaults to false. Alternatively, setting opt.ignoreDefaults to true will compare all attributes to their defaults, returning only those that differ. You can also provide an array of strings for opt.ignoreDefaults, specifying a list of attributes to compare against their defaults.
Additionally, opt.ignoreEmptyAttributes defaults to false, which may include empty objects in the JSON output. To exclude empty objects, set opt.ignoreEmptyAttributes to true.
This method accepts an optional opt object, the opt.cellAttributes accepts same options as the dia.Cell.toJSON() method, which will impact the result of the toJSON() method.
Description
This PR includes changes to the
dia.Cell.toJSON()
, now accepting two new options.opt.ignoreDefaults
(default['attrs']
) - accepts an array of attribute names to be compared to the defaults, additionally setting this option tofalse
will result in returning all of the attributes without comparing them, while setting it totrue
results in a comparison of all the attributes with defaultsopt.ignoreEmptyAttributes
(defaultfalse
) - determines if the result should include empty attributesThese two options are also applicable to
dia.Graph.toJSON()
method.This PR also includes a new
util.objectDifference
function used to determine the difference between two provided objects.Documentation
https://docs.jointjs.com/api/dia/Cell/#tojson
toJSON()
Return a copy of the cell's attributes for JSON serialization. This can be used for persistance or serialization. Note that this method doesn't return a JSON string but rather an object that can be then serialized to JSON with
JSON.stringify()
.By default,
opt.ignoreDefaults
is set to['attrs']
. This setting ensures that only non-default attributes in the attrs object are returned, as it compares the attrs object to its defaults. To include all attributes ofdia.Cell
without filtering out defaults, setopt.ignoreDefaults
tofalse
. Alternatively, settingopt.ignoreDefaults
totrue
will compare all attributes to their defaults, returning only those that differ. You can also provide an array of strings foropt.ignoreDefaults
, specifying a list of attributes to compare against their defaults.Additionally,
opt.ignoreEmptyAttributes
defaults tofalse
, which may include empty objects in the JSON output. To exclude empty objects, setopt.ignoreEmptyAttributes
totrue
.https://docs.jointjs.com/api/dia/Graph/#tojson
toJSON()
This method accepts an optional
opt
object, theopt.cellAttributes
accepts same options as the dia.Cell.toJSON() method, which will impact the result of thetoJSON()
method.https://docs.jointjs.com/api/util/
objectDifference()
Return an object that represents the difference between
object
andbase
.