├── LICENSE ├── README.md ├── build ├── jbPivot.js └── jbPivot.min.js ├── css └── jbPivot.css ├── dobuild ├── jbPivot.jquery.json ├── package.json ├── src ├── agregate_average.js ├── agregate_count.js ├── agregate_distinct.js ├── agregate_sum.js ├── formatter_default.js ├── group_distinct.js └── pivot.js └── test └── testpivot.html /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jbPivot 2 | 3 | A simple jQuery pivot table widget 4 | 5 | ## Web site 6 | 7 | For examples and usages see: 8 | 9 | ## Version 10 | 11 | 0.1 - First Version 12 | 13 | ## Usage 14 | 15 | Include jquery and jqueryui: 16 | 17 | 18 | 19 | 20 | Include jbPivot and the css file: 21 | 22 | 23 | 24 | 25 | Insert a div where you want the table: 26 | 27 |
28 | 29 | Initialize the table: 30 | 31 | $("#myTable").jbPivot(options); 32 | 33 | Where options has the next format. 34 | 35 | var options= { fields: { 36 | : { 37 | field: "" 38 | ,label: "" 39 | ,sort: <"asc"|"desc"> 40 | ,showAll: 41 | ,groupType: <"distinct"*|"none"|...> 42 | ,agregateType: <"distinct"*|"count"|"average"|"sum"|...> 43 | ,formatter: 47 | } 48 | ,...(0..n) 49 | } 50 | ,xfields:["" ,...(0..n) ] 51 | ,yfields:["" ,...(0..n) ] 52 | ,zfields:["" ,...(0..n) ] 53 | ,copyright: 54 | ,summary: 55 | ,data: [ 56 | {"": 57 | ,...(0..n) 58 | } 59 | ,...(0..n) 60 | ] 61 | ,formatter: <"default"*|...|function(val, field) { // Only called when the field specific formated is not defined 62 | // Calculate the formated val 63 | return formatedVal; 64 | } 65 | ,l_all: "All" // Translation of the word all to be displayed 66 | ,l_unused_fields: "Unused fields" //Translation of the word "Unused fields to be displayed" 67 | }; 68 | 69 | Yo can insert more records to the table dinamicaly: 70 | 71 | $("#pivot1").data('jbPivot').insertRecords([ 72 | {id:1 ,gender:"male", age:"30-40",eyes:"green", v:8}, 73 | {id:2 ,gender:"male", age:"20-30",eyes:"brown", v:7}, 74 | {id:3 ,gender:"male", age:"30-40",eyes:"brown", v:3}, 75 | {id:4 ,gender:"female", age:"40-50",eyes:"brown", v:5}, 76 | {id:5 ,gender:"male", age:"30-40",eyes:"green", v:7}, 77 | {id:6 ,gender:"male", age:"30-40",eyes:"green", v:9}, 78 | {id:7 ,gender:"female", age:"40-50",eyes:"green", v:8} 79 | ]); 80 | 81 | In order to insert a field, You change the options, meke a reset and then reinsert the data: 82 | 83 | $("#pivot1").data('jbPivot').options.fields.NewField={ field: 'v', agregateType: "sum", groupType:"none" }; 84 | $("#pivot1").data('jbPivot').reset(); 85 | $("#pivot1").data('jbPivot').insertRecords([ 86 | {id:1 ,gender:"male", age:"30-40",eyes:"green", v:8}, 87 | {id:2 ,gender:"male", age:"20-30",eyes:"brown", v:7}, 88 | {id:3 ,gender:"male", age:"30-40",eyes:"brown", v:3}, 89 | {id:4 ,gender:"female", age:"40-50",eyes:"brown", v:5}, 90 | {id:5 ,gender:"male", age:"30-40",eyes:"green", v:7}, 91 | {id:6 ,gender:"male", age:"30-40",eyes:"green", v:9}, 92 | {id:7 ,gender:"female", age:"40-50",eyes:"green", v:8}, 93 | ]); 94 | 95 | 96 | Goto to see more examples. 97 | 98 | 99 | ## Author 100 | 101 | Uniclau S.L. 102 | 103 | 104 | ## License 105 | 106 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 107 | 108 | This program is free software: you can redistribute it and/or modify 109 | it under the terms of the GNU General Public License as published by 110 | the Free Software Foundation, either version 3 of the License, or 111 | (at your option) any later version. 112 | 113 | This program is distributed in the hope that it will be useful, 114 | but WITHOUT ANY WARRANTY; without even the implied warranty of 115 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 116 | GNU General Public License for more details. 117 | 118 | There is a copy of the license in the COPYING file in this directory. 119 | 120 | You can also find it at . 121 | -------------------------------------------------------------------------------- /build/jbPivot.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 3 | 4 | This file is part of jbPivot. 5 | 6 | jbPivot is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | jbPivot is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with jbPivot. If not, see . 18 | */ 19 | 20 | 21 | $.unc = { 22 | plugins: { 23 | agregates: {}, 24 | addAgregate: function(agregateName, factory) { 25 | "use strict"; 26 | this.agregates[agregateName] = factory; 27 | }, 28 | groupers: {}, 29 | addGrouper: function(grouperName, factory) { 30 | "use strict"; 31 | this.groupers[grouperName] = factory; 32 | }, 33 | formatters: {}, 34 | addFormatter: function(formatterName, factory) { 35 | "use strict"; 36 | this.formatters[formatterName] = factory; 37 | } 38 | } 39 | }; 40 | 41 | 42 | $(function() { 43 | "use strict"; 44 | $.widget("unc.jbPivot", { 45 | options: { 46 | fields: {}, 47 | summary: true, 48 | copyright: true, 49 | formatter: "default", 50 | l_all: "All", 51 | l_unused_fields: "Unused fields" 52 | }, 53 | _create: function() { 54 | this.CollapsedNodes = {}; 55 | this.renderPending = false; 56 | this.reset(); 57 | if (typeof this.options.data !== "undefined") { 58 | this.insertRecords(this.options.data); 59 | } 60 | var self = this; 61 | $(this.element).on('click', ".collapse_button", function(event) { 62 | event.preventDefault(); 63 | self._togleCollapse(this.rel); 64 | }); 65 | 66 | $(this.element).on('dragstart', '.draggable', function(event) { 67 | self.pre_post = ""; 68 | self.dragcls = ""; 69 | self.dragdata = $(this).attr("rel"); 70 | event.originalEvent.dataTransfer.effectAllowed = 'move'; 71 | event.originalEvent.dataTransfer.setData("Text", $(this).attr("rel")); 72 | $(".pivot").addClass("drag_in_progress"); 73 | }); 74 | 75 | 76 | 77 | $(this.element).on('dragleave', '.dropable', function(event) { 78 | 79 | // var target=$(event.originalEvent.target); 80 | var target = $(this); 81 | var arr = target.attr('class').match(/\s+(target(X|Y|Z|U)[\d]+)($|\s)/); 82 | var cls = "." + arr[1]; 83 | var el = self.element; 84 | setTimeout(function() { 85 | $(cls, el).removeClass("dropping_pre"); 86 | $(cls, el).removeClass("dropping_post"); 87 | self.pre_post = ""; 88 | self.dragcls = ""; 89 | }, 0); 90 | 91 | event.stopPropagation(); 92 | event.preventDefault(); 93 | return false; 94 | }); 95 | 96 | $(this.element).on('dragover', '.dropable', function(event) { 97 | var target = $(this); 98 | var parentOffset = $(this).offset(); 99 | //or $(this).offset(); if you really just want the current element's offset 100 | var offsetX = event.originalEvent.pageX - parentOffset.left; 101 | var offsetY = event.originalEvent.pageY - parentOffset.top; 102 | 103 | var arr = target.attr('class').match(/\s+(target(X|Y|Z|U)([\d]+))($|\s)/); 104 | arr[3] = parseInt(arr[3], 10); 105 | var cls = "." + arr[1]; 106 | 107 | var pre_post; 108 | var oldpp = self.pre_post; 109 | var oldcls = self.dragcls; 110 | if ((arr[2] === "Y") || (arr[2] === "U")) { 111 | pre_post = offsetY > target.height() / 2 ? "post" : "pre"; 112 | } else { 113 | pre_post = offsetX > target.width() / 2 ? "post" : "pre"; 114 | } 115 | if (arr[3] === 0) { 116 | pre_post = "post"; 117 | } 118 | 119 | var from = self.dragdata; 120 | var to = $(this).attr("rel"); 121 | if (self._canMove(from, to, pre_post)) { 122 | 123 | var el = self.element; 124 | 125 | if ((oldpp !== pre_post) || (cls !== oldcls)) { 126 | $(cls, el).removeClass("dropping_pre"); 127 | $(cls, el).removeClass("dropping_post"); 128 | setTimeout(function() { 129 | $(cls, el).addClass("dropping_" + pre_post); 130 | self.pre_post = pre_post; 131 | self.dragcls = cls; 132 | }, 0); 133 | } 134 | 135 | 136 | event.originalEvent.dataTransfer.dropEffect = 'move'; 137 | event.stopPropagation(); 138 | event.preventDefault(); 139 | return false; 140 | } 141 | }); 142 | 143 | $(this.element).on('drop', '.dropable', function(event) { 144 | var target = $(this); 145 | 146 | var parentOffset = $(this).offset(); 147 | //or $(this).offset(); if you really just want the current element's offset 148 | var offsetX = event.originalEvent.pageX - parentOffset.left; 149 | var offsetY = event.originalEvent.pageY - parentOffset.top; 150 | 151 | var arr = target.attr('class').match(/\s+(target(X|Y|Z|U)([\d]+))($|\s)/); 152 | arr[3] = parseInt(arr[3], 10); 153 | 154 | var pre_pos; 155 | if ((arr[2] === "Y") || (arr[2] === "U")) { 156 | pre_pos = offsetY > target.height() / 2 ? "post" : "pre"; 157 | } else { 158 | pre_pos = offsetX > target.width() / 2 ? "post" : "pre"; 159 | } 160 | if (arr[3] === 0) { 161 | pre_pos = "post"; 162 | } 163 | var from = event.originalEvent.dataTransfer.getData("Text"); 164 | var to = $(this).attr("rel"); 165 | self._moveField(from, to, pre_pos); 166 | event.preventDefault(); 167 | return false; 168 | }); 169 | 170 | $(this.element).on('dragend', '.dropable', function() { 171 | var el = self.element; 172 | $(".pivot", el).removeClass("drag_in_progress"); 173 | }); 174 | 175 | }, 176 | reset: function() { 177 | this.fields = []; 178 | this.afields = []; 179 | this.xfields = []; 180 | this.yfields = []; 181 | this.zfields = []; 182 | this.ufields = []; 183 | this.fieldNames = []; 184 | this.fieldLabels = []; 185 | this.formatters = []; 186 | 187 | if ((typeof this.options.formatter === "undefined") || (this.options.formatter === null)) { 188 | this.options.formatter = "default"; 189 | } 190 | if (typeof this.options.formatter === "string") { 191 | if (typeof $.unc.plugins.formatters[this.options.formatter] !== "function") { 192 | throw ("Formatter: " + this.options.formatter + " is not defined"); 193 | } 194 | this.defaultFormatter = $.unc.plugins.formatters[this.options.formatter](this.options); 195 | } else if (typeof this.options.formatter === "function") { 196 | this.defaultFormatter = { 197 | format: this.options.formatter 198 | }; 199 | } else { 200 | throw ("Invalid formatter"); 201 | } 202 | 203 | if (this.options.formatter === null) { 204 | throw ("Formatter not defined"); 205 | } 206 | 207 | var f; 208 | var k = 0; 209 | var indexbyname = {}; 210 | for (f in this.options.fields) { 211 | if (this.options.fields.hasOwnProperty(f)) { 212 | var fo = $.extend({ 213 | agregateType: "distinct", 214 | groupType: "distinct", 215 | label: f, 216 | formatter: null 217 | }, this.options.fields[f]); 218 | 219 | if (fo.groupType !== "none") { 220 | if (typeof $.unc.plugins.groupers[fo.groupType] !== "function") { 221 | throw ("Grouper: " + fo.groupType + " is not defined"); 222 | } 223 | this.fields.push($.unc.plugins.groupers[fo.groupType](fo)); 224 | } else { 225 | this.fields.push(null); 226 | } 227 | 228 | if (fo.agregateType !== "none") { 229 | if (typeof $.unc.plugins.agregates[fo.agregateType] !== "function") { 230 | throw ("Grouper: " + fo.agregateType + " is not defined"); 231 | } 232 | this.afields.push($.unc.plugins.agregates[fo.agregateType](fo)); 233 | } else { 234 | this.afields.push(null); 235 | } 236 | 237 | if (typeof fo.formatter === "string") { 238 | if (typeof $.unc.plugins.formatters[fo.formatter] !== "function") { 239 | throw ("Formatter" + fo.formatter + " is not defined"); 240 | } 241 | this.formatters.push($.unc.plugins.formatters[fo.formatter](fo)); 242 | } else if (typeof fo.formatter === "function") { 243 | this.formatters.push({ 244 | format: fo.formatter 245 | }); 246 | } else { 247 | this.formatters.push(null); 248 | } 249 | 250 | indexbyname[f] = k; 251 | k++; 252 | 253 | this.fieldNames.push(f); 254 | this.fieldLabels.push(fo.label); 255 | } 256 | } 257 | 258 | var i, fn; 259 | 260 | for (i = 0; i < this.options.xfields.length; i++) { 261 | fn = this.options.xfields[i]; 262 | if (typeof indexbyname[fn] === "undefined") { 263 | throw ("Field " + fn + " in xfields not defined"); 264 | } 265 | if (typeof this.fields[indexbyname[fn]] === null) { 266 | throw ("Field " + fn + "is not groupable ans is ispecified in xfields"); 267 | } 268 | this.xfields.push(indexbyname[fn]); 269 | delete indexbyname[fn]; 270 | } 271 | for (i = 0; i < this.options.yfields.length; i++) { 272 | fn = this.options.yfields[i]; 273 | if (typeof indexbyname[fn] === "undefined") { 274 | throw ("Field " + fn + " in yfields not defined"); 275 | } 276 | if (typeof this.fields[indexbyname[fn]] === null) { 277 | throw ("Field " + fn + "is not groupable ans is ispecified in yfields"); 278 | } 279 | this.yfields.push(indexbyname[fn]); 280 | delete indexbyname[fn]; 281 | } 282 | for (i = 0; i < this.options.zfields.length; i++) { 283 | fn = this.options.zfields[i]; 284 | if (typeof indexbyname[fn] === "undefined") { 285 | throw ("Field " + fn + " in zfields not defined"); 286 | } 287 | if (typeof this.afields[indexbyname[fn]] === null) { 288 | throw ("Field " + fn + "is not agregatable ans is ispecified in zfields"); 289 | } 290 | this.zfields.push(indexbyname[fn]); 291 | delete indexbyname[fn]; 292 | } 293 | for (fn in indexbyname) { 294 | if (indexbyname.hasOwnProperty(fn)) { 295 | this.ufields.push(indexbyname[fn]); 296 | } 297 | } 298 | 299 | 300 | var mask = (1 << this.fields.length) - 1; 301 | 302 | this.indexes = {}; 303 | this.indexes_len = {}; 304 | 305 | this.indexes[mask] = {}; 306 | this.indexes_len[mask] = 0; 307 | this._generate_trees(); 308 | 309 | this._forceRender(); 310 | }, 311 | insertRecords: function(records) { 312 | var i, f; 313 | for (i = 0; i < records.length; i++) { 314 | var R = records[i]; 315 | 316 | var mindex = []; 317 | for (f = 0; f < this.fields.length; f++) { 318 | if (this.fields[f] !== null) { 319 | mindex.push(this.fields[f].CalculateValue(R)); 320 | } else { 321 | mindex.push(0); 322 | } 323 | } 324 | 325 | 326 | for (var mask in this.indexes) { 327 | if (this.indexes.hasOwnProperty(mask)) { 328 | 329 | var mindex2 = mindex.slice(0); 330 | for (var k = 0; k < this.fields.length; k++) { 331 | if (((1 << k) & mask) === 0) { 332 | mindex2[k] = 0; 333 | } 334 | } 335 | 336 | var groupidx = this._arr2idx(mindex2); 337 | 338 | if (typeof this.indexes[mask][groupidx] === "undefined") { 339 | this.indexes[mask][groupidx] = []; 340 | this.indexes_len[mask]++; 341 | } 342 | for (f = 0; f < this.afields.length; f++) { 343 | if (this.afields[f] !== null) { 344 | this.indexes[mask][groupidx][f] = this.afields[f].agregate(this.indexes[mask][groupidx][f], R); 345 | } 346 | } 347 | } 348 | } 349 | } 350 | 351 | this._generate_trees(); 352 | this._forceRender(); 353 | }, 354 | _forceRender: function() { 355 | if (this.renderPending) { 356 | return; 357 | } 358 | this.renderPending = true; 359 | var self = this; 360 | setTimeout(function() { 361 | self.renderPending = false; 362 | self._renderHtml(); 363 | }, 100); 364 | }, 365 | _arr2idx: function(arr) { 366 | return arr.join(","); 367 | }, 368 | _idx2arr: function(S) { 369 | var i; 370 | var arr = S.split(","); 371 | var res = []; 372 | for (i = 0; i < arr.length; i++) { 373 | res.push(parseInt(arr[i], 10)); 374 | } 375 | return res; 376 | }, 377 | // Returns an array of with all agregated fields from a vector (-1 means any). 378 | _getValues: function(mindex) { 379 | var groupidx; 380 | var mask = 0; 381 | for (var i = 0; i < this.fields.length; i++) { 382 | if (mindex[i] === -1) { 383 | mindex[i] = 0; 384 | } else { 385 | mask = mask | (1 << i); 386 | } 387 | } 388 | 389 | if (typeof this.indexes[mask] === "undefined") { 390 | this._generate_index(mask); 391 | } 392 | 393 | groupidx = this._arr2idx(mindex); 394 | 395 | var V = this.indexes[mask][groupidx]; 396 | if ((typeof V === "undefined") || (V === null)) { 397 | V = new Array(this.afields.length); 398 | } 399 | 400 | return V; 401 | }, 402 | _generate_index: function(mask) { 403 | var m; 404 | var smask = null; 405 | 406 | for (m in this.indexes) { 407 | if ((mask & m) === mask) { 408 | if ((smask === null) || (this.indexes_len[m] < this.indexes_len[smask])) { 409 | smask = m; 410 | } 411 | } 412 | } 413 | 414 | this.indexes[mask] = {}; 415 | this.indexes_len[mask] = 0; 416 | 417 | for (var v in this.indexes[smask]) { 418 | if (this.indexes[smask].hasOwnProperty(v)) { 419 | var mindex = this._idx2arr(v); 420 | for (m = 0; m < this.fields.length; m++) { 421 | if (((1 << m) & mask) === 0) { 422 | mindex[m] = 0; 423 | } 424 | } 425 | var groupidx = this._arr2idx(mindex); 426 | 427 | if (typeof this.indexes[mask][groupidx] === "undefined") { 428 | this.indexes[mask][groupidx] = []; 429 | this.indexes_len[mask]++; 430 | } 431 | for (var f = 0; f < this.afields.length; f++) { 432 | if (this.afields[f] !== null) { 433 | this.indexes[mask][groupidx][f] = this.afields[f].agregate(this.indexes[mask][groupidx][f], 434 | this.indexes[smask][v][f]); 435 | } 436 | } 437 | } 438 | } 439 | }, 440 | _generate_trees: function() { 441 | var node, i; 442 | var mask = (1 << this.fields.length) - 1; 443 | this.xtree = { 444 | childs: {} 445 | }; 446 | this.ytree = { 447 | childs: {} 448 | }; 449 | for (var k in this.indexes[mask]) { 450 | if (this.indexes[mask].hasOwnProperty(k)) { 451 | var mindex = this._idx2arr(k); 452 | 453 | node = this.xtree; 454 | 455 | for (i = 0; i < this.xfields.length; i++) { 456 | if (typeof node.childs[mindex[this.xfields[i]]] === "undefined") { 457 | node.childs[mindex[this.xfields[i]]] = { 458 | childs: {} 459 | }; 460 | } 461 | node = node.childs[mindex[this.xfields[i]]]; 462 | 463 | } 464 | 465 | node = this.ytree; 466 | 467 | for (i = 0; i < this.yfields.length; i++) { 468 | if (typeof node.childs[mindex[this.yfields[i]]] === "undefined") { 469 | node.childs[mindex[this.yfields[i]]] = { 470 | childs: {} 471 | }; 472 | } 473 | node = node.childs[mindex[this.yfields[i]]]; 474 | } 475 | } 476 | } 477 | }, 478 | _tree2table: function(axis, node, table) { 479 | 480 | var x, y, c; 481 | 482 | var w = axis === "y" ? this.yfields.length : this.xfields.length; 483 | 484 | y = table.length - 1; 485 | x = table[y].index.length; 486 | 487 | 488 | var m; 489 | 490 | if (this._isCollapsed(axis, table[y].index)) { 491 | table[y].cells[x] = {}; 492 | table[y].cells[x].spanx = w - x + 1; 493 | table[y].cells[x].spany = 1; 494 | m = 1; 495 | } else { 496 | var baseindex = table[y].index.slice(0); 497 | var newline = false; 498 | m = 0; 499 | 500 | 501 | var displayvalues; 502 | if (x < w) { 503 | var usedvalues = []; 504 | for (c in node.childs) { 505 | if (node.childs.hasOwnProperty(c)) { 506 | usedvalues.push(c); 507 | } 508 | } 509 | 510 | var fd = axis === "y" ? this.fields[this.yfields[x]] : this.fields[this.xfields[x]]; 511 | displayvalues = fd.DisplayValues(usedvalues); 512 | } else { 513 | displayvalues = []; 514 | } 515 | 516 | for (c = 0; c < displayvalues.length; c++) { 517 | 518 | if (newline) { 519 | table.push({ 520 | index: baseindex.slice(0), 521 | cells: {} 522 | }); 523 | } 524 | 525 | table[table.length - 1].index.push(displayvalues[c]); 526 | 527 | var nextNode; 528 | if (typeof node.childs[displayvalues[c]] === "undefined") { 529 | nextNode = { 530 | childs: {}, 531 | collapsed: false 532 | }; 533 | } else { 534 | nextNode = node.childs[displayvalues[c]]; 535 | } 536 | 537 | m += this._tree2table(axis, nextNode, table); 538 | newline = true; 539 | } 540 | 541 | if (m === 0) { 542 | table[y].cells[x] = {}; 543 | table[y].cells[x].spanx = w - x + 1; 544 | table[y].cells[x].spany = 1; 545 | m = 1; 546 | } else { 547 | table[y].cells[x] = {}; 548 | table[y].cells[x].spanx = 1; 549 | table[y].cells[x].spany = m; 550 | } 551 | } 552 | 553 | return m; 554 | }, 555 | _collapseLink: function(axis, mindex) { 556 | var S = ""; 557 | 558 | S += this._isCollapsed(axis, mindex) ? "+" : "-"; 559 | 560 | S += ""; 561 | return S; 562 | 563 | }, 564 | _renderHtml: function() { 565 | var colspan, cls, i, x, y, z, mindex; 566 | 567 | var cmax = this.xfields.length > this.yfields.length ? this.xfields.length : this.yfields.length; 568 | cmax++; 569 | 570 | var tablex = [{ 571 | index: [], 572 | cells: {} 573 | }]; 574 | this._tree2table("x", this.xtree, tablex); 575 | 576 | var tabley = [{ 577 | index: [], 578 | cells: {} 579 | }]; 580 | this._tree2table("y", this.ytree, tabley); 581 | 582 | var S = ""; 583 | 584 | S += ""; 585 | 586 | for (i = 0; i < this.ufields.length; i++) { 587 | S += ""; 608 | 609 | S += ""; 642 | S += "\n"; 643 | 644 | for (y = 1; y <= this.yfields.length; y++) { 645 | S += ""; 646 | for (x = 0; x < tabley.length; x++) { 647 | if (tabley[x].cells[y]) { 648 | S += ""; 675 | } 676 | } 677 | S += "\n"; 678 | } 679 | 680 | S += ""; 681 | for (x = 0; x < tabley.length; x++) { 682 | for (z = 0; z < this.zfields.length; z++) { 683 | S += ""; 788 | } 789 | } 790 | 791 | for (x = 0; x < tabley.length; x++) { 792 | 793 | mindex = []; 794 | for (i = 0; i < this.fields.length; i++) { 795 | mindex.push(-1); 796 | } 797 | 798 | for (i = 0; i < tablex[y].index.length; i++) { 799 | mindex[this.xfields[i]] = tablex[y].index[i]; 800 | } 801 | 802 | for (i = 0; i < tabley[x].index.length; i++) { 803 | mindex[this.yfields[i]] = tabley[x].index[i]; 804 | } 805 | 806 | V = this._getValues(mindex); 807 | 808 | for (z = 0; z < this.zfields.length; z++) { 809 | S += " 0)) { 861 | S += ""; 862 | S += "
" + this.options.l_unused_fields + "
"; 603 | 604 | 605 | 606 | 607 | S += "
0 ? this.zfields.length : 1); 624 | S += " 0) { 636 | S += this._collapseLink("y", []); 637 | } 638 | 639 | S += this.options.l_all; 640 | 641 | S += "
0 ? this.zfields.length : 1); 661 | 662 | S += " colspan=\"" + colspan + "\""; 663 | S += " rowspan=\"" + tabley[x].cells[y].spanx + "\""; 664 | S += ">"; 665 | 666 | 667 | if (y < this.yfields.length) { 668 | S += this._collapseLink("y", tabley[x].index.slice(0, y)); 669 | } 670 | 671 | S += this.fields[this.yfields[y - 1]].getStringValue(tabley[x].index[y - 1]); 672 | 673 | 674 | S += "
1 ? " colspan=\"" + tablex[y].cells[x].spanx + "\"" : ""; 753 | S += tablex[y].cells[x].spany > 1 ? " rowspan=\"" + tablex[y].cells[x].spany + "\"" : ""; 754 | 755 | cls = "lefttitle dropable"; 756 | if (x > 0) { 757 | cls += " draggable"; 758 | } 759 | if (x === 0) { 760 | cls += " line_left_" + cmax; 761 | } 762 | 763 | cls += this._clsTopLine(tablex, y, tablex[y].cells[x].spany); 764 | cls += this._clsBottomLine(tablex, y, tablex[y].cells[x].spany); 765 | cls += " targetX" + x; 766 | 767 | S += " class=\"" + cls + "\""; 768 | 769 | S += "\""; 770 | S += " rel=\"X," + x + "\""; 771 | 772 | if (x > 0) { 773 | S += " draggable=\"true\""; 774 | } 775 | 776 | S += ">"; 777 | 778 | if (x < this.xfields.length) { 779 | S += this._collapseLink("x", tablex[y].index.slice(0, x)); 780 | } 781 | 782 | if (x === 0) { 783 | S += this.options.l_all; 784 | } else { 785 | S += this.fields[this.xfields[x - 1]].getStringValue(tablex[y].index[x - 1]); 786 | } 787 | S += "
0) { 1070 | m = 0; 1071 | while ((m < this.yfields.length) && (m < tabley[x].index.length) && (m < tabley[x - 1].index.length) && (tabley[x].index[m] === tabley[x - 1].index[m])) { 1072 | m++; 1073 | } 1074 | m = this.yfields.length - m; 1075 | } else { 1076 | m = this.xfields.length > this.yfields.length ? this.xfields.length : this.yfields.length; 1077 | m++; 1078 | } 1079 | 1080 | cls += " line_left_" + m; 1081 | return cls; 1082 | }, 1083 | _clsRightLine: function(tabley, x, span) { 1084 | if (typeof span === "undefined") { 1085 | span = 1; 1086 | } 1087 | 1088 | var cls = " "; 1089 | var m; 1090 | 1091 | if (x + span < tabley.length) { 1092 | m = 0; 1093 | while ((m < this.yfields.length) && (m < tabley[x].index.length) && (m < tabley[x + span].index.length) && (tabley[x].index[m] === tabley[x + span].index[m])) { 1094 | m++; 1095 | } 1096 | m = this.yfields.length - m; 1097 | } else { 1098 | m = this.xfields.length > this.yfields.length ? this.xfields.length : this.yfields.length; 1099 | m++; 1100 | } 1101 | 1102 | cls += " line_right_" + m; 1103 | 1104 | return cls; 1105 | }, 1106 | _clsTopLine: function(tablex, y, span) { 1107 | if (typeof span === "undefined") { 1108 | span = 1; 1109 | } 1110 | 1111 | var cls = " "; 1112 | var m; 1113 | 1114 | if (y > 0) { 1115 | m = 0; 1116 | while ((m < this.xfields.length) && (m < tablex[y].index.length) && (m < tablex[y - 1].index.length) && (tablex[y].index[m] === tablex[y - 1].index[m])) { 1117 | m++; 1118 | } 1119 | m = this.xfields.length - m; 1120 | } else { 1121 | m = this.xfields.length > this.yfields.length ? this.xfields.length : this.yfields.length; 1122 | m++; 1123 | } 1124 | 1125 | cls += " line_top_" + m; 1126 | return cls; 1127 | }, 1128 | _clsBottomLine: function(tablex, y, span) { 1129 | if (typeof span === "undefined") { 1130 | span = 1; 1131 | } 1132 | 1133 | var cls = " "; 1134 | var m; 1135 | if (y + span < tablex.length) { 1136 | m = 0; 1137 | while ((m < this.xfields.length) && (m < tablex[y].index.length) && (m < tablex[y + span].index.length) && (tablex[y].index[m] === tablex[y + span].index[m])) { 1138 | m++; 1139 | } 1140 | m = this.xfields.length - m; 1141 | } else { 1142 | m = this.xfields.length > this.yfields.length ? this.xfields.length : this.yfields.length; 1143 | m++; 1144 | } 1145 | 1146 | cls += " line_bottom_" + m; 1147 | 1148 | return cls; 1149 | }, 1150 | /* _clsGroupX: function (tablex, tabley, x, y) { 1151 | var cls = " "; 1152 | 1153 | return cls; 1154 | }, 1155 | _clsGroupY: function (tablex, tabley, x, y) { 1156 | var cls = " "; 1157 | 1158 | return cls; 1159 | }, 1160 | */ 1161 | _format: function(value, field) { 1162 | var V = null; 1163 | if (this.formatters[field] !== null) { 1164 | V = this.formatters[field].format(value, this.fieldNames[field]); 1165 | } 1166 | if ((typeof V === "undefined") || (V === null)) { 1167 | V = this.defaultFormatter.format(value, this.fieldNames[field]); 1168 | } 1169 | return V; 1170 | } 1171 | }); 1172 | });/* 1173 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 1174 | 1175 | This file is part of jbPivot. 1176 | 1177 | jbPivot is free software: you can redistribute it and/or modify 1178 | it under the terms of the GNU General Public License as published by 1179 | the Free Software Foundation, either version 3 of the License, or 1180 | (at your option) any later version. 1181 | 1182 | jbPivot is distributed in the hope that it will be useful, 1183 | but WITHOUT ANY WARRANTY; without even the implied warranty of 1184 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1185 | GNU General Public License for more details. 1186 | 1187 | You should have received a copy of the GNU General Public License 1188 | along with jbPivot. If not, see . 1189 | */ 1190 | 1191 | function grp_distinct(options) { 1192 | "use strict"; 1193 | var self = {}; 1194 | self.values = []; 1195 | self.names = {}; 1196 | self.fieldtype = "number"; 1197 | self.field = options.field; 1198 | if (typeof options.sort === "undefined") { 1199 | self.sort = "ASC"; 1200 | } else { 1201 | self.sort = options.sort.toUpperCase(); 1202 | } 1203 | if (typeof options.params !== "undefined") { 1204 | self.params = options.params; 1205 | } else { 1206 | self.params = null; 1207 | } 1208 | if (typeof options.showAll !== "undefined") { 1209 | self.showAll = options.showAll; 1210 | } else { 1211 | self.showAll = false; 1212 | } 1213 | 1214 | self.CalculateValue = function (R) { 1215 | var V = ""; 1216 | var res; 1217 | if (typeof R[this.field] === "function") { 1218 | V = R[this.field](this.params); 1219 | } else if (typeof R[this.field] === "number") { 1220 | V = R[this.field].toString(); 1221 | } else if (typeof R[this.field] === "string") { 1222 | V = R[this.field]; 1223 | this.fieldtype = "string"; 1224 | } 1225 | 1226 | if (typeof V !== "string") { 1227 | V = ""; 1228 | } 1229 | 1230 | if (typeof this.names[V] !== "undefined") { 1231 | res = this.names[V]; 1232 | } else { 1233 | res = this.values.push(V) - 1; 1234 | this.names[V] = res; 1235 | } 1236 | 1237 | return res; 1238 | }; 1239 | 1240 | self.getStringValue = function (idx) { 1241 | return this.values[idx]; 1242 | }; 1243 | 1244 | self.DisplayValues = function (UsedValues) { 1245 | var res; 1246 | var i; 1247 | 1248 | if (this.showAll) { 1249 | res = []; 1250 | for (i = 0; i < this.values.length; i++) { 1251 | res.push(i.toString()); 1252 | } 1253 | } else { 1254 | res = UsedValues.slice(0); 1255 | } 1256 | 1257 | var self = this; 1258 | 1259 | if (this.fieldtype === "string") { 1260 | res = res.sort(function (a, b) { 1261 | var res = 0; 1262 | if (self.values[a] < self.values[b]) { 1263 | res = -1; 1264 | } 1265 | if (self.values[a] > self.values[b]) { 1266 | res = 1; 1267 | } 1268 | return res; 1269 | }); 1270 | } else { 1271 | res = res.sort(function (a, b) { 1272 | var aa = parseFloat(self.values[a]); 1273 | var bb = parseFloat(self.values[b]); 1274 | var res = 0; 1275 | if (aa < bb) { 1276 | res = -1; 1277 | } 1278 | if (aa > bb) { 1279 | res = 1; 1280 | } 1281 | return res; 1282 | }); 1283 | } 1284 | 1285 | if (this.sort === "DESC") { 1286 | res = res.reverse(); 1287 | } 1288 | 1289 | return res; 1290 | }; 1291 | 1292 | return self; 1293 | } 1294 | 1295 | $.unc.plugins.addGrouper('distinct', grp_distinct);/* 1296 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 1297 | 1298 | This file is part of jbPivot. 1299 | 1300 | jbPivot is free software: you can redistribute it and/or modify 1301 | it under the terms of the GNU General Public License as published by 1302 | the Free Software Foundation, either version 3 of the License, or 1303 | (at your option) any later version. 1304 | 1305 | jbPivot is distributed in the hope that it will be useful, 1306 | but WITHOUT ANY WARRANTY; without even the implied warranty of 1307 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1308 | GNU General Public License for more details. 1309 | 1310 | You should have received a copy of the GNU General Public License 1311 | along with jbPivot. If not, see . 1312 | */ 1313 | 1314 | function agregate_average(options) { 1315 | "use strict"; 1316 | var self = {}; 1317 | self.options = $.extend({}, options); 1318 | self.agregate = function (a, b) { 1319 | var res; 1320 | if ((!a) || (a.type !== "agregate_average")) { 1321 | res = { 1322 | type: "agregate_average", 1323 | sum: 0, 1324 | count: 0 1325 | }; 1326 | } else { 1327 | res = { 1328 | type: "agregate_average", 1329 | sum: a.sum, 1330 | count: a.count 1331 | }; 1332 | } 1333 | if (b.type === "agregate_average") { 1334 | res.sum += b.sum; 1335 | res.count += b.count; 1336 | } else if (typeof b === "object") { 1337 | res.count++; 1338 | if (typeof b[this.options.field] === "number") { 1339 | res.sum += b[this.options.field]; 1340 | } else if (typeof b[this.options.field] === "string") { 1341 | try { 1342 | res.sum += parseInt(b[this.options.field], 10); 1343 | } catch (err) { 1344 | 1345 | } 1346 | } 1347 | } 1348 | return res; 1349 | }; 1350 | 1351 | self.getValue = function (a) { 1352 | var res = null; 1353 | if ((a) && (a.type === "agregate_average") && (a.count > 0)) { 1354 | var v = a.sum / a.count; 1355 | res = v; 1356 | } 1357 | return res; 1358 | }; 1359 | return self; 1360 | } 1361 | 1362 | $.unc.plugins.addAgregate('average', agregate_average);/* 1363 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 1364 | 1365 | This file is part of jbPivot. 1366 | 1367 | jbPivot is free software: you can redistribute it and/or modify 1368 | it under the terms of the GNU General Public License as published by 1369 | the Free Software Foundation, either version 3 of the License, or 1370 | (at your option) any later version. 1371 | 1372 | jbPivot is distributed in the hope that it will be useful, 1373 | but WITHOUT ANY WARRANTY; without even the implied warranty of 1374 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1375 | GNU General Public License for more details. 1376 | 1377 | You should have received a copy of the GNU General Public License 1378 | along with jbPivot. If not, see . 1379 | */ 1380 | 1381 | function agregate_count() { 1382 | "use strict"; 1383 | var self = {}; 1384 | self.agregate = function (a, b) { 1385 | var res; 1386 | if ((!a) || (a.type !== "agregate_count")) { 1387 | res = { 1388 | type: "agregate_count", 1389 | count: 0 1390 | }; 1391 | } else { 1392 | res = { 1393 | type: "agregate_count", 1394 | count: a.count 1395 | }; 1396 | } 1397 | if (b.type === "agregate_count") { 1398 | res.count += b.count; 1399 | } else if (typeof b === "object") { 1400 | res.count++; 1401 | } 1402 | return res; 1403 | }; 1404 | 1405 | self.getValue = function (a) { 1406 | var res = null; 1407 | if ((a) && (a.type === "agregate_count")) { 1408 | res = a.count; 1409 | } 1410 | return res; 1411 | }; 1412 | return self; 1413 | } 1414 | 1415 | $.unc.plugins.addAgregate('count', agregate_count);/* 1416 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 1417 | 1418 | This file is part of jbPivot. 1419 | 1420 | jbPivot is free software: you can redistribute it and/or modify 1421 | it under the terms of the GNU General Public License as published by 1422 | the Free Software Foundation, either version 3 of the License, or 1423 | (at your option) any later version. 1424 | 1425 | jbPivot is distributed in the hope that it will be useful, 1426 | but WITHOUT ANY WARRANTY; without even the implied warranty of 1427 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1428 | GNU General Public License for more details. 1429 | 1430 | You should have received a copy of the GNU General Public License 1431 | along with jbPivot. If not, see . 1432 | */ 1433 | 1434 | function agregate_distinct(options) { 1435 | "use strict"; 1436 | var self = {}; 1437 | self.field = options.field; 1438 | self.agregate = function (a, b) { 1439 | var res = { 1440 | type: "fa_distinct" 1441 | }; 1442 | if ((!a) || (a.type !== "fa_distinct")) { 1443 | res.repeated = false; 1444 | if (b.type === "fa_distinct") { 1445 | res.val = b.val; 1446 | } else if (typeof b === "object") { 1447 | res.repeated = false; 1448 | if ((typeof b[this.field] === "number") || (typeof b[this.field] === "string")) { 1449 | res.val = b[this.field]; 1450 | } else { 1451 | res.val = null; 1452 | } 1453 | } else { 1454 | res.val = null; 1455 | } 1456 | } else { 1457 | if (b.type === "fa_distinct") { 1458 | res.repeated = (a.repeated || b.repeated || (a.val !== b.val)); 1459 | res.val = a.val; 1460 | } else if (typeof b === "object") { 1461 | if ((typeof b[this.field] === "number") || (typeof b[this.field] === "string")) { 1462 | res.repeated = (a.repeated || (a.val !== b[this.field])); 1463 | res.val = a.val; 1464 | } else { 1465 | res.repeated = (a.repeated || (a.val !== null)); 1466 | res.val = null; 1467 | } 1468 | } else { 1469 | res.repeated = (a.repeated || (a.val !== null)); 1470 | res.val = null; 1471 | } 1472 | } 1473 | 1474 | return res; 1475 | }; 1476 | 1477 | self.getValue = function (a) { 1478 | var res = null; 1479 | if ((a) && (a.type === "fa_distinct")) { 1480 | if (a.repeated) { 1481 | res = "*"; 1482 | } else { 1483 | res = a.val; 1484 | } 1485 | } 1486 | return res; 1487 | }; 1488 | return self; 1489 | } 1490 | 1491 | $.unc.plugins.addAgregate('distinct', agregate_distinct);/* 1492 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 1493 | 1494 | This file is part of jbPivot. 1495 | 1496 | jbPivot is free software: you can redistribute it and/or modify 1497 | it under the terms of the GNU General Public License as published by 1498 | the Free Software Foundation, either version 3 of the License, or 1499 | (at your option) any later version. 1500 | 1501 | jbPivot is distributed in the hope that it will be useful, 1502 | but WITHOUT ANY WARRANTY; without even the implied warranty of 1503 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1504 | GNU General Public License for more details. 1505 | 1506 | You should have received a copy of the GNU General Public License 1507 | along with jbPivot. If not, see . 1508 | */ 1509 | 1510 | function agregate_sum(options) { 1511 | "use strict"; 1512 | var self = {}; 1513 | self.field = options.field; 1514 | self.agregate = function (a, b) { 1515 | var res; 1516 | if ((!a) || (a.type !== "agregate_sum")) { 1517 | res = { 1518 | type: "agregate_sum", 1519 | sum: 0 1520 | }; 1521 | } else { 1522 | res = { 1523 | type: "agregate_sum", 1524 | sum: a.sum 1525 | }; 1526 | } 1527 | if (b.type === "agregate_sum") { 1528 | res.sum += b.sum; 1529 | } else if (typeof b === "object") { 1530 | if (typeof b[this.field] === "number") { 1531 | res.sum += b[this.field]; 1532 | } else if (typeof b[this.field] === "string") { 1533 | try { 1534 | res.sum += parseInt(b[this.field],10); 1535 | } catch (err) { 1536 | 1537 | } 1538 | } 1539 | } 1540 | return res; 1541 | }; 1542 | 1543 | self.getValue = function (a) { 1544 | var res = null; 1545 | if ((a) && (a.type === "agregate_sum")) { 1546 | res = a.sum; 1547 | } 1548 | return res; 1549 | }; 1550 | return self; 1551 | } 1552 | 1553 | $.unc.plugins.addAgregate('sum', agregate_sum);/* 1554 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 1555 | 1556 | This file is part of jbPivot. 1557 | 1558 | jbPivot is free software: you can redistribute it and/or modify 1559 | it under the terms of the GNU General Public License as published by 1560 | the Free Software Foundation, either version 3 of the License, or 1561 | (at your option) any later version. 1562 | 1563 | jbPivot is distributed in the hope that it will be useful, 1564 | but WITHOUT ANY WARRANTY; without even the implied warranty of 1565 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1566 | GNU General Public License for more details. 1567 | 1568 | You should have received a copy of the GNU General Public License 1569 | along with jbPivot. If not, see . 1570 | */ 1571 | 1572 | function formatter_default() { 1573 | "use strict"; 1574 | var self = {}; 1575 | self.format = function (value) { 1576 | var V = ""; 1577 | try { 1578 | V = value.toString(); 1579 | } catch (Error) { 1580 | 1581 | } 1582 | return V; 1583 | }; 1584 | return self; 1585 | } 1586 | 1587 | $.unc.plugins.addFormatter('default', formatter_default); -------------------------------------------------------------------------------- /build/jbPivot.min.js: -------------------------------------------------------------------------------- 1 | $.unc={plugins:{agregates:{},addAgregate:function(b,a){this.agregates[b]=a},groupers:{},addGrouper:function(b,a){this.groupers[b]=a},formatters:{},addFormatter:function(b,a){this.formatters[b]=a}}};$(function(){$.widget("unc.jbPivot",{options:{fields:{},summary:true,copyright:true,formatter:"default",l_all:"All",l_unused_fields:"Unused fields"},_create:function(){this.CollapsedNodes={};this.renderPending=false;this.reset();if(typeof this.options.data!=="undefined"){this.insertRecords(this.options.data)}var a=this;$(this.element).on("click",".collapse_button",function(b){b.preventDefault();a._togleCollapse(this.rel)});$(this.element).on("dragstart",".draggable",function(b){a.pre_post="";a.dragcls="";a.dragdata=$(this).attr("rel");b.originalEvent.dataTransfer.effectAllowed="move";b.originalEvent.dataTransfer.setData("Text",$(this).attr("rel"));$(".pivot").addClass("drag_in_progress")});$(this.element).on("dragleave",".dropable",function(e){var f=$(this);var b=f.attr("class").match(/\s+(target(X|Y|Z|U)[\d]+)($|\s)/);var c="."+b[1];var d=a.element;setTimeout(function(){$(c,d).removeClass("dropping_pre");$(c,d).removeClass("dropping_post");a.pre_post="";a.dragcls=""},0);e.stopPropagation();e.preventDefault();return false});$(this.element).on("dragover",".dropable",function(d){var k=$(this);var b=$(this).offset();var h=d.originalEvent.pageX-b.left;var g=d.originalEvent.pageY-b.top;var i=k.attr("class").match(/\s+(target(X|Y|Z|U)([\d]+))($|\s)/);i[3]=parseInt(i[3],10);var n="."+i[1];var f;var c=a.pre_post;var j=a.dragcls;if((i[2]==="Y")||(i[2]==="U")){f=g>k.height()/2?"post":"pre"}else{f=h>k.width()/2?"post":"pre"}if(i[3]===0){f="post"}var m=a.dragdata;var l=$(this).attr("rel");if(a._canMove(m,l,f)){var e=a.element;if((c!==f)||(n!==j)){$(n,e).removeClass("dropping_pre");$(n,e).removeClass("dropping_post");setTimeout(function(){$(n,e).addClass("dropping_"+f);a.pre_post=f;a.dragcls=n},0)}d.originalEvent.dataTransfer.dropEffect="move";d.stopPropagation();d.preventDefault();return false}});$(this.element).on("drop",".dropable",function(c){var g=$(this);var b=$(this).offset();var e=c.originalEvent.pageX-b.left;var d=c.originalEvent.pageY-b.top;var f=g.attr("class").match(/\s+(target(X|Y|Z|U)([\d]+))($|\s)/);f[3]=parseInt(f[3],10);var j;if((f[2]==="Y")||(f[2]==="U")){j=d>g.height()/2?"post":"pre"}else{j=e>g.width()/2?"post":"pre"}if(f[3]===0){j="post"}var i=c.originalEvent.dataTransfer.getData("Text");var h=$(this).attr("rel");a._moveField(i,h,j);c.preventDefault();return false});$(this.element).on("dragend",".dropable",function(){var b=a.element;$(".pivot",b).removeClass("drag_in_progress")})},reset:function(){this.fields=[];this.afields=[];this.xfields=[];this.yfields=[];this.zfields=[];this.ufields=[];this.fieldNames=[];this.fieldLabels=[];this.formatters=[];if((typeof this.options.formatter==="undefined")||(this.options.formatter===null)){this.options.formatter="default"}if(typeof this.options.formatter==="string"){if(typeof $.unc.plugins.formatters[this.options.formatter]!=="function"){throw ("Formatter: "+this.options.formatter+" is not defined")}this.defaultFormatter=$.unc.plugins.formatters[this.options.formatter](this.options)}else{if(typeof this.options.formatter==="function"){this.defaultFormatter={format:this.options.formatter}}else{throw ("Invalid formatter")}}if(this.options.formatter===null){throw ("Formatter not defined")}var h;var b=0;var g={};for(h in this.options.fields){if(this.options.fields.hasOwnProperty(h)){var d=$.extend({agregateType:"distinct",groupType:"distinct",label:h,formatter:null},this.options.fields[h]);if(d.groupType!=="none"){if(typeof $.unc.plugins.groupers[d.groupType]!=="function"){throw ("Grouper: "+d.groupType+" is not defined")}this.fields.push($.unc.plugins.groupers[d.groupType](d))}else{this.fields.push(null)}if(d.agregateType!=="none"){if(typeof $.unc.plugins.agregates[d.agregateType]!=="function"){throw ("Grouper: "+d.agregateType+" is not defined")}this.afields.push($.unc.plugins.agregates[d.agregateType](d))}else{this.afields.push(null)}if(typeof d.formatter==="string"){if(typeof $.unc.plugins.formatters[d.formatter]!=="function"){throw ("Formatter"+d.formatter+" is not defined")}this.formatters.push($.unc.plugins.formatters[d.formatter](d))}else{if(typeof d.formatter==="function"){this.formatters.push({format:d.formatter})}else{this.formatters.push(null)}}g[h]=b;b++;this.fieldNames.push(h);this.fieldLabels.push(d.label)}}var c,e;for(c=0;c';a+=this._isCollapsed(b,c)?"+":"-";a+="";return a},_renderHtml:function(){var a,m,d,j,h,g,n;var l=this.xfields.length>this.yfields.length?this.xfields.length:this.yfields.length;l++;var f=[{index:[],cells:{}}];this._tree2table("x",this.xtree,f);var e=[{index:[],cells:{}}];this._tree2table("y",this.ytree,e);var c="";c+="";for(d=0;d"}c+="
"+this.options.l_unused_fields+"
";c+='';c+="";c+='";c+="\n";for(h=1;h<=this.yfields.length;h++){c+="";for(j=0;j0?this.zfields.length:1);c+=' colspan="'+a+'"';c+=' rowspan="'+e[j].cells[h].spanx+'"';c+=">";if(h"}}c+="\n"}c+="";for(j=0;j"}if(this.zfields.length===0){c+="1?' colspan="'+f[h].cells[j].spanx+'"':"";c+=f[h].cells[j].spany>1?' rowspan="'+f[h].cells[j].spany+'"':"";m="lefttitle dropable";if(j>0){m+=" draggable"}if(j===0){m+=" line_left_"+l}m+=this._clsTopLine(f,h,f[h].cells[j].spany);m+=this._clsBottomLine(f,h,f[h].cells[j].spany);m+=" targetX"+j;c+=' class="'+m+'"';c+='"';c+=' rel="X,'+j+'"';if(j>0){c+=' draggable="true"'}c+=">";if(j"}}for(j=0;j"}if(this.zfields.length===0){c+="0)){c+="";c+=""}var k=1+this.xfields.length+e.length*this.zfields.length;c+="
0?this.zfields.length:1);c+="0){c+=this._collapseLink("y",[])}c+=this.options.l_all;c+="
"}}c+="
0){a=0;while((athis.yfields.length?this.xfields.length:this.yfields.length;a++}c+=" line_left_"+a;return c},_clsRightLine:function(e,b,d){if(typeof d==="undefined"){d=1}var c=" ";var a;if(b+dthis.yfields.length?this.xfields.length:this.yfields.length;a++}c+=" line_right_"+a;return c},_clsTopLine:function(e,d,c){if(typeof c==="undefined"){c=1}var b=" ";var a;if(d>0){a=0;while((athis.yfields.length?this.xfields.length:this.yfields.length;a++}b+=" line_top_"+a;return b},_clsBottomLine:function(e,d,c){if(typeof c==="undefined"){c=1}var b=" ";var a;if(d+cthis.yfields.length?this.xfields.length:this.yfields.length;a++}b+=" line_bottom_"+a;return b},_format:function(b,c){var a=null;if(this.formatters[c]!==null){a=this.formatters[c].format(b,this.fieldNames[c])}if((typeof a==="undefined")||(a===null)){a=this.defaultFormatter.format(b,this.fieldNames[c])}return a}})});function grp_distinct(b){var a={};a.values=[];a.names={};a.fieldtype="number";a.field=b.field;if(typeof b.sort==="undefined"){a.sort="ASC"}else{a.sort=b.sort.toUpperCase()}if(typeof b.params!=="undefined"){a.params=b.params}else{a.params=null}if(typeof b.showAll!=="undefined"){a.showAll=b.showAll}else{a.showAll=false}a.CalculateValue=function(e){var c="";var d;if(typeof e[this.field]==="function"){c=e[this.field](this.params)}else{if(typeof e[this.field]==="number"){c=e[this.field].toString()}else{if(typeof e[this.field]==="string"){c=e[this.field];this.fieldtype="string"}}}if(typeof c!=="string"){c=""}if(typeof this.names[c]!=="undefined"){d=this.names[c]}else{d=this.values.push(c)-1;this.names[c]=d}return d};a.getStringValue=function(c){return this.values[c]};a.DisplayValues=function(f){var e;var d;if(this.showAll){e=[];for(d=0;dc.values[g]){i=1}return i})}else{e=e.sort(function(h,g){var j=parseFloat(c.values[h]);var k=parseFloat(c.values[g]);var i=0;if(jk){i=1}return i})}if(this.sort==="DESC"){e=e.reverse()}return e};return a}$.unc.plugins.addGrouper("distinct",grp_distinct);function agregate_average(b){var a={};a.options=$.extend({},b);a.agregate=function(d,c){var e;if((!d)||(d.type!=="agregate_average")){e={type:"agregate_average",sum:0,count:0}}else{e={type:"agregate_average",sum:d.sum,count:d.count}}if(c.type==="agregate_average"){e.sum+=c.sum;e.count+=c.count}else{if(typeof c==="object"){e.count++;if(typeof c[this.options.field]==="number"){e.sum+=c[this.options.field]}else{if(typeof c[this.options.field]==="string"){try{e.sum+=parseInt(c[this.options.field],10)}catch(f){}}}}}return e};a.getValue=function(c){var e=null;if((c)&&(c.type==="agregate_average")&&(c.count>0)){var d=c.sum/c.count;e=d}return e};return a}$.unc.plugins.addAgregate("average",agregate_average);function agregate_count(){var a={};a.agregate=function(d,c){var e;if((!d)||(d.type!=="agregate_count")){e={type:"agregate_count",count:0}}else{e={type:"agregate_count",count:d.count}}if(c.type==="agregate_count"){e.count+=c.count}else{if(typeof c==="object"){e.count++}}return e};a.getValue=function(b){var c=null;if((b)&&(b.type==="agregate_count")){c=b.count}return c};return a}$.unc.plugins.addAgregate("count",agregate_count);function agregate_distinct(b){var a={};a.field=b.field;a.agregate=function(d,c){var e={type:"fa_distinct"};if((!d)||(d.type!=="fa_distinct")){e.repeated=false;if(c.type==="fa_distinct"){e.val=c.val}else{if(typeof c==="object"){e.repeated=false;if((typeof c[this.field]==="number")||(typeof c[this.field]==="string")){e.val=c[this.field]}else{e.val=null}}else{e.val=null}}}else{if(c.type==="fa_distinct"){e.repeated=(d.repeated||c.repeated||(d.val!==c.val));e.val=d.val}else{if(typeof c==="object"){if((typeof c[this.field]==="number")||(typeof c[this.field]==="string")){e.repeated=(d.repeated||(d.val!==c[this.field]));e.val=d.val}else{e.repeated=(d.repeated||(d.val!==null));e.val=null}}else{e.repeated=(d.repeated||(d.val!==null));e.val=null}}}return e};a.getValue=function(c){var d=null;if((c)&&(c.type==="fa_distinct")){if(c.repeated){d="*"}else{d=c.val}}return d};return a}$.unc.plugins.addAgregate("distinct",agregate_distinct);function agregate_sum(b){var a={};a.field=b.field;a.agregate=function(d,c){var e;if((!d)||(d.type!=="agregate_sum")){e={type:"agregate_sum",sum:0}}else{e={type:"agregate_sum",sum:d.sum}}if(c.type==="agregate_sum"){e.sum+=c.sum}else{if(typeof c==="object"){if(typeof c[this.field]==="number"){e.sum+=c[this.field]}else{if(typeof c[this.field]==="string"){try{e.sum+=parseInt(c[this.field],10)}catch(f){}}}}}return e};a.getValue=function(c){var d=null;if((c)&&(c.type==="agregate_sum")){d=c.sum}return d};return a}$.unc.plugins.addAgregate("sum",agregate_sum);function formatter_default(){var a={};a.format=function(c){var b="";try{b=c.toString()}catch(d){}return b};return a}$.unc.plugins.addFormatter("default",formatter_default); -------------------------------------------------------------------------------- /css/jbPivot.css: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 3 | 4 | This file is part of jbPivot. 5 | 6 | jbPivot is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | jbPivot is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with jbPivot. If not, see . 18 | */ 19 | 20 | body 21 | { 22 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 23 | font-size: 14px; 24 | } 25 | 26 | .pivot{ 27 | display:table; 28 | border-collapse:collapse; 29 | border-spacing: 0px; 30 | border: solid 0px; 31 | } 32 | 33 | 34 | .unused_fields{ 35 | display:table; 36 | border-spacing: 0px; 37 | border: solid 1px; 38 | margin-right: 15px; 39 | float: left; 40 | border-color: #bbb; 41 | } 42 | 43 | .unused_fields th { 44 | display: table-cell; 45 | border:solid 0px; 46 | padding: 5px 9px 5px; 47 | /*background-color: #777;*/ 48 | color: white; 49 | border-bottom-color: #bbb; 50 | border-bottom-width: 1px; 51 | background: #969da5; /* Old browsers */ 52 | background: -moz-linear-gradient(top, #969da5 0%, #28343b 80%); /* FF3.6+ */ 53 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#969da5), color-stop(80%,#28343b)); /* Chrome,Safari4+ */ 54 | background: -webkit-linear-gradient(top, #969da5 0%,#28343b 80%); /* Chrome10+,Safari5.1+ */ 55 | background: -o-linear-gradient(top, #969da5 0%,#28343b 80%); /* Opera 11.10+ */ 56 | background: -ms-linear-gradient(top, #969da5 0%,#28343b 80%); /* IE10+ */ 57 | background: linear-gradient(to bottom, #969da5 0%,#28343b 80%); /* W3C */ 58 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#969da5', endColorstr='#28343b',GradientType=0 ); /* IE6-9 */ 59 | } 60 | 61 | .unused_fields td { 62 | display: table-cell; 63 | border:solid 0px; 64 | padding: 5px 9px 5px; 65 | background-color: #f9f9f9; 66 | background: -moz-linear-gradient(top, #ffffff 0%, #f9f9f9 11%, #ededed 100%); 67 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(11%,#f9f9f9), color-stop(100%,#ededed)); 68 | background: -webkit-linear-gradient(top, #ffffff 0%,#f9f9f9 11%,#ededed 100%); 69 | background: -o-linear-gradient(top, #ffffff 0%,#f9f9f9 11%,#ededed 100%); 70 | background: -ms-linear-gradient(top, #ffffff 0%,#f9f9f9 11%,#ededed 100%); 71 | background: linear-gradient(to bottom, #ffffff 0%,#f9f9f9 11%,#ededed 100%); 72 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ededed',GradientType=0 ); 73 | } 74 | 75 | 76 | .pivot td,th { 77 | display: table-cell; 78 | border:solid 0px; 79 | padding: 5px 7px 5px; 80 | } 81 | 82 | .pivot td { 83 | text-align: center; 84 | background-color: white; 85 | } 86 | 87 | .pivot .lefttitle { 88 | text-align: left; 89 | border: 1px solid #ddd; 90 | background-color: #f9f9f9; 91 | background: -moz-linear-gradient(top, #ffffff 0%, #f9f9f9 11%, #ededed 100%); 92 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(11%,#f9f9f9), color-stop(100%,#ededed)); 93 | background: -webkit-linear-gradient(top, #ffffff 0%,#f9f9f9 11%,#ededed 100%); 94 | background: -o-linear-gradient(top, #ffffff 0%,#f9f9f9 11%,#ededed 100%); 95 | background: -ms-linear-gradient(top, #ffffff 0%,#f9f9f9 11%,#ededed 100%); 96 | background: linear-gradient(to bottom, #ffffff 0%,#f9f9f9 11%,#ededed 100%); 97 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ededed',GradientType=0 ); 98 | } 99 | 100 | .pivot .toptitle { 101 | text-align: center; 102 | padding: 5px 10px 5px; 103 | background-color: #f9f9f9; 104 | background: -moz-linear-gradient(top, #ffffff 0%, #e5e5e5 100%); 105 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#e5e5e5)); 106 | background: -webkit-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); 107 | background: -o-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); 108 | background: -ms-linear-gradient(top, #ffffff 0%,#e5e5e5 100%); 109 | background: linear-gradient(to bottom, #ffffff 0%,#e5e5e5 100%); 110 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#e5e5e5',GradientType=0 ); 111 | } 112 | 113 | .pivot .ztitle { 114 | text-align: center; 115 | padding: 5px 10px 5px; 116 | background-color: #999; 117 | color: white; 118 | background: #c5deea; 119 | background: #c5deea; /* Old browsers */ 120 | background: -moz-linear-gradient(top, #c5deea 0%, #8abbd7 3%, #066dab 100%); /* FF3.6+ */ 121 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#c5deea), color-stop(3%,#8abbd7), color-stop(100%,#066dab)); /* Chrome,Safari4+ */ 122 | background: -webkit-linear-gradient(top, #c5deea 0%,#8abbd7 3%,#066dab 100%); /* Chrome10+,Safari5.1+ */ 123 | background: -o-linear-gradient(top, #c5deea 0%,#8abbd7 3%,#066dab 100%); /* Opera 11.10+ */ 124 | background: -ms-linear-gradient(top, #c5deea 0%,#8abbd7 3%,#066dab 100%); /* IE10+ */ 125 | background: linear-gradient(to bottom, #c5deea 0%,#8abbd7 3%,#066dab 100%); /* W3C */ 126 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#c5deea', endColorstr='#066dab',GradientType=0 ); /* IE6-9 */ 127 | } 128 | 129 | .pivot .summary { 130 | text-align: center; 131 | /*background-color: #777;*/ 132 | color: white; 133 | background: #cedce7; 134 | background: -moz-linear-gradient(top, #cedce7 0%, #596a72 100%); 135 | background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#cedce7), color-stop(100%,#596a72)); 136 | background: -webkit-linear-gradient(top, #cedce7 0%,#596a72 100%); 137 | background: -o-linear-gradient(top, #cedce7 0%,#596a72 100%); 138 | background: -ms-linear-gradient(top, #cedce7 0%,#596a72 100%); 139 | background: linear-gradient(to bottom, #cedce7 0%,#596a72 100%); 140 | filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#cedce7', endColorstr='#596a72',GradientType=0 ); 141 | } 142 | 143 | .pivot .copyright { 144 | font-size: x-small; 145 | border-size:0px; 146 | text-align: right; 147 | vertical-align: middle; 148 | height: 15px; 149 | padding: 2px; 150 | } 151 | 152 | .pivot .copyright img { 153 | height: 12px; 154 | width: auto; 155 | padding-left:5px; 156 | float: right; 157 | } 158 | 159 | 160 | .pivot .toptitle.dropping_pre { 161 | border-top-width: 5px; 162 | border-top-color: rgb(255,0,0); 163 | } 164 | 165 | .pivot .toptitle.dropping_post { 166 | border-bottom-width: 5px; 167 | border-bottom-color: rgb(255,0,0); 168 | } 169 | 170 | .pivot .lefttitle.dropping_pre { 171 | border-left-width: 5px; 172 | border-left-color: rgb(255,0,0); 173 | } 174 | 175 | .pivot .lefttitle.dropping_post { 176 | border-right-width: 5px; 177 | border-right-color: rgb(255,0,0); 178 | } 179 | 180 | .pivot .ztitle.dropping_pre { 181 | border-left-width: 5px; 182 | border-left-color: rgb(255,0,0); 183 | } 184 | 185 | .pivot .ztitle.dropping_post { 186 | border-right-width: 5px; 187 | border-right-color: rgb(255,0,0); 188 | } 189 | 190 | .unused_fields .unused_field.dropping_pre { 191 | border-top-width: 5px; 192 | border-top-color: rgb(255,0,0); 193 | } 194 | 195 | .unused_fields .unused_field.dropping_post { 196 | border-bottom-width: 5px; 197 | border-bottom-color: rgb(255,0,0); 198 | dropping_post} 199 | 200 | .pivot .draggable { 201 | cursor: move; 202 | } 203 | 204 | .pivot.drag_in_progress th>* { 205 | pointer-events:none; 206 | backgroun-color: #FF0000; 207 | } 208 | 209 | 210 | .pivot .collapse_button { 211 | background: #4479BA; 212 | padding: 1px 7px 2px; 213 | color: #FFF; 214 | text-decoration: none; 215 | margin-right: 5px; 216 | margin-top: 0 !important; 217 | font: bold 12px Arial; 218 | height: 1.2em; 219 | /*border-radius: 20px; 220 | -moz-box-shadow: 2px 2px 4px 1px #ccc; 221 | -webkit-box-shadow: 2px 2px 4px 1px #ccc; 222 | box-shadow: 2px 2px 4px 1px #ccc;*/ 223 | border-radius: 2px; 224 | } 225 | 226 | .pivot .bordermark { 227 | border-left-width: 5px; 228 | border-right-width: 5px; 229 | border-bottom-width: 0px; 230 | border-left-color: rgba(0,231,0,0); 231 | border-right-color: rgba(0,231,0,0); 232 | border-bottom-color: rgba(0,231,0,0); 233 | } 234 | 235 | .pivot .lefttitle .collapse_button { 236 | float: left; 237 | } 238 | 239 | .pivot .line_top_0 { 240 | border-top-width: 0px; 241 | } 242 | 243 | .pivot .line_top_1 { 244 | border-top-width: 1px; 245 | border-top-color: #eee; 246 | } 247 | 248 | .pivot .line_top_2 { 249 | border-top-width: 1px; 250 | border-top-color: #ddd; 251 | } 252 | 253 | .pivot .line_top_3 { 254 | border-top-width: 1px; 255 | border-top-color: #ccc; 256 | } 257 | 258 | .pivot .line_top_4 { 259 | border-top-width: 1px; 260 | border-top-color: #bbb; 261 | } 262 | 263 | .pivot .line_top_5 { 264 | border-top-width: 1px; 265 | border-top-color: #aaa; 266 | } 267 | 268 | .pivot .line_top_6 { 269 | border-top-width: 2px; 270 | border-top-color: #999; 271 | } 272 | 273 | .pivot .line_top_7 { 274 | border-top-width: 2px; 275 | border-top-color: #888; 276 | } 277 | 278 | .pivot .line_top_8 { 279 | border-top-width: 2px; 280 | border-top-color: #777; 281 | } 282 | 283 | .pivot .line_top_9 { 284 | border-top-width: 2px; 285 | border-top-color: #666; 286 | } 287 | 288 | .pivot .line_top_10 { 289 | border-top-width: 2px; 290 | border-top-color: #555; 291 | } 292 | 293 | 294 | 295 | .pivot .line_bottom_0 { 296 | border-bottom-width: 0px; 297 | } 298 | 299 | .pivot .line_bottom_1 { 300 | border-bottom-width: 1px; 301 | border-bottom-color: #eee; 302 | } 303 | 304 | .pivot .line_bottom_2 { 305 | border-bottom-width: 1px; 306 | border-bottom-color: #ddd; 307 | } 308 | 309 | .pivot .line_bottom_3 { 310 | border-bottom-width: 1px; 311 | border-bottom-color: #ccc; 312 | } 313 | 314 | .pivot .line_bottom_4 { 315 | border-bottom-width: 1px; 316 | border-bottom-color: #bbb; 317 | } 318 | 319 | .pivot .line_bottom_5 { 320 | border-bottom-width: 1px; 321 | border-bottom-color: #aaa; 322 | } 323 | 324 | .pivot .line_bottom_6 { 325 | border-bottom-width: 2px; 326 | border-bottom-color: #999; 327 | } 328 | 329 | .pivot .line_bottom_7 { 330 | border-bottom-width: 2px; 331 | border-bottom-color: #888; 332 | } 333 | 334 | .pivot .line_bottom_8 { 335 | border-bottom-width: 2px; 336 | border-bottom-color: #777; 337 | } 338 | 339 | .pivot .line_bottom_9 { 340 | border-bottom-width: 2px; 341 | border-bottom-color: #666; 342 | } 343 | 344 | .pivot .line_bottom_10 { 345 | border-bottom-width: 2px; 346 | border-bottom-color: #555; 347 | } 348 | 349 | 350 | 351 | .pivot .line_left_0 { 352 | border-left-width: 1px; 353 | border-left-color: #eee; 354 | } 355 | .pivot .line_left_1 { 356 | border-left-width: 1px; 357 | border-left-color: #eee; 358 | } 359 | .pivot .line_left_2 { 360 | border-left-width: 1px; 361 | border-left-color: #ddd; 362 | } 363 | .pivot .line_left_3 { 364 | border-left-width: 1px; 365 | border-left-color: #ccc; 366 | } 367 | .pivot .line_left_4 { 368 | border-left-width: 1px; 369 | border-left-color: #bbb; 370 | } 371 | .pivot .line_left_5 { 372 | border-left-width: 1px; 373 | border-left-color: #aaa; 374 | } 375 | .pivot .line_left_6 { 376 | border-left-width: 2px; 377 | border-left-color: #999; 378 | } 379 | .pivot .line_left_7 { 380 | border-left-width: 2px; 381 | border-left-color: #888; 382 | } 383 | .pivot .line_left_8 { 384 | border-left-width: 2px; 385 | border-left-color: #777; 386 | } 387 | .pivot .line_left_9 { 388 | border-left-width: 2px; 389 | border-left-color: #666; 390 | } 391 | .pivot .line_left_10 { 392 | border-left-width: 2px; 393 | border-left-color: #555; 394 | } 395 | 396 | 397 | .pivot .line_right_0 { 398 | border-right-width: 1px; 399 | border-right-color: #eee; 400 | } 401 | .pivot .line_right_1 { 402 | border-right-width: 1px; 403 | border-right-color: #eee; 404 | } 405 | .pivot .line_right_2 { 406 | border-right-width: 1px; 407 | border-right-color: #ddd; 408 | } 409 | .pivot .line_right_3 { 410 | border-right-width: 1px; 411 | border-right-color: #ccc; 412 | } 413 | .pivot .line_right_4 { 414 | border-right-width: 1px; 415 | border-right-color: #bbb; 416 | } 417 | .pivot .line_right_5 { 418 | border-right-width: 1px; 419 | border-right-color: #aaa; 420 | } 421 | .pivot .line_right_6 { 422 | border-right-width: 2px; 423 | border-right-color: #999; 424 | } 425 | .pivot .line_right_7 { 426 | border-right-width: 2px; 427 | border-right-color: #888; 428 | } 429 | .pivot .line_right_8 { 430 | border-right-width: 2px; 431 | border-right-color: #777; 432 | } 433 | .pivot .line_right_9 { 434 | border-right-width: 2px; 435 | border-right-color: #666; 436 | } 437 | .pivot .line_right_10 { 438 | border-right-width: 2px; 439 | border-right-color: #555; 440 | } 441 | 442 | -------------------------------------------------------------------------------- /dobuild: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright 2013 Uniclau S.L. (www.uniclau.com) 3 | # 4 | # This file is part of jbPivot. 5 | # 6 | # jbPivot is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # jbPivot is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with jbPivot. If not, see . 18 | 19 | rm build/* 20 | cat src/pivot.js src/group_*.js src/agregate_*.js src/formatter_*.js > build/jbpivot.js 21 | cat css/*.css > build/jbpivot.css 22 | java -jar ~/git/yuicompressor-2.4.7/build/yuicompressor-2.4.7.jar build/jbPivot.js -o build/jbpivot.min.js 23 | java -jar ~/git/yuicompressor-2.4.7/build/yuicompressor-2.4.7.jar build/jbPivot.css -o build/jbpivot.min.css 24 | 25 | -------------------------------------------------------------------------------- /jbPivot.jquery.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jbPivot", 3 | "title": "jQuery jbPivot", 4 | "description": "A simple pivot table jQuery widget", 5 | "keywords": [ 6 | "table", 7 | "grid", 8 | "pivot", 9 | "grouping", 10 | "analyze", 11 | "agregate"], 12 | "version": "0.1.0", 13 | "author": { 14 | "name": "Jordi Baylina", 15 | "email": "baylina@uniclau.com", 16 | "url": "http://www.jbpivot.org" 17 | }, 18 | "maintainers": [ 19 | { 20 | "name": "Jordi Baylina", 21 | "email": "baylina@uniclau.com", 22 | "url": "http://www.jbpivot.org" 23 | }, 24 | { 25 | "name": "Jordi Moraleda", 26 | "email": "moraleda@uniclau.com", 27 | "url": "http://www.uniclau.com" 28 | } 29 | ], 30 | "licenses": [ 31 | { 32 | "type": "GPLv3", 33 | "url": "http://www.gnu.org/licenses/gpl.html" 34 | } 35 | ], 36 | "dependencies": { 37 | "jquery": ">=1.4" 38 | }, 39 | "bugs": "https://github.com/uniclau/jbPivot/issues", 40 | "homepage": "http://www.jbpivot.org", 41 | "docs": "https://github.com/uniclau/jbPivot/blob/master/README.md", 42 | "demo": "http://www.jbpivot.org" 43 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jbpivot", 3 | "description": "A simple jQuery pivot table widget", 4 | "version": "0.1.0", 5 | "main": "build/jbPivot.min.js", 6 | "author": { 7 | "name": "Jordi Baylina", 8 | "email": "info@uniclau.com", 9 | "url": "http://www.uniclau.com/" 10 | }, 11 | "bugs": { 12 | "url": "https://github.com/uniclau/jbPivot/issues" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/uniclau/jbPivot.git" 17 | }, 18 | "keywords": [ 19 | "pivot", 20 | "table", 21 | "grid", 22 | "grouping" 23 | ], 24 | "license": "GPL", 25 | "dependencies": { 26 | "jquery": "*", 27 | "jquery-ui": "*" 28 | }, 29 | "devDependencies": { 30 | "grunt-contrib-concat": "~0.3.0", 31 | "grunt-contrib-uglify": "~0.2.0", 32 | "grunt-contrib-jshint": "^0.10.0", 33 | "grunt": "~0.4.2" 34 | }, 35 | "scripts": { 36 | "build": "npm install && grunt", 37 | "test": "grunt" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/agregate_average.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 3 | 4 | This file is part of jbPivot. 5 | 6 | jbPivot is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | jbPivot is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with jbPivot. If not, see . 18 | */ 19 | 20 | function agregate_average(options) { 21 | "use strict"; 22 | var self = {}; 23 | self.options = $.extend({}, options); 24 | self.agregate = function (a, b) { 25 | var res; 26 | if ((!a) || (a.type !== "agregate_average")) { 27 | res = { 28 | type: "agregate_average", 29 | sum: 0, 30 | count: 0 31 | }; 32 | } else { 33 | res = { 34 | type: "agregate_average", 35 | sum: a.sum, 36 | count: a.count 37 | }; 38 | } 39 | if (b.type === "agregate_average") { 40 | res.sum += b.sum; 41 | res.count += b.count; 42 | } else if (typeof b === "object") { 43 | res.count++; 44 | if (typeof b[this.options.field] === "number") { 45 | res.sum += b[this.options.field]; 46 | } else if (typeof b[this.options.field] === "string") { 47 | try { 48 | res.sum += parseInt(b[this.options.field], 10); 49 | } catch (err) { 50 | 51 | } 52 | } 53 | } 54 | return res; 55 | }; 56 | 57 | self.getValue = function (a) { 58 | var res = null; 59 | if ((a) && (a.type === "agregate_average") && (a.count > 0)) { 60 | var v = a.sum / a.count; 61 | res = v; 62 | } 63 | return res; 64 | }; 65 | return self; 66 | } 67 | 68 | $.unc.plugins.addAgregate('average', agregate_average); -------------------------------------------------------------------------------- /src/agregate_count.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 3 | 4 | This file is part of jbPivot. 5 | 6 | jbPivot is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | jbPivot is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with jbPivot. If not, see . 18 | */ 19 | 20 | function agregate_count() { 21 | "use strict"; 22 | var self = {}; 23 | self.agregate = function (a, b) { 24 | var res; 25 | if ((!a) || (a.type !== "agregate_count")) { 26 | res = { 27 | type: "agregate_count", 28 | count: 0 29 | }; 30 | } else { 31 | res = { 32 | type: "agregate_count", 33 | count: a.count 34 | }; 35 | } 36 | if (b.type === "agregate_count") { 37 | res.count += b.count; 38 | } else if (typeof b === "object") { 39 | res.count++; 40 | } 41 | return res; 42 | }; 43 | 44 | self.getValue = function (a) { 45 | var res = null; 46 | if ((a) && (a.type === "agregate_count")) { 47 | res = a.count; 48 | } 49 | return res; 50 | }; 51 | return self; 52 | } 53 | 54 | $.unc.plugins.addAgregate('count', agregate_count); -------------------------------------------------------------------------------- /src/agregate_distinct.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 3 | 4 | This file is part of jbPivot. 5 | 6 | jbPivot is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | jbPivot is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with jbPivot. If not, see . 18 | */ 19 | 20 | function agregate_distinct(options) { 21 | "use strict"; 22 | var self = {}; 23 | self.field = options.field; 24 | self.agregate = function (a, b) { 25 | var res = { 26 | type: "fa_distinct" 27 | }; 28 | if ((!a) || (a.type !== "fa_distinct")) { 29 | res.repeated = false; 30 | if (b.type === "fa_distinct") { 31 | res.val = b.val; 32 | } else if (typeof b === "object") { 33 | res.repeated = false; 34 | if ((typeof b[this.field] === "number") || (typeof b[this.field] === "string")) { 35 | res.val = b[this.field]; 36 | } else { 37 | res.val = null; 38 | } 39 | } else { 40 | res.val = null; 41 | } 42 | } else { 43 | if (b.type === "fa_distinct") { 44 | res.repeated = (a.repeated || b.repeated || (a.val !== b.val)); 45 | res.val = a.val; 46 | } else if (typeof b === "object") { 47 | if ((typeof b[this.field] === "number") || (typeof b[this.field] === "string")) { 48 | res.repeated = (a.repeated || (a.val !== b[this.field])); 49 | res.val = a.val; 50 | } else { 51 | res.repeated = (a.repeated || (a.val !== null)); 52 | res.val = null; 53 | } 54 | } else { 55 | res.repeated = (a.repeated || (a.val !== null)); 56 | res.val = null; 57 | } 58 | } 59 | 60 | return res; 61 | }; 62 | 63 | self.getValue = function (a) { 64 | var res = null; 65 | if ((a) && (a.type === "fa_distinct")) { 66 | if (a.repeated) { 67 | res = "*"; 68 | } else { 69 | res = a.val; 70 | } 71 | } 72 | return res; 73 | }; 74 | return self; 75 | } 76 | 77 | $.unc.plugins.addAgregate('distinct', agregate_distinct); -------------------------------------------------------------------------------- /src/agregate_sum.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 3 | 4 | This file is part of jbPivot. 5 | 6 | jbPivot is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | jbPivot is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with jbPivot. If not, see . 18 | */ 19 | 20 | function agregate_sum(options) { 21 | "use strict"; 22 | var self = {}; 23 | self.field = options.field; 24 | self.agregate = function (a, b) { 25 | var res; 26 | if ((!a) || (a.type !== "agregate_sum")) { 27 | res = { 28 | type: "agregate_sum", 29 | sum: 0 30 | }; 31 | } else { 32 | res = { 33 | type: "agregate_sum", 34 | sum: a.sum 35 | }; 36 | } 37 | if (b.type === "agregate_sum") { 38 | res.sum += b.sum; 39 | } else if (typeof b === "object") { 40 | if (typeof b[this.field] === "number") { 41 | res.sum += b[this.field]; 42 | } else if (typeof b[this.field] === "string") { 43 | try { 44 | res.sum += parseInt(b[this.field],10); 45 | } catch (err) { 46 | 47 | } 48 | } 49 | } 50 | return res; 51 | }; 52 | 53 | self.getValue = function (a) { 54 | var res = null; 55 | if ((a) && (a.type === "agregate_sum")) { 56 | res = a.sum; 57 | } 58 | return res; 59 | }; 60 | return self; 61 | } 62 | 63 | $.unc.plugins.addAgregate('sum', agregate_sum); -------------------------------------------------------------------------------- /src/formatter_default.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 3 | 4 | This file is part of jbPivot. 5 | 6 | jbPivot is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | jbPivot is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with jbPivot. If not, see . 18 | */ 19 | 20 | function formatter_default() { 21 | "use strict"; 22 | var self = {}; 23 | self.format = function (value) { 24 | var V = ""; 25 | try { 26 | V = value.toString(); 27 | } catch (Error) { 28 | 29 | } 30 | return V; 31 | }; 32 | return self; 33 | } 34 | 35 | $.unc.plugins.addFormatter('default', formatter_default); -------------------------------------------------------------------------------- /src/group_distinct.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 3 | 4 | This file is part of jbPivot. 5 | 6 | jbPivot is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | jbPivot is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with jbPivot. If not, see . 18 | */ 19 | 20 | function grp_distinct(options) { 21 | "use strict"; 22 | var self = {}; 23 | self.values = []; 24 | self.names = {}; 25 | self.fieldtype = "number"; 26 | self.field = options.field; 27 | if (typeof options.sort === "undefined") { 28 | self.sort = "ASC"; 29 | } else { 30 | self.sort = options.sort.toUpperCase(); 31 | } 32 | if (typeof options.params !== "undefined") { 33 | self.params = options.params; 34 | } else { 35 | self.params = null; 36 | } 37 | if (typeof options.showAll !== "undefined") { 38 | self.showAll = options.showAll; 39 | } else { 40 | self.showAll = false; 41 | } 42 | 43 | self.CalculateValue = function (R) { 44 | var V = ""; 45 | var res; 46 | if (typeof R[this.field] === "function") { 47 | V = R[this.field](this.params); 48 | } else if (typeof R[this.field] === "number") { 49 | V = R[this.field].toString(); 50 | } else if (typeof R[this.field] === "string") { 51 | V = R[this.field]; 52 | this.fieldtype = "string"; 53 | } 54 | 55 | if (typeof V !== "string") { 56 | V = ""; 57 | } 58 | 59 | if (typeof this.names[V] !== "undefined") { 60 | res = this.names[V]; 61 | } else { 62 | res = this.values.push(V) - 1; 63 | this.names[V] = res; 64 | } 65 | 66 | return res; 67 | }; 68 | 69 | self.getStringValue = function (idx) { 70 | return this.values[idx]; 71 | }; 72 | 73 | self.DisplayValues = function (UsedValues) { 74 | var res; 75 | var i; 76 | 77 | if (this.showAll) { 78 | res = []; 79 | for (i = 0; i < this.values.length; i++) { 80 | res.push(i.toString()); 81 | } 82 | } else { 83 | res = UsedValues.slice(0); 84 | } 85 | 86 | var self = this; 87 | 88 | if (this.fieldtype === "string") { 89 | res = res.sort(function (a, b) { 90 | var res = 0; 91 | if (self.values[a] < self.values[b]) { 92 | res = -1; 93 | } 94 | if (self.values[a] > self.values[b]) { 95 | res = 1; 96 | } 97 | return res; 98 | }); 99 | } else { 100 | res = res.sort(function (a, b) { 101 | var aa = parseFloat(self.values[a]); 102 | var bb = parseFloat(self.values[b]); 103 | var res = 0; 104 | if (aa < bb) { 105 | res = -1; 106 | } 107 | if (aa > bb) { 108 | res = 1; 109 | } 110 | return res; 111 | }); 112 | } 113 | 114 | if (this.sort === "DESC") { 115 | res = res.reverse(); 116 | } 117 | 118 | return res; 119 | }; 120 | 121 | return self; 122 | } 123 | 124 | $.unc.plugins.addGrouper('distinct', grp_distinct); -------------------------------------------------------------------------------- /src/pivot.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2013 Uniclau S.L. (www.uniclau.com) 3 | 4 | This file is part of jbPivot. 5 | 6 | jbPivot is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | jbPivot is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with jbPivot. If not, see . 18 | */ 19 | 20 | 21 | $.unc = { 22 | plugins: { 23 | agregates: {}, 24 | addAgregate: function(agregateName, factory) { 25 | "use strict"; 26 | this.agregates[agregateName] = factory; 27 | }, 28 | groupers: {}, 29 | addGrouper: function(grouperName, factory) { 30 | "use strict"; 31 | this.groupers[grouperName] = factory; 32 | }, 33 | formatters: {}, 34 | addFormatter: function(formatterName, factory) { 35 | "use strict"; 36 | this.formatters[formatterName] = factory; 37 | } 38 | } 39 | }; 40 | 41 | 42 | $(function() { 43 | "use strict"; 44 | $.widget("unc.jbPivot", { 45 | options: { 46 | fields: {}, 47 | summary: true, 48 | copyright: true, 49 | formatter: "default", 50 | l_all: "All", 51 | l_unused_fields: "Unused fields" 52 | }, 53 | _create: function() { 54 | this.CollapsedNodes = {}; 55 | this.renderPending = false; 56 | this.reset(); 57 | if (typeof this.options.data !== "undefined") { 58 | this.insertRecords(this.options.data); 59 | } 60 | var self = this; 61 | $(this.element).on('click', ".collapse_button", function(event) { 62 | event.preventDefault(); 63 | self._togleCollapse(this.rel); 64 | }); 65 | 66 | $(this.element).on('dragstart', '.draggable', function(event) { 67 | self.pre_post = ""; 68 | self.dragcls = ""; 69 | self.dragdata = $(this).attr("rel"); 70 | event.originalEvent.dataTransfer.effectAllowed = 'move'; 71 | event.originalEvent.dataTransfer.setData("Text", $(this).attr("rel")); 72 | $(".pivot").addClass("drag_in_progress"); 73 | }); 74 | 75 | 76 | 77 | $(this.element).on('dragleave', '.dropable', function(event) { 78 | 79 | // var target=$(event.originalEvent.target); 80 | var target = $(this); 81 | var arr = target.attr('class').match(/\s+(target(X|Y|Z|U)[\d]+)($|\s)/); 82 | var cls = "." + arr[1]; 83 | var el = self.element; 84 | setTimeout(function() { 85 | $(cls, el).removeClass("dropping_pre"); 86 | $(cls, el).removeClass("dropping_post"); 87 | self.pre_post = ""; 88 | self.dragcls = ""; 89 | }, 0); 90 | 91 | event.stopPropagation(); 92 | event.preventDefault(); 93 | return false; 94 | }); 95 | 96 | $(this.element).on('dragover', '.dropable', function(event) { 97 | var target = $(this); 98 | var parentOffset = $(this).offset(); 99 | //or $(this).offset(); if you really just want the current element's offset 100 | var offsetX = event.originalEvent.pageX - parentOffset.left; 101 | var offsetY = event.originalEvent.pageY - parentOffset.top; 102 | 103 | var arr = target.attr('class').match(/\s+(target(X|Y|Z|U)([\d]+))($|\s)/); 104 | arr[3] = parseInt(arr[3], 10); 105 | var cls = "." + arr[1]; 106 | 107 | var pre_post; 108 | var oldpp = self.pre_post; 109 | var oldcls = self.dragcls; 110 | if ((arr[2] === "Y") || (arr[2] === "U")) { 111 | pre_post = offsetY > target.height() / 2 ? "post" : "pre"; 112 | } else { 113 | pre_post = offsetX > target.width() / 2 ? "post" : "pre"; 114 | } 115 | if (arr[3] === 0) { 116 | pre_post = "post"; 117 | } 118 | 119 | var from = self.dragdata; 120 | var to = $(this).attr("rel"); 121 | if (self._canMove(from, to, pre_post)) { 122 | 123 | var el = self.element; 124 | 125 | if ((oldpp !== pre_post) || (cls !== oldcls)) { 126 | $(cls, el).removeClass("dropping_pre"); 127 | $(cls, el).removeClass("dropping_post"); 128 | setTimeout(function() { 129 | $(cls, el).addClass("dropping_" + pre_post); 130 | self.pre_post = pre_post; 131 | self.dragcls = cls; 132 | }, 0); 133 | } 134 | 135 | 136 | event.originalEvent.dataTransfer.dropEffect = 'move'; 137 | event.stopPropagation(); 138 | event.preventDefault(); 139 | return false; 140 | } 141 | }); 142 | 143 | $(this.element).on('drop', '.dropable', function(event) { 144 | var target = $(this); 145 | 146 | var parentOffset = $(this).offset(); 147 | //or $(this).offset(); if you really just want the current element's offset 148 | var offsetX = event.originalEvent.pageX - parentOffset.left; 149 | var offsetY = event.originalEvent.pageY - parentOffset.top; 150 | 151 | var arr = target.attr('class').match(/\s+(target(X|Y|Z|U)([\d]+))($|\s)/); 152 | arr[3] = parseInt(arr[3], 10); 153 | 154 | var pre_pos; 155 | if ((arr[2] === "Y") || (arr[2] === "U")) { 156 | pre_pos = offsetY > target.height() / 2 ? "post" : "pre"; 157 | } else { 158 | pre_pos = offsetX > target.width() / 2 ? "post" : "pre"; 159 | } 160 | if (arr[3] === 0) { 161 | pre_pos = "post"; 162 | } 163 | var from = event.originalEvent.dataTransfer.getData("Text"); 164 | var to = $(this).attr("rel"); 165 | self._moveField(from, to, pre_pos); 166 | event.preventDefault(); 167 | return false; 168 | }); 169 | 170 | $(this.element).on('dragend', '.dropable', function() { 171 | var el = self.element; 172 | $(".pivot", el).removeClass("drag_in_progress"); 173 | }); 174 | 175 | }, 176 | reset: function() { 177 | this.fields = []; 178 | this.afields = []; 179 | this.xfields = []; 180 | this.yfields = []; 181 | this.zfields = []; 182 | this.ufields = []; 183 | this.fieldNames = []; 184 | this.fieldLabels = []; 185 | this.formatters = []; 186 | 187 | if ((typeof this.options.formatter === "undefined") || (this.options.formatter === null)) { 188 | this.options.formatter = "default"; 189 | } 190 | if (typeof this.options.formatter === "string") { 191 | if (typeof $.unc.plugins.formatters[this.options.formatter] !== "function") { 192 | throw ("Formatter: " + this.options.formatter + " is not defined"); 193 | } 194 | this.defaultFormatter = $.unc.plugins.formatters[this.options.formatter](this.options); 195 | } else if (typeof this.options.formatter === "function") { 196 | this.defaultFormatter = { 197 | format: this.options.formatter 198 | }; 199 | } else { 200 | throw ("Invalid formatter"); 201 | } 202 | 203 | if (this.options.formatter === null) { 204 | throw ("Formatter not defined"); 205 | } 206 | 207 | var f; 208 | var k = 0; 209 | var indexbyname = {}; 210 | for (f in this.options.fields) { 211 | if (this.options.fields.hasOwnProperty(f)) { 212 | var fo = $.extend({ 213 | agregateType: "distinct", 214 | groupType: "distinct", 215 | label: f, 216 | formatter: null 217 | }, this.options.fields[f]); 218 | 219 | if (fo.groupType !== "none") { 220 | if (typeof $.unc.plugins.groupers[fo.groupType] !== "function") { 221 | throw ("Grouper: " + fo.groupType + " is not defined"); 222 | } 223 | this.fields.push($.unc.plugins.groupers[fo.groupType](fo)); 224 | } else { 225 | this.fields.push(null); 226 | } 227 | 228 | if (fo.agregateType !== "none") { 229 | if (typeof $.unc.plugins.agregates[fo.agregateType] !== "function") { 230 | throw ("Grouper: " + fo.agregateType + " is not defined"); 231 | } 232 | this.afields.push($.unc.plugins.agregates[fo.agregateType](fo)); 233 | } else { 234 | this.afields.push(null); 235 | } 236 | 237 | if (typeof fo.formatter === "string") { 238 | if (typeof $.unc.plugins.formatters[fo.formatter] !== "function") { 239 | throw ("Formatter" + fo.formatter + " is not defined"); 240 | } 241 | this.formatters.push($.unc.plugins.formatters[fo.formatter](fo)); 242 | } else if (typeof fo.formatter === "function") { 243 | this.formatters.push({ 244 | format: fo.formatter 245 | }); 246 | } else { 247 | this.formatters.push(null); 248 | } 249 | 250 | indexbyname[f] = k; 251 | k++; 252 | 253 | this.fieldNames.push(f); 254 | this.fieldLabels.push(fo.label); 255 | } 256 | } 257 | 258 | var i, fn; 259 | 260 | for (i = 0; i < this.options.xfields.length; i++) { 261 | fn = this.options.xfields[i]; 262 | if (typeof indexbyname[fn] === "undefined") { 263 | throw ("Field " + fn + " in xfields not defined"); 264 | } 265 | if (typeof this.fields[indexbyname[fn]] === null) { 266 | throw ("Field " + fn + "is not groupable ans is ispecified in xfields"); 267 | } 268 | this.xfields.push(indexbyname[fn]); 269 | delete indexbyname[fn]; 270 | } 271 | for (i = 0; i < this.options.yfields.length; i++) { 272 | fn = this.options.yfields[i]; 273 | if (typeof indexbyname[fn] === "undefined") { 274 | throw ("Field " + fn + " in yfields not defined"); 275 | } 276 | if (typeof this.fields[indexbyname[fn]] === null) { 277 | throw ("Field " + fn + "is not groupable ans is ispecified in yfields"); 278 | } 279 | this.yfields.push(indexbyname[fn]); 280 | delete indexbyname[fn]; 281 | } 282 | for (i = 0; i < this.options.zfields.length; i++) { 283 | fn = this.options.zfields[i]; 284 | if (typeof indexbyname[fn] === "undefined") { 285 | throw ("Field " + fn + " in zfields not defined"); 286 | } 287 | if (typeof this.afields[indexbyname[fn]] === null) { 288 | throw ("Field " + fn + "is not agregatable ans is ispecified in zfields"); 289 | } 290 | this.zfields.push(indexbyname[fn]); 291 | delete indexbyname[fn]; 292 | } 293 | for (fn in indexbyname) { 294 | if (indexbyname.hasOwnProperty(fn)) { 295 | this.ufields.push(indexbyname[fn]); 296 | } 297 | } 298 | 299 | 300 | var mask = (1 << this.fields.length) - 1; 301 | 302 | this.indexes = {}; 303 | this.indexes_len = {}; 304 | 305 | this.indexes[mask] = {}; 306 | this.indexes_len[mask] = 0; 307 | this._generate_trees(); 308 | 309 | this._forceRender(); 310 | }, 311 | insertRecords: function(records) { 312 | var i, f; 313 | for (i = 0; i < records.length; i++) { 314 | var R = records[i]; 315 | 316 | var mindex = []; 317 | for (f = 0; f < this.fields.length; f++) { 318 | if (this.fields[f] !== null) { 319 | mindex.push(this.fields[f].CalculateValue(R)); 320 | } else { 321 | mindex.push(0); 322 | } 323 | } 324 | 325 | 326 | for (var mask in this.indexes) { 327 | if (this.indexes.hasOwnProperty(mask)) { 328 | 329 | var mindex2 = mindex.slice(0); 330 | for (var k = 0; k < this.fields.length; k++) { 331 | if (((1 << k) & mask) === 0) { 332 | mindex2[k] = 0; 333 | } 334 | } 335 | 336 | var groupidx = this._arr2idx(mindex2); 337 | 338 | if (typeof this.indexes[mask][groupidx] === "undefined") { 339 | this.indexes[mask][groupidx] = []; 340 | this.indexes_len[mask]++; 341 | } 342 | for (f = 0; f < this.afields.length; f++) { 343 | if (this.afields[f] !== null) { 344 | this.indexes[mask][groupidx][f] = this.afields[f].agregate(this.indexes[mask][groupidx][f], R); 345 | } 346 | } 347 | } 348 | } 349 | } 350 | 351 | this._generate_trees(); 352 | this._forceRender(); 353 | }, 354 | _forceRender: function() { 355 | if (this.renderPending) { 356 | return; 357 | } 358 | this.renderPending = true; 359 | var self = this; 360 | setTimeout(function() { 361 | self.renderPending = false; 362 | self._renderHtml(); 363 | }, 100); 364 | }, 365 | _arr2idx: function(arr) { 366 | return arr.join(","); 367 | }, 368 | _idx2arr: function(S) { 369 | var i; 370 | var arr = S.split(","); 371 | var res = []; 372 | for (i = 0; i < arr.length; i++) { 373 | res.push(parseInt(arr[i], 10)); 374 | } 375 | return res; 376 | }, 377 | // Returns an array of with all agregated fields from a vector (-1 means any). 378 | _getValues: function(mindex) { 379 | var groupidx; 380 | var mask = 0; 381 | for (var i = 0; i < this.fields.length; i++) { 382 | if (mindex[i] === -1) { 383 | mindex[i] = 0; 384 | } else { 385 | mask = mask | (1 << i); 386 | } 387 | } 388 | 389 | if (typeof this.indexes[mask] === "undefined") { 390 | this._generate_index(mask); 391 | } 392 | 393 | groupidx = this._arr2idx(mindex); 394 | 395 | var V = this.indexes[mask][groupidx]; 396 | if ((typeof V === "undefined") || (V === null)) { 397 | V = new Array(this.afields.length); 398 | } 399 | 400 | return V; 401 | }, 402 | _generate_index: function(mask) { 403 | var m; 404 | var smask = null; 405 | 406 | for (m in this.indexes) { 407 | if ((mask & m) === mask) { 408 | if ((smask === null) || (this.indexes_len[m] < this.indexes_len[smask])) { 409 | smask = m; 410 | } 411 | } 412 | } 413 | 414 | this.indexes[mask] = {}; 415 | this.indexes_len[mask] = 0; 416 | 417 | for (var v in this.indexes[smask]) { 418 | if (this.indexes[smask].hasOwnProperty(v)) { 419 | var mindex = this._idx2arr(v); 420 | for (m = 0; m < this.fields.length; m++) { 421 | if (((1 << m) & mask) === 0) { 422 | mindex[m] = 0; 423 | } 424 | } 425 | var groupidx = this._arr2idx(mindex); 426 | 427 | if (typeof this.indexes[mask][groupidx] === "undefined") { 428 | this.indexes[mask][groupidx] = []; 429 | this.indexes_len[mask]++; 430 | } 431 | for (var f = 0; f < this.afields.length; f++) { 432 | if (this.afields[f] !== null) { 433 | this.indexes[mask][groupidx][f] = this.afields[f].agregate(this.indexes[mask][groupidx][f], 434 | this.indexes[smask][v][f]); 435 | } 436 | } 437 | } 438 | } 439 | }, 440 | _generate_trees: function() { 441 | var node, i; 442 | var mask = (1 << this.fields.length) - 1; 443 | this.xtree = { 444 | childs: {} 445 | }; 446 | this.ytree = { 447 | childs: {} 448 | }; 449 | for (var k in this.indexes[mask]) { 450 | if (this.indexes[mask].hasOwnProperty(k)) { 451 | var mindex = this._idx2arr(k); 452 | 453 | node = this.xtree; 454 | 455 | for (i = 0; i < this.xfields.length; i++) { 456 | if (typeof node.childs[mindex[this.xfields[i]]] === "undefined") { 457 | node.childs[mindex[this.xfields[i]]] = { 458 | childs: {} 459 | }; 460 | } 461 | node = node.childs[mindex[this.xfields[i]]]; 462 | 463 | } 464 | 465 | node = this.ytree; 466 | 467 | for (i = 0; i < this.yfields.length; i++) { 468 | if (typeof node.childs[mindex[this.yfields[i]]] === "undefined") { 469 | node.childs[mindex[this.yfields[i]]] = { 470 | childs: {} 471 | }; 472 | } 473 | node = node.childs[mindex[this.yfields[i]]]; 474 | } 475 | } 476 | } 477 | }, 478 | _tree2table: function(axis, node, table) { 479 | 480 | var x, y, c; 481 | 482 | var w = axis === "y" ? this.yfields.length : this.xfields.length; 483 | 484 | y = table.length - 1; 485 | x = table[y].index.length; 486 | 487 | 488 | var m; 489 | 490 | if (this._isCollapsed(axis, table[y].index)) { 491 | table[y].cells[x] = {}; 492 | table[y].cells[x].spanx = w - x + 1; 493 | table[y].cells[x].spany = 1; 494 | m = 1; 495 | } else { 496 | var baseindex = table[y].index.slice(0); 497 | var newline = false; 498 | m = 0; 499 | 500 | 501 | var displayvalues; 502 | if (x < w) { 503 | var usedvalues = []; 504 | for (c in node.childs) { 505 | if (node.childs.hasOwnProperty(c)) { 506 | usedvalues.push(c); 507 | } 508 | } 509 | 510 | var fd = axis === "y" ? this.fields[this.yfields[x]] : this.fields[this.xfields[x]]; 511 | displayvalues = fd.DisplayValues(usedvalues); 512 | } else { 513 | displayvalues = []; 514 | } 515 | 516 | for (c = 0; c < displayvalues.length; c++) { 517 | 518 | if (newline) { 519 | table.push({ 520 | index: baseindex.slice(0), 521 | cells: {} 522 | }); 523 | } 524 | 525 | table[table.length - 1].index.push(displayvalues[c]); 526 | 527 | var nextNode; 528 | if (typeof node.childs[displayvalues[c]] === "undefined") { 529 | nextNode = { 530 | childs: {}, 531 | collapsed: false 532 | }; 533 | } else { 534 | nextNode = node.childs[displayvalues[c]]; 535 | } 536 | 537 | m += this._tree2table(axis, nextNode, table); 538 | newline = true; 539 | } 540 | 541 | if (m === 0) { 542 | table[y].cells[x] = {}; 543 | table[y].cells[x].spanx = w - x + 1; 544 | table[y].cells[x].spany = 1; 545 | m = 1; 546 | } else { 547 | table[y].cells[x] = {}; 548 | table[y].cells[x].spanx = 1; 549 | table[y].cells[x].spany = m; 550 | } 551 | } 552 | 553 | return m; 554 | }, 555 | _collapseLink: function(axis, mindex) { 556 | var S = ""; 557 | 558 | S += this._isCollapsed(axis, mindex) ? "+" : "-"; 559 | 560 | S += ""; 561 | return S; 562 | 563 | }, 564 | _renderHtml: function() { 565 | var colspan, cls, i, x, y, z, mindex; 566 | 567 | var cmax = this.xfields.length > this.yfields.length ? this.xfields.length : this.yfields.length; 568 | cmax++; 569 | 570 | var tablex = [{ 571 | index: [], 572 | cells: {} 573 | }]; 574 | this._tree2table("x", this.xtree, tablex); 575 | 576 | var tabley = [{ 577 | index: [], 578 | cells: {} 579 | }]; 580 | this._tree2table("y", this.ytree, tabley); 581 | 582 | var S = ""; 583 | 584 | S += ""; 585 | 586 | for (i = 0; i < this.ufields.length; i++) { 587 | S += ""; 608 | 609 | S += ""; 642 | S += "\n"; 643 | 644 | for (y = 1; y <= this.yfields.length; y++) { 645 | S += ""; 646 | for (x = 0; x < tabley.length; x++) { 647 | if (tabley[x].cells[y]) { 648 | S += ""; 675 | } 676 | } 677 | S += "\n"; 678 | } 679 | 680 | S += ""; 681 | for (x = 0; x < tabley.length; x++) { 682 | for (z = 0; z < this.zfields.length; z++) { 683 | S += ""; 788 | } 789 | } 790 | 791 | for (x = 0; x < tabley.length; x++) { 792 | 793 | mindex = []; 794 | for (i = 0; i < this.fields.length; i++) { 795 | mindex.push(-1); 796 | } 797 | 798 | for (i = 0; i < tablex[y].index.length; i++) { 799 | mindex[this.xfields[i]] = tablex[y].index[i]; 800 | } 801 | 802 | for (i = 0; i < tabley[x].index.length; i++) { 803 | mindex[this.yfields[i]] = tabley[x].index[i]; 804 | } 805 | 806 | V = this._getValues(mindex); 807 | 808 | for (z = 0; z < this.zfields.length; z++) { 809 | S += " 0)) { 861 | S += ""; 862 | S += "
" + this.options.l_unused_fields + "
"; 603 | 604 | 605 | 606 | 607 | S += "
0 ? this.zfields.length : 1); 624 | S += " 0) { 636 | S += this._collapseLink("y", []); 637 | } 638 | 639 | S += this.options.l_all; 640 | 641 | S += "
0 ? this.zfields.length : 1); 661 | 662 | S += " colspan=\"" + colspan + "\""; 663 | S += " rowspan=\"" + tabley[x].cells[y].spanx + "\""; 664 | S += ">"; 665 | 666 | 667 | if (y < this.yfields.length) { 668 | S += this._collapseLink("y", tabley[x].index.slice(0, y)); 669 | } 670 | 671 | S += this.fields[this.yfields[y - 1]].getStringValue(tabley[x].index[y - 1]); 672 | 673 | 674 | S += "
1 ? " colspan=\"" + tablex[y].cells[x].spanx + "\"" : ""; 753 | S += tablex[y].cells[x].spany > 1 ? " rowspan=\"" + tablex[y].cells[x].spany + "\"" : ""; 754 | 755 | cls = "lefttitle dropable"; 756 | if (x > 0) { 757 | cls += " draggable"; 758 | } 759 | if (x === 0) { 760 | cls += " line_left_" + cmax; 761 | } 762 | 763 | cls += this._clsTopLine(tablex, y, tablex[y].cells[x].spany); 764 | cls += this._clsBottomLine(tablex, y, tablex[y].cells[x].spany); 765 | cls += " targetX" + x; 766 | 767 | S += " class=\"" + cls + "\""; 768 | 769 | S += "\""; 770 | S += " rel=\"X," + x + "\""; 771 | 772 | if (x > 0) { 773 | S += " draggable=\"true\""; 774 | } 775 | 776 | S += ">"; 777 | 778 | if (x < this.xfields.length) { 779 | S += this._collapseLink("x", tablex[y].index.slice(0, x)); 780 | } 781 | 782 | if (x === 0) { 783 | S += this.options.l_all; 784 | } else { 785 | S += this.fields[this.xfields[x - 1]].getStringValue(tablex[y].index[x - 1]); 786 | } 787 | S += "
0) { 1070 | m = 0; 1071 | while ((m < this.yfields.length) && (m < tabley[x].index.length) && (m < tabley[x - 1].index.length) && (tabley[x].index[m] === tabley[x - 1].index[m])) { 1072 | m++; 1073 | } 1074 | m = this.yfields.length - m; 1075 | } else { 1076 | m = this.xfields.length > this.yfields.length ? this.xfields.length : this.yfields.length; 1077 | m++; 1078 | } 1079 | 1080 | cls += " line_left_" + m; 1081 | return cls; 1082 | }, 1083 | _clsRightLine: function(tabley, x, span) { 1084 | if (typeof span === "undefined") { 1085 | span = 1; 1086 | } 1087 | 1088 | var cls = " "; 1089 | var m; 1090 | 1091 | if (x + span < tabley.length) { 1092 | m = 0; 1093 | while ((m < this.yfields.length) && (m < tabley[x].index.length) && (m < tabley[x + span].index.length) && (tabley[x].index[m] === tabley[x + span].index[m])) { 1094 | m++; 1095 | } 1096 | m = this.yfields.length - m; 1097 | } else { 1098 | m = this.xfields.length > this.yfields.length ? this.xfields.length : this.yfields.length; 1099 | m++; 1100 | } 1101 | 1102 | cls += " line_right_" + m; 1103 | 1104 | return cls; 1105 | }, 1106 | _clsTopLine: function(tablex, y, span) { 1107 | if (typeof span === "undefined") { 1108 | span = 1; 1109 | } 1110 | 1111 | var cls = " "; 1112 | var m; 1113 | 1114 | if (y > 0) { 1115 | m = 0; 1116 | while ((m < this.xfields.length) && (m < tablex[y].index.length) && (m < tablex[y - 1].index.length) && (tablex[y].index[m] === tablex[y - 1].index[m])) { 1117 | m++; 1118 | } 1119 | m = this.xfields.length - m; 1120 | } else { 1121 | m = this.xfields.length > this.yfields.length ? this.xfields.length : this.yfields.length; 1122 | m++; 1123 | } 1124 | 1125 | cls += " line_top_" + m; 1126 | return cls; 1127 | }, 1128 | _clsBottomLine: function(tablex, y, span) { 1129 | if (typeof span === "undefined") { 1130 | span = 1; 1131 | } 1132 | 1133 | var cls = " "; 1134 | var m; 1135 | if (y + span < tablex.length) { 1136 | m = 0; 1137 | while ((m < this.xfields.length) && (m < tablex[y].index.length) && (m < tablex[y + span].index.length) && (tablex[y].index[m] === tablex[y + span].index[m])) { 1138 | m++; 1139 | } 1140 | m = this.xfields.length - m; 1141 | } else { 1142 | m = this.xfields.length > this.yfields.length ? this.xfields.length : this.yfields.length; 1143 | m++; 1144 | } 1145 | 1146 | cls += " line_bottom_" + m; 1147 | 1148 | return cls; 1149 | }, 1150 | /* _clsGroupX: function (tablex, tabley, x, y) { 1151 | var cls = " "; 1152 | 1153 | return cls; 1154 | }, 1155 | _clsGroupY: function (tablex, tabley, x, y) { 1156 | var cls = " "; 1157 | 1158 | return cls; 1159 | }, 1160 | */ 1161 | _format: function(value, field) { 1162 | var V = null; 1163 | if (this.formatters[field] !== null) { 1164 | V = this.formatters[field].format(value, this.fieldNames[field]); 1165 | } 1166 | if ((typeof V === "undefined") || (V === null)) { 1167 | V = this.defaultFormatter.format(value, this.fieldNames[field]); 1168 | } 1169 | return V; 1170 | } 1171 | }); 1172 | }); -------------------------------------------------------------------------------- /test/testpivot.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 42 | 43 | 120 | 121 | 122 | 123 |
124 |
125 | reload 126 | 127 | 128 | 129 | 130 | 131 | 132 | --------------------------------------------------------------------------------