hebasta | 10e0c21 | 2018-06-19 17:09:08 +0200 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Creates and displays corpus statistic |
| 4 | * |
| 5 | * @author Helge Stallkamp |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | define(['util'], function (){ |
| 11 | |
| 12 | return{ |
| 13 | |
| 14 | /** |
| 15 | * Create new statistic object |
| 16 | */ |
| 17 | create: function(statistic){ |
| 18 | return Object.create(this)._init(statistic); |
| 19 | }, |
| 20 | |
| 21 | /** |
| 22 | * Initialize statistic object |
| 23 | */ |
| 24 | _init: function(statistic){ |
| 25 | if(statistic === undefined){ |
| 26 | throw new Error("Missing parameter"); |
| 27 | } |
| 28 | else{ |
| 29 | this._statistic = statistic; |
| 30 | this._visibleStat = false; |
| 31 | return this; |
| 32 | } |
| 33 | }, |
| 34 | |
| 35 | /** |
| 36 | * Display statistic object |
| 37 | * as HTML Description List Element |
| 38 | */ |
| 39 | element : function(){ |
| 40 | |
| 41 | //if this._element already exists return without doing something |
| 42 | if (this._element !== undefined) { |
| 43 | return this._element; |
| 44 | }; |
| 45 | |
| 46 | //create HTML Description List Element |
| 47 | var statDL = document.createElement('dl'); |
| 48 | var statistic = this._statistic; |
| 49 | |
| 50 | var keys = Object.keys(statistic); |
| 51 | for(i = 0; i < keys.length; i++){ |
| 52 | statSp = statDL.addE('div') |
| 53 | statDT = statSp.addE('dt'); |
| 54 | var k = keys[i]; |
| 55 | statDT.addT(k); |
| 56 | statDT.setAttribute('title' , k); |
| 57 | statDD = statSp.addE('dd'); |
| 58 | statDD.addT(statistic[k]); |
| 59 | } |
| 60 | |
| 61 | this._element = statDL; |
| 62 | return this._element; |
| 63 | }, |
| 64 | |
| 65 | } |
| 66 | |
| 67 | }); |