feat(library): add navigated viewer

This adds an additional viewer variant that contains canvas navigation
features.

Related to #169
This commit is contained in:
Nico Rehwaldt 2015-01-10 12:04:26 +01:00
parent 39d5fa2e9c
commit 5735a8bc3a
6 changed files with 90 additions and 18 deletions

View File

@ -1,7 +1,6 @@
'use strict'; 'use strict';
var Diagram = require('diagram-js'), var BpmnModdle = require('bpmn-moddle'),
BpmnModdle = require('bpmn-moddle'),
IdSupport = require('bpmn-moddle/lib/id-support'), IdSupport = require('bpmn-moddle/lib/id-support'),
Ids = require('ids'); Ids = require('ids');

23
lib/NavigatedViewer.js Normal file
View File

@ -0,0 +1,23 @@
var Viewer = require('./Viewer');
/**
* A viewer that includes mouse navigation facilities
*
* @param {Object} options
*/
function NavigatedViewer(options) {
Viewer.call(this, options);
}
NavigatedViewer.prototype = Object.create(Viewer.prototype);
module.exports = NavigatedViewer;
NavigatedViewer.prototype._navigationModules = [
require('diagram-js/lib/navigation/zoomscroll'),
require('diagram-js/lib/navigation/movecanvas')
];
NavigatedViewer.prototype._modules = [].concat(
NavigatedViewer.prototype._modules,
NavigatedViewer.prototype._navigationModules);

View File

@ -40,9 +40,12 @@ var DEFAULT_OPTIONS = {
}; };
/** /**
* A viewer for BPMN 2.0 diagrams * A viewer for BPMN 2.0 diagrams.
* *
* @class * Includes the basic viewing functionality.
*
* Have a look at {@link NavigatedViewer} or {@link Modeler} for bundles that include
* additional features.
* *
* @param {Object} [options] configuration options to pass to the viewer * @param {Object} [options] configuration options to pass to the viewer
* @param {DOMElement} [options.container] the container to render the viewer in, defaults to body. * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.

View File

@ -1,8 +1,6 @@
'use strict'; 'use strict';
var Matchers = require('../Matchers'), var TestHelper = require('../TestHelper');
TestHelper = require('../TestHelper');
var fs = require('fs'); var fs = require('fs');
@ -11,9 +9,6 @@ var Modeler = require('../../lib/Modeler');
describe('Modeler', function() { describe('Modeler', function() {
beforeEach(Matchers.addDeepEquals);
var container; var container;
beforeEach(function() { beforeEach(function() {

View File

@ -0,0 +1,59 @@
'use strict';
var TestHelper = require('../TestHelper');
var fs = require('fs');
var NavigatedViewer = require('../../lib/NavigatedViewer');
describe('NavigatedViewer', function() {
var container;
beforeEach(function() {
container = jasmine.getEnv().getTestContainer();
});
function createViewer(xml, done) {
var viewer = new NavigatedViewer({ container: container });
viewer.importXML(xml, function(err, warnings) {
done(err, warnings, viewer);
});
}
it('should import simple process', function(done) {
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
createViewer(xml, done);
});
describe('navigation features', function() {
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
it('should include zoomScroll', function(done) {
createViewer(xml, function(err, warnings, viewer) {
expect(viewer.get('zoomScroll')).toBeDefined();
done(err);
});
});
it('should include moveCanvas', function(done) {
createViewer(xml, function(err, warnings, viewer) {
expect(viewer.get('moveCanvas')).toBeDefined();
done(err);
});
});
});
});

View File

@ -1,10 +1,6 @@
'use strict'; 'use strict';
var Matchers = require('../Matchers'), var TestHelper = require('../TestHelper');
TestHelper = require('../TestHelper');
/* global bootstrapViewer, inject */
var fs = require('fs'); var fs = require('fs');
@ -13,9 +9,6 @@ var Viewer = require('../../lib/Viewer');
describe('Viewer', function() { describe('Viewer', function() {
beforeEach(Matchers.addDeepEquals);
var container; var container;
beforeEach(function() { beforeEach(function() {