@@ -109,6 +109,102 @@ PivotView.prototype.init = function () {
109109
110110} ;
111111
112+ /**
113+ * Return cell element which contains table data.
114+ * @param {number } x
115+ * @param {number } y
116+ * @param {boolean } [considerHeaders] - With this flag origin will be set to actual table look
117+ * origin. If false, only table body's first cell will become
118+ * as origin.
119+ * @return {HTMLElement }
120+ */
121+ PivotView . prototype . getCellElement = function ( x , y , considerHeaders ) {
122+
123+ var element = this . tablesStack [ this . tablesStack . length - 1 ] . element ,
124+ table , hh , hw , table2 ;
125+
126+ var getTableCell = function ( table , x , y ) {
127+ var m = [ ] , row , cell , xx , tx , ty , xxx , yyy ;
128+ for ( yyy = 0 ; yyy < table . rows . length ; yyy ++ ) {
129+ row = table . rows [ yyy ] ;
130+ for ( xxx = 0 ; xxx < row . cells . length ; xxx ++ ) {
131+ cell = row . cells [ xxx ] ;
132+ xx = xxx ;
133+ for ( ; m [ yyy ] && m [ yyy ] [ xx ] ; ++ xx ) { }
134+ for ( tx = xx ; tx < xx + cell . colSpan ; ++ tx ) {
135+ for ( ty = yyy ; ty < yyy + cell . rowSpan ; ++ ty ) {
136+ if ( ! m [ ty ] )
137+ m [ ty ] = [ ] ;
138+ m [ ty ] [ tx ] = true ;
139+ }
140+ }
141+ if ( xx <= x && x < xx + cell . colSpan && yyy <= y && y < yyy + cell . rowSpan )
142+ return cell ;
143+ }
144+ }
145+ return null ;
146+ } ;
147+
148+ if ( considerHeaders ) {
149+ table = element . getElementsByClassName ( "lpt-topHeader" ) [ 0 ] ; if ( ! table ) return null ;
150+ table = table . getElementsByTagName ( "table" ) [ 0 ] ; if ( ! table ) return null ;
151+ hh = 0 ; [ ] . slice . call ( table . rows ) . forEach ( function ( e ) {
152+ hh += e . rowSpan || 1 ;
153+ } ) ;
154+ table2 = element . getElementsByClassName ( "lpt-leftHeader" ) [ 0 ] ; if ( ! table ) return null ;
155+ table2 = table2 . getElementsByTagName ( "table" ) [ 0 ] ; if ( ! table ) return null ;
156+ hw = 0 ; [ ] . slice . call ( ( table2 . rows [ 0 ] || { cells : [ ] } ) . cells ) . forEach ( function ( e ) {
157+ hw += e . colSpan || 1 ;
158+ } ) ;
159+ if ( x < hw && y < hh )
160+ return element . getElementsByClassName ( "lpt-headerValue" ) [ 0 ] || null ;
161+ if ( x >= hw && y < hh )
162+ return ( getTableCell ( table , x - hw , y ) || { childNodes : [ null ] } ) . childNodes [ 0 ] ;
163+ if ( x < hw && y >= hh )
164+ return ( getTableCell ( table2 , x , y - hh ) || { childNodes : [ null ] } ) . childNodes [ 0 ] ;
165+ x -= hw ; y -= hh ;
166+ }
167+
168+ table = element . getElementsByClassName ( "lpt-tableBlock" ) [ 0 ] ; if ( ! table ) return null ;
169+ table = table . getElementsByTagName ( "table" ) [ 0 ] ; if ( ! table ) return null ;
170+ return ( ( table . rows [ y ] || { cells : [ ] } ) . cells [ x ] || { childNodes : [ null ] } ) . childNodes [ 0 ] ;
171+
172+ } ;
173+
174+ /**
175+ * @see getCellElement
176+ * @param {boolean } [considerHeaders]
177+ */
178+ PivotView . prototype . getTableSize = function ( considerHeaders ) {
179+
180+ var table , hw = 0 , hh = 0 , element = this . tablesStack [ this . tablesStack . length - 1 ] . element ;
181+
182+ table = element . getElementsByClassName ( "lpt-tableBlock" ) [ 0 ] ; if ( ! table ) return 0 ;
183+ table = table . getElementsByTagName ( "table" ) [ 0 ] ; if ( ! table ) return 0 ;
184+ [ ] . slice . call ( table . rows ) . forEach ( function ( e ) {
185+ hh += e . rowSpan || 1 ;
186+ } ) ;
187+ [ ] . slice . call ( ( table . rows [ 0 ] || { cells : [ ] } ) . cells ) . forEach ( function ( e ) {
188+ hw += e . colSpan || 1 ;
189+ } ) ;
190+
191+ if ( ! considerHeaders ) return { width : hw , height : hh } ;
192+
193+ table = element . getElementsByClassName ( "lpt-topHeader" ) [ 0 ] ; if ( ! table ) return 0 ;
194+ table = table . getElementsByTagName ( "table" ) [ 0 ] ; if ( ! table ) return 0 ;
195+ [ ] . slice . call ( table . rows ) . forEach ( function ( e ) {
196+ hh += e . rowSpan || 1 ;
197+ } ) ;
198+ table = element . getElementsByClassName ( "lpt-leftHeader" ) [ 0 ] ; if ( ! table ) return 0 ;
199+ table = table . getElementsByTagName ( "table" ) [ 0 ] ; if ( ! table ) return 0 ;
200+ [ ] . slice . call ( ( table . rows [ 0 ] || { cells : [ ] } ) . cells ) . forEach ( function ( e ) {
201+ hw += e . colSpan || 1 ;
202+ } ) ;
203+
204+ return { width : hw , height : hh } ;
205+
206+ } ;
207+
112208PivotView . prototype . displayLoading = function ( ) {
113209
114210 this . displayMessage (
0 commit comments