Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

329 lines
11 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.grid.PivotAxis"></div>/**
  16. * @class Ext.grid.PivotAxis
  17. * @extends Ext.Component
  18. * <p>PivotAxis is a class that supports a {@link Ext.grid.PivotGrid}. Each PivotGrid contains two PivotAxis instances - the left
  19. * axis and the top axis. Each PivotAxis defines an ordered set of dimensions, each of which should correspond to a field in a
  20. * Store's Record (see {@link Ext.grid.PivotGrid} documentation for further explanation).</p>
  21. * <p>Developers should have little interaction with the PivotAxis instances directly as most of their management is performed by
  22. * the PivotGrid. An exception is the dynamic reconfiguration of axes at run time - to achieve this we use PivotAxis's
  23. * {@link #setDimensions} function and refresh the grid:</p>
  24. <pre><code>
  25. var pivotGrid = new Ext.grid.PivotGrid({
  26. //some PivotGrid config here
  27. });
  28. //change the left axis dimensions
  29. pivotGrid.leftAxis.setDimensions([
  30. {
  31. dataIndex: 'person',
  32. direction: 'DESC',
  33. width : 100
  34. },
  35. {
  36. dataIndex: 'product',
  37. direction: 'ASC',
  38. width : 80
  39. }
  40. ]);
  41. pivotGrid.view.refresh(true);
  42. </code></pre>
  43. * This clears the previous dimensions on the axis and redraws the grid with the new dimensions.
  44. */
  45. Ext.grid.PivotAxis = Ext.extend(Ext.Component, {
  46. <div id="cfg-Ext.grid.PivotAxis-orientation"></div>/**
  47. * @cfg {String} orientation One of 'vertical' or 'horizontal'. Defaults to horizontal
  48. */
  49. orientation: 'horizontal',
  50. <div id="cfg-Ext.grid.PivotAxis-defaultHeaderWidth"></div>/**
  51. * @cfg {Number} defaultHeaderWidth The width to render each row header that does not have a width specified via
  52. {@link #getRowGroupHeaders}. Defaults to 80.
  53. */
  54. defaultHeaderWidth: 80,
  55. /**
  56. * @private
  57. * @cfg {Number} paddingWidth The amount of padding used by each cell.
  58. * TODO: From 4.x onwards this can be removed as it won't be needed. For now it is used to account for the differences between
  59. * the content box and border box measurement models
  60. */
  61. paddingWidth: 7,
  62. <div id="method-Ext.grid.PivotAxis-setDimensions"></div>/**
  63. * Updates the dimensions used by this axis
  64. * @param {Array} dimensions The new dimensions
  65. */
  66. setDimensions: function(dimensions) {
  67. this.dimensions = dimensions;
  68. },
  69. /**
  70. * @private
  71. * Builds the html table that contains the dimensions for this axis. This branches internally between vertical
  72. * and horizontal orientations because the table structure is slightly different in each case
  73. */
  74. onRender: function(ct, position) {
  75. var rows = this.orientation == 'horizontal'
  76. ? this.renderHorizontalRows()
  77. : this.renderVerticalRows();
  78. this.el = Ext.DomHelper.overwrite(ct.dom, {tag: 'table', cn: rows}, true);
  79. },
  80. /**
  81. * @private
  82. * Specialised renderer for horizontal oriented axes
  83. * @return {Object} The HTML Domspec for a horizontal oriented axis
  84. */
  85. renderHorizontalRows: function() {
  86. var headers = this.buildHeaders(),
  87. rowCount = headers.length,
  88. rows = [],
  89. cells, cols, colCount, i, j;
  90. for (i = 0; i < rowCount; i++) {
  91. cells = [];
  92. cols = headers[i].items;
  93. colCount = cols.length;
  94. for (j = 0; j < colCount; j++) {
  95. cells.push({
  96. tag: 'td',
  97. html: cols[j].header,
  98. colspan: cols[j].span
  99. });
  100. }
  101. rows[i] = {
  102. tag: 'tr',
  103. cn: cells
  104. };
  105. }
  106. return rows;
  107. },
  108. /**
  109. * @private
  110. * Specialised renderer for vertical oriented axes
  111. * @return {Object} The HTML Domspec for a vertical oriented axis
  112. */
  113. renderVerticalRows: function() {
  114. var headers = this.buildHeaders(),
  115. colCount = headers.length,
  116. rowCells = [],
  117. rows = [],
  118. rowCount, col, row, colWidth, i, j;
  119. for (i = 0; i < colCount; i++) {
  120. col = headers[i];
  121. colWidth = col.width || 80;
  122. rowCount = col.items.length;
  123. for (j = 0; j < rowCount; j++) {
  124. row = col.items[j];
  125. rowCells[row.start] = rowCells[row.start] || [];
  126. rowCells[row.start].push({
  127. tag : 'td',
  128. html : row.header,
  129. rowspan: row.span,
  130. width : Ext.isBorderBox ? colWidth : colWidth - this.paddingWidth
  131. });
  132. }
  133. }
  134. rowCount = rowCells.length;
  135. for (i = 0; i < rowCount; i++) {
  136. rows[i] = {
  137. tag: 'tr',
  138. cn : rowCells[i]
  139. };
  140. }
  141. return rows;
  142. },
  143. /**
  144. * @private
  145. * Returns the set of all unique tuples based on the bound store and dimension definitions.
  146. * Internally we construct a new, temporary store to make use of the multi-sort capabilities of Store. In
  147. * 4.x this functionality should have been moved to MixedCollection so this step should not be needed.
  148. * @return {Array} All unique tuples
  149. */
  150. getTuples: function() {
  151. var newStore = new Ext.data.Store({});
  152. newStore.data = this.store.data.clone();
  153. newStore.fields = this.store.fields;
  154. var sorters = [],
  155. dimensions = this.dimensions,
  156. length = dimensions.length,
  157. i;
  158. for (i = 0; i < length; i++) {
  159. sorters.push({
  160. field : dimensions[i].dataIndex,
  161. direction: dimensions[i].direction || 'ASC'
  162. });
  163. }
  164. newStore.sort(sorters);
  165. var records = newStore.data.items,
  166. hashes = [],
  167. tuples = [],
  168. recData, hash, info, data, key;
  169. length = records.length;
  170. for (i = 0; i < length; i++) {
  171. info = this.getRecordInfo(records[i]);
  172. data = info.data;
  173. hash = "";
  174. for (key in data) {
  175. hash += data[key] + '---';
  176. }
  177. if (hashes.indexOf(hash) == -1) {
  178. hashes.push(hash);
  179. tuples.push(info);
  180. }
  181. }
  182. newStore.destroy();
  183. return tuples;
  184. },
  185. /**
  186. * @private
  187. */
  188. getRecordInfo: function(record) {
  189. var dimensions = this.dimensions,
  190. length = dimensions.length,
  191. data = {},
  192. dimension, dataIndex, i;
  193. //get an object containing just the data we are interested in based on the configured dimensions
  194. for (i = 0; i < length; i++) {
  195. dimension = dimensions[i];
  196. dataIndex = dimension.dataIndex;
  197. data[dataIndex] = record.get(dataIndex);
  198. }
  199. //creates a specialised matcher function for a given tuple. The returned function will return
  200. //true if the record passed to it matches the dataIndex values of each dimension in this axis
  201. var createMatcherFunction = function(data) {
  202. return function(record) {
  203. for (var dataIndex in data) {
  204. if (record.get(dataIndex) != data[dataIndex]) {
  205. return false;
  206. }
  207. }
  208. return true;
  209. };
  210. };
  211. return {
  212. data: data,
  213. matcher: createMatcherFunction(data)
  214. };
  215. },
  216. /**
  217. * @private
  218. * Uses the calculated set of tuples to build an array of headers that can be rendered into a table using rowspan or
  219. * colspan. Basically this takes the set of tuples and spans any cells that run into one another, so if we had dimensions
  220. * of Person and Product and several tuples containing different Products for the same Person, those Products would be
  221. * spanned.
  222. * @return {Array} The headers
  223. */
  224. buildHeaders: function() {
  225. var tuples = this.getTuples(),
  226. rowCount = tuples.length,
  227. dimensions = this.dimensions,
  228. colCount = dimensions.length,
  229. headers = [],
  230. tuple, rows, currentHeader, previousHeader, span, start, isLast, changed, i, j;
  231. for (i = 0; i < colCount; i++) {
  232. dimension = dimensions[i];
  233. rows = [];
  234. span = 0;
  235. start = 0;
  236. for (j = 0; j < rowCount; j++) {
  237. tuple = tuples[j];
  238. isLast = j == (rowCount - 1);
  239. currentHeader = tuple.data[dimension.dataIndex];
  240. /*
  241. * 'changed' indicates that we need to create a new cell. This should be true whenever the cell
  242. * above (previousHeader) is different from this cell, or when the cell on the previous dimension
  243. * changed (e.g. if the current dimension is Product and the previous was Person, we need to start
  244. * a new cell if Product is the same but Person changed, so we check the previous dimension and tuple)
  245. */
  246. changed = previousHeader != undefined && previousHeader != currentHeader;
  247. if (i > 0 && j > 0) {
  248. changed = changed || tuple.data[dimensions[i-1].dataIndex] != tuples[j-1].data[dimensions[i-1].dataIndex];
  249. }
  250. if (changed) {
  251. rows.push({
  252. header: previousHeader,
  253. span : span,
  254. start : start
  255. });
  256. start += span;
  257. span = 0;
  258. }
  259. if (isLast) {
  260. rows.push({
  261. header: currentHeader,
  262. span : span + 1,
  263. start : start
  264. });
  265. start += span;
  266. span = 0;
  267. }
  268. previousHeader = currentHeader;
  269. span++;
  270. }
  271. headers.push({
  272. items: rows,
  273. width: dimension.width || this.defaultHeaderWidth
  274. });
  275. previousHeader = undefined;
  276. }
  277. return headers;
  278. }
  279. });
  280. </pre>
  281. </body>
  282. </html>