Browse Source

Merge branch 'develop' of https://github.com/almende/vis into rtl-dir

codeClimate
Yotam Berkowitz 8 years ago
parent
commit
afdefcc006
8 changed files with 59 additions and 23 deletions
  1. +6
    -0
      lib/network/modules/Canvas.js
  2. +14
    -2
      lib/network/modules/Clustering.js
  3. +22
    -5
      lib/network/modules/components/NavigationHandler.js
  4. +1
    -1
      lib/timeline/Core.js
  5. +9
    -11
      lib/timeline/Timeline.js
  6. +4
    -2
      lib/timeline/component/ItemSet.js
  7. +1
    -1
      lib/timeline/component/item/Item.js
  8. +2
    -1
      test/DataView.test.js

+ 6
- 0
lib/network/modules/Canvas.js View File

@ -18,6 +18,7 @@ class Canvas {
this.resizeFunction = this._onResize.bind(this); this.resizeFunction = this._onResize.bind(this);
this.cameraState = {}; this.cameraState = {};
this.initialized = false; this.initialized = false;
this.canvasViewCenter = {};
this.options = {}; this.options = {};
this.defaultOptions = { this.defaultOptions = {
@ -284,6 +285,11 @@ class Canvas {
this.options.width = width; this.options.width = width;
this.options.height = height; this.options.height = height;
this.canvasViewCenter = {
x: 0.5 * this.frame.clientWidth,
y: 0.5 * this.frame.clientHeight
};
emitEvent = true; emitEvent = true;
} }
else { else {

+ 14
- 2
lib/network/modules/Clustering.js View File

@ -235,7 +235,19 @@ class ClusterEngine {
} }
} }
} }
var childNodeIDs = Object.keys(childNodesObj).map(function(childNode){
return childNodesObj[childNode].id;
})
for (childNode in childNodesObj) {
var childNode = childNodesObj[childNode];
for (var y=0; y < childNode.edges.length; y++){
var childEdge = childNode.edges[y];
if (childNodeIDs.indexOf(this._getConnectedId(childEdge,childNode.id)) > -1){
childEdgesObj[childEdge.id] = childEdge;
}
}
}
this._cluster(childNodesObj, childEdgesObj, options, refreshData); this._cluster(childNodesObj, childEdgesObj, options, refreshData);
} }
@ -723,7 +735,7 @@ class ClusterEngine {
let allEdgeIds = this.getClusteredEdges(startEdgeId); let allEdgeIds = this.getClusteredEdges(startEdgeId);
for (let i = 0; i < allEdgeIds.length; i++) { for (let i = 0; i < allEdgeIds.length; i++) {
var edge = this.body.edges[allEdgeIds[i]]; var edge = this.body.edges[allEdgeIds[i]];
edge.setOptions(newOptions);
edge.setOptions(newOptions);
} }
this.body.emitter.emit('_dataChanged'); this.body.emitter.emit('_dataChanged');
} }

+ 22
- 5
lib/network/modules/components/NavigationHandler.js View File

@ -150,12 +150,29 @@ class NavigationHandler {
_moveDown() {this.body.view.translation.y -= this.options.keyboard.speed.y;} _moveDown() {this.body.view.translation.y -= this.options.keyboard.speed.y;}
_moveLeft() {this.body.view.translation.x += this.options.keyboard.speed.x;} _moveLeft() {this.body.view.translation.x += this.options.keyboard.speed.x;}
_moveRight(){this.body.view.translation.x -= this.options.keyboard.speed.x;} _moveRight(){this.body.view.translation.x -= this.options.keyboard.speed.x;}
_zoomIn() {
this.body.view.scale *= 1+this.options.keyboard.speed.zoom;
this.body.emitter.emit('zoom', {direction: '+', scale: this.body.view.scale});}
_zoomIn() {
var scaleOld = this.body.view.scale;
var scale = this.body.view.scale * (1 + this.options.keyboard.speed.zoom);
var translation = this.body.view.translation;
var scaleFrac = scale / scaleOld;
var tx = (1 - scaleFrac) * this.canvas.canvasViewCenter.x + translation.x * scaleFrac;
var ty = (1 - scaleFrac) * this.canvas.canvasViewCenter.y + translation.y * scaleFrac;
this.body.view.scale = scale;
this.body.view.translation = { x: tx, y: ty };
this.body.emitter.emit('zoom', { direction: '+', scale: this.body.view.scale });
}
_zoomOut() { _zoomOut() {
this.body.view.scale /= 1+this.options.keyboard.speed.zoom;
this.body.emitter.emit('zoom', {direction: '-', scale: this.body.view.scale});
var scaleOld = this.body.view.scale;
var scale = this.body.view.scale / (1 + this.options.keyboard.speed.zoom);
var translation = this.body.view.translation;
var scaleFrac = scale / scaleOld;
var tx = (1 - scaleFrac) * this.canvas.canvasViewCenter.x + translation.x * scaleFrac;
var ty = (1 - scaleFrac) * this.canvas.canvasViewCenter.y + translation.y * scaleFrac;
this.body.view.scale = scale;
this.body.view.translation = { x: tx, y: ty };
this.body.emitter.emit('zoom', { direction: '-', scale: this.body.view.scale });
} }

+ 1
- 1
lib/timeline/Core.js View File

@ -1146,4 +1146,4 @@ Core.prototype._createConfigurator = function () {
throw new Error('Cannot invoke abstract method _createConfigurator'); throw new Error('Cannot invoke abstract method _createConfigurator');
}; };
module.exports = Core;
module.exports = Core;

+ 9
- 11
lib/timeline/Timeline.js View File

@ -28,8 +28,8 @@ import Validator from '../shared/Validator';
* @constructor * @constructor
* @extends Core * @extends Core
*/ */
function Timeline (container, items, groups, options) { function Timeline (container, items, groups, options) {
if (!(this instanceof Timeline)) { if (!(this instanceof Timeline)) {
throw new SyntaxError('Constructor must be called with the new operator'); throw new SyntaxError('Constructor must be called with the new operator');
} }
@ -45,22 +45,21 @@ function Timeline (container, items, groups, options) {
this.defaultOptions = { this.defaultOptions = {
start: null, start: null,
end: null, end: null,
autoResize: true, autoResize: true,
orientation: { orientation: {
axis: 'bottom', // axis orientation: 'bottom', 'top', or 'both' axis: 'bottom', // axis orientation: 'bottom', 'top', or 'both'
item: 'bottom' // not relevant item: 'bottom' // not relevant
}, },
moment: moment, moment: moment,
width: null, width: null,
height: null, height: null,
maxHeight: null, maxHeight: null,
minHeight: null minHeight: null
}; };
this.options = util.deepExtend({}, this.defaultOptions); this.options = util.deepExtend({}, this.defaultOptions);
if (options) {
this.options.rtl = options.rtl
}
// Create the DOM, props, and emitter // Create the DOM, props, and emitter
this._create(container); this._create(container);
@ -104,11 +103,6 @@ function Timeline (container, items, groups, options) {
// current time bar // current time bar
this.currentTime = new CurrentTime(this.body); this.currentTime = new CurrentTime(this.body);
this.components.push(this.currentTime); this.components.push(this.currentTime);
// apply options
if (options) {
this.setOptions(options);
}
// item set // item set
this.itemSet = new ItemSet(this.body, this.options); this.itemSet = new ItemSet(this.body, this.options);
@ -149,6 +143,11 @@ function Timeline (container, items, groups, options) {
} }
}); });
// apply options
if (options) {
this.setOptions(options);
}
// IMPORTANT: THIS HAPPENS BEFORE SET ITEMS! // IMPORTANT: THIS HAPPENS BEFORE SET ITEMS!
if (groups) { if (groups) {
this.setGroups(groups); this.setGroups(groups);
@ -194,7 +193,6 @@ Timeline.prototype.setOptions = function (options) {
if (errorFound === true) { if (errorFound === true) {
console.log('%cErrors have been found in the supplied options object.', printStyle); console.log('%cErrors have been found in the supplied options object.', printStyle);
} }
Core.prototype.setOptions.call(this, options); Core.prototype.setOptions.call(this, options);
if ('type' in options) { if ('type' in options) {

+ 4
- 2
lib/timeline/component/ItemSet.js View File

@ -95,7 +95,9 @@ function ItemSet(body, options) {
// options is shared by this ItemSet and all its items // options is shared by this ItemSet and all its items
this.options = util.extend({}, this.defaultOptions); this.options = util.extend({}, this.defaultOptions);
this.options.rtl = options.rtl;
if (options) {
this.options.rtl = options.rtl; // required to determine from the initial creation if rtl
}
// options for getting items from the DataSet with the correct type // options for getting items from the DataSet with the correct type
this.itemOptions = { this.itemOptions = {
@ -318,7 +320,7 @@ ItemSet.prototype.setOptions = function(options) {
// copy all options that we know // copy all options that we know
var fields = ['type', 'rtl', 'align', 'order', 'stack', 'selectable', 'multiselect', 'itemsAlwaysDraggable', 'multiselectPerGroup', 'groupOrder', 'dataAttributes', 'template', 'groupTemplate', 'hide', 'snap', 'groupOrderSwap']; var fields = ['type', 'rtl', 'align', 'order', 'stack', 'selectable', 'multiselect', 'itemsAlwaysDraggable', 'multiselectPerGroup', 'groupOrder', 'dataAttributes', 'template', 'groupTemplate', 'hide', 'snap', 'groupOrderSwap'];
util.selectiveExtend(fields, this.options, options); util.selectiveExtend(fields, this.options, options);
if ('orientation' in options) { if ('orientation' in options) {
if (typeof options.orientation === 'string') { if (typeof options.orientation === 'string') {
this.options.orientation.item = options.orientation === 'top' ? 'top' : 'bottom'; this.options.orientation.item = options.orientation === 'top' ? 'top' : 'bottom';

+ 1
- 1
lib/timeline/component/item/Item.js View File

@ -197,7 +197,7 @@ Item.prototype._updateContents = function (element) {
content = this.data.content; content = this.data.content;
} }
if (content instanceof Object) {
if ((content instanceof Object) && !(content instanceof Element)) {
templateFunction(itemData, element) templateFunction(itemData, element)
} else { } else {
var changed = this._contentToString(this.content) !== this._contentToString(content); var changed = this._contentToString(this.content) !== this._contentToString(content);

+ 2
- 1
test/DataView.test.js View File

@ -200,7 +200,8 @@ describe('DataView', function () {
}] }]
]); ]);
assert.deepEqual(viewUpdates, [ assert.deepEqual(viewUpdates, [
['update', {items: [2], data: [{id: 2, title: 'Item 2 (changed)'}]}]
['update', {items: [2], data: [{id: 2, title: 'Item 2 (changed)'}],
oldData: [{"group": 2, "id": 2, "title": "Item 2"}]}]
]); ]);
}); });

Loading…
Cancel
Save