@@ -60,10 +60,59 @@ ClassView.prototype.resetView = function () {
6060
6161} ;
6262
63+ /**
64+ * @param {string } name
65+ * @param classMetaData
66+ * @returns {joint.shapes.uml.Class }
67+ */
68+ ClassView . prototype . createClassInstance = function ( name , classMetaData ) {
69+
70+ var attrArr , methArr ,
71+ classParams = classMetaData [ "parameters" ] ,
72+ classProps = classMetaData [ "properties" ] ,
73+ classMethods = classMetaData [ "methods" ] ;
74+
75+ var insertString = function ( array , string ) {
76+ string . match ( / .{ 1 , 44 } / g) . forEach ( function ( p ) {
77+ array . push ( p ) ;
78+ } ) ;
79+ } ;
80+
81+ return new joint . shapes . uml . Class ( {
82+ name : name ,
83+ attributes : attrArr = ( function ( params , ps ) {
84+ var arr = [ ] , n ;
85+ for ( n in params ) {
86+ insertString ( arr , n + ( params [ n ] [ "type" ] ? ": " + params [ n ] [ "type" ] : "" ) ) ;
87+ }
88+ for ( n in ps ) {
89+ insertString (
90+ arr ,
91+ ( ps [ n ] [ "private" ] ? "- " : "+ " ) + n
92+ + ( ps [ n ] [ "type" ] ? ": " + ps [ n ] [ "type" ] : "" )
93+ ) ;
94+ }
95+ return arr ;
96+ } ) ( classParams , classProps ) ,
97+ methods : methArr = ( function ( ps ) {
98+ var arr = [ ] , n ;
99+ for ( n in ps ) {
100+ insertString ( arr , "+ " + n + ( ps [ n ] [ "returns" ] ? ": " + ps [ n ] [ "returns" ] : "" ) ) ;
101+ }
102+ return arr ;
103+ } ) ( classMethods ) ,
104+ size : {
105+ width : 300 ,
106+ height : Math . max ( attrArr . length * 12.1 , 15 ) + Math . max ( methArr . length * 12.1 , 15 ) + 40
107+ }
108+ } ) ;
109+
110+ } ;
111+
63112ClassView . prototype . render = function ( data ) {
64113
65- var p , pp , className , classProps , classMethods , classInstance ,
66- uml = joint . shapes . uml , attrArr , methArr , relFrom , relTo ,
114+ var p , pp , className , classInstance ,
115+ uml = joint . shapes . uml , relFrom , relTo ,
67116 classes = { } , connector ;
68117
69118 if ( ! data [ "classes" ] ) {
@@ -72,36 +121,7 @@ ClassView.prototype.render = function (data) {
72121 }
73122
74123 for ( className in data [ "classes" ] ) {
75- classProps = data [ "classes" ] [ className ] [ "properties" ] ;
76- classMethods = data [ "classes" ] [ className ] [ "methods" ] ;
77-
78- classInstance = new uml . Class ( {
79- name : className ,
80- attributes : attrArr = ( function ( ps ) {
81- var arr = [ ] , n , s ;
82- for ( n in ps ) {
83- s = ( ps [ n ] [ "private" ] ? "- " : "+ " ) + n + ": " + ps [ n ] [ "type" ] ;
84- s . match ( / .{ 1 , 44 } / g) . forEach ( function ( p ) {
85- arr . push ( p ) ;
86- } ) ;
87- }
88- return arr ;
89- } ) ( classProps ) ,
90- methods : methArr = ( function ( ps ) {
91- var arr = [ ] , n , s ;
92- for ( n in ps ) {
93- s = "+ " + n + ( ps [ n ] [ "returns" ] ? ": " + ps [ n ] [ "returns" ] : "" ) ;
94- s . match ( / .{ 1 , 44 } / g) . forEach ( function ( p ) {
95- arr . push ( p ) ;
96- } ) ;
97- }
98- return arr ;
99- } ) ( classMethods ) ,
100- size : {
101- width : 300 ,
102- height : Math . max ( attrArr . length * 12.1 , 15 ) + Math . max ( methArr . length * 12.1 , 15 ) + 40
103- }
104- } ) ;
124+ classInstance = this . createClassInstance ( className , data [ "classes" ] [ className ] ) ;
105125 this . objects . push ( classInstance ) ;
106126 classes [ className ] = {
107127 instance : classInstance
@@ -168,20 +188,26 @@ ClassView.prototype.updateSizes = function () {
168188/**
169189 * Scale view according to delta.
170190 *
171- * @param {number } delta
191+ * @param {number|string } delta
172192 */
173193ClassView . prototype . zoom = function ( delta ) {
174194
175195 var scaleOld = this . PAPER_SCALE , scaleDelta ;
176- this . PAPER_SCALE += delta * Math . min ( 0.5 , Math . abs ( this . PAPER_SCALE - ( delta < 0 ? this . MIN_PAPER_SCALE : this . MAX_PAPER_SCALE ) ) / 2 ) ;
177- this . paper . scale (
178- this . PAPER_SCALE ,
179- this . PAPER_SCALE
180- ) ;
196+ if ( typeof delta === "number" ) {
197+ this . PAPER_SCALE += delta * Math . min (
198+ 0.5 ,
199+ Math . abs ( this . PAPER_SCALE - ( delta < 0 ? this . MIN_PAPER_SCALE : this . MAX_PAPER_SCALE ) ) / 2
200+ ) ;
201+ } else {
202+ this . PAPER_SCALE = 1 ;
203+ }
204+ this . paper . scale ( this . PAPER_SCALE , this . PAPER_SCALE ) ;
181205 scaleDelta = this . PAPER_SCALE - scaleOld ;
182206 this . paper . setOrigin (
183- this . paper . options . origin . x - scaleDelta * this . cacheUMLExplorer . elements . classViewContainer . offsetWidth / 2 ,
184- this . paper . options . origin . y - scaleDelta * this . cacheUMLExplorer . elements . classViewContainer . offsetHeight / 2
207+ this . paper . options . origin . x
208+ - scaleDelta * this . cacheUMLExplorer . elements . classViewContainer . offsetWidth / 2 ,
209+ this . paper . options . origin . y
210+ - scaleDelta * this . cacheUMLExplorer . elements . classViewContainer . offsetHeight / 2
185211 ) ;
186212
187213} ;
@@ -244,6 +270,15 @@ ClassView.prototype.init = function () {
244270 this . cacheUMLExplorer . elements . classViewContainer . addEventListener ( "mousewheel" , function ( e ) {
245271 self . zoom ( Math . max ( - 1 , Math . min ( 1 , ( e . wheelDelta || - e . detail ) ) ) ) ;
246272 } ) ;
273+ this . cacheUMLExplorer . elements . zoomInButton . addEventListener ( "click" , function ( ) {
274+ self . zoom ( 1 ) ;
275+ } ) ;
276+ this . cacheUMLExplorer . elements . zoomOutButton . addEventListener ( "click" , function ( ) {
277+ self . zoom ( - 1 ) ;
278+ } ) ;
279+ this . cacheUMLExplorer . elements . zoomNormalButton . addEventListener ( "click" , function ( ) {
280+ self . zoom ( null ) ;
281+ } ) ;
247282
248283 //var classes = {
249284 //
0 commit comments