- 1 :
/**
- 2 :
* Document Terms is a table view of term frequencies for each document.
- 3 :
*
- 4 :
* @example
- 5 :
*
- 6 :
* let config = {
- 7 :
* "bins": null,
- 8 :
* "columns": null,
- 9 :
* "dir": null,
- 10 :
* "docId": null,
- 11 :
* "docIndex": null,
- 12 :
* "query": null,
- 13 :
* "sort": null,
- 14 :
* "stopList": null,
- 15 :
* "termColors": null,
- 16 :
* };
- 17 :
*
- 18 :
* loadCorpus("austen").tool("documentterms", config);
- 19 :
*
- 20 :
* @class DocumentTerms
- 21 :
* @tutorial documentterms
- 22 :
* @memberof Tools
- 23 :
*/
- 24 :
Ext.define('Voyant.panel.DocumentTerms', {
- 25 :
extend: 'Ext.grid.Panel',
- 26 :
mixins: ['Voyant.panel.Panel'],
- 27 :
requires: ['Voyant.data.store.DocumentTerms'],
- 28 :
alias: 'widget.documentterms',
- 29 :
config: {
- 30 :
options: [{
- 31 :
xtype: 'stoplistoption'
- 32 :
},{
- 33 :
xtype: 'categoriesoption'
- 34 :
},{
- 35 :
xtype: 'termcolorsoption'
- 36 :
}]
- 37 :
},
- 38 :
statics: {
- 39 :
i18n: {
- 40 :
},
- 41 :
api: {
- 42 :
/**
- 43 :
* @memberof Tools.DocumentTerms
- 44 :
* @instance
- 45 :
* @property {stopList}
- 46 :
* @default
- 47 :
*/
- 48 :
stopList: 'auto',
- 49 :
/**
- 50 :
* @memberof Tools.DocumentTerms
- 51 :
* @instance
- 52 :
* @property {query}
- 53 :
*/
- 54 :
query: undefined,
- 55 :
/**
- 56 :
* @memberof Tools.DocumentTerms
- 57 :
* @instance
- 58 :
* @property {docId}
- 59 :
*/
- 60 :
docId: undefined,
- 61 :
/**
- 62 :
* @memberof Tools.DocumentTerms
- 63 :
* @instance
- 64 :
* @property {docIndex}
- 65 :
*/
- 66 :
docIndex: undefined,
- 67 :
/**
- 68 :
* @memberof Tools.DocumentTerms
- 69 :
* @instance
- 70 :
* @property {bins}
- 71 :
* @default
- 72 :
*/
- 73 :
bins: 10,
- 74 :
/**
- 75 :
* @memberof Tools.DocumentTerms
- 76 :
* @instance
- 77 :
* @property {columns} columns 'docIndex', 'term', 'rawFreq', 'relativeFreq', 'tfidf', 'zscore', 'distributions'
- 78 :
*/
- 79 :
columns: undefined,
- 80 :
/**
- 81 :
* @memberof Tools.DocumentTerms
- 82 :
* @instance
- 83 :
* @property {sort}
- 84 :
*/
- 85 :
sort: undefined,
- 86 :
/**
- 87 :
* @memberof Tools.DocumentTerms
- 88 :
* @instance
- 89 :
* @property {dir}
- 90 :
*/
- 91 :
dir: undefined,
- 92 :
/**
- 93 :
* @memberof Tools.DocumentTerms
- 94 :
* @instance
- 95 :
* @property {termColors}
- 96 :
* @default
- 97 :
*/
- 98 :
termColors: 'categories'
- 99 :
},
- 100 :
glyph: 'xf0ce@FontAwesome'
- 101 :
},
- 102 :
constructor: function(config) {
- 103 :
- 104 :
this.callParent(arguments);
- 105 :
this.mixins['Voyant.panel.Panel'].constructor.apply(this, arguments);
- 106 :
- 107 :
// create a listener for corpus loading (defined here, in case we need to load it next)
- 108 :
this.on('loadedCorpus', function(src, corpus) {
- 109 :
var store = this.getStore();
- 110 :
store.setCorpus(corpus);
- 111 :
if (this.isVisible()) {
- 112 :
store.load();
- 113 :
}
- 114 :
});
- 115 :
- 116 :
if (config.embedded) {
- 117 :
if (window.console) {
- 118 :
console.warn(config.embedded.then);
- 119 :
}
- 120 :
var cls = Ext.getClass(config.embedded).getName();
- 121 :
if (cls=="Voyant.data.store.DocumentTerms" || cls=="Voyant.data.model.Document") {
- 122 :
this.fireEvent('loadedCorpus', this, config.embedded.getCorpus());
- 123 :
}
- 124 :
}
- 125 :
else if (config.corpus) {
- 126 :
this.fireEvent('loadedCorpus', this, config.corpus);
- 127 :
}
- 128 :
- 129 :
this.on("query", function(src, query) {
- 130 :
this.fireEvent("corpusTermsClicked", src, query);
- 131 :
}, this);
- 132 :
- 133 :
this.on("corpusTermsClicked", function(src, terms) {
- 134 :
if (this.getStore().getCorpus()) { // make sure we have a corpus
- 135 :
var query = [];
- 136 :
terms.forEach(function(term) {
- 137 :
query.push(Ext.isString(term) ? term : term.get("term"));
- 138 :
});
- 139 :
this.setApiParams({
- 140 :
query: query,
- 141 :
docId: undefined,
- 142 :
docIndex: undefined
- 143 :
});
- 144 :
if (this.isVisible()) {
- 145 :
this.getStore().load({params: this.getApiParams()});
- 146 :
}
- 147 :
}
- 148 :
});
- 149 :
- 150 :
this.on("documentsClicked", function(src, documents) {
- 151 :
var docIds = [];
- 152 :
documents.forEach(function(doc) {docIds.push(doc.get('id'));});
- 153 :
this.setApiParams({
- 154 :
docId: docIds,
- 155 :
query: undefined
- 156 :
});
- 157 :
if (this.isVisible()) {
- 158 :
this.getStore().load({params: this.getApiParams()});
- 159 :
}
- 160 :
});
- 161 :
- 162 :
this.on("documentsSelected", function(src, docIds) {
- 163 :
this.setApiParams({
- 164 :
docId: docIds,
- 165 :
query: undefined
- 166 :
});
- 167 :
if (this.isVisible()) {
- 168 :
this.getStore().load({params: this.getApiParams()});
- 169 :
}
- 170 :
});
- 171 :
- 172 :
this.on("corpusSelected", function(src, corpus) {
- 173 :
this.setApiParams({
- 174 :
docId: undefined,
- 175 :
docIndex: undefined
- 176 :
});
- 177 :
if (this.isVisible()) {
- 178 :
this.getStore().load({params: this.getApiParams()});
- 179 :
}
- 180 :
});
- 181 :
- 182 :
this.on("activate", function() { // load after tab activate (if we're in a tab panel)
- 183 :
if (this.getStore().getCorpus()) {
- 184 :
this.getStore().load({params: this.getApiParams()});
- 185 :
}
- 186 :
}, this);
- 187 :
},
- 188 :
- 189 :
initComponent: function() {
- 190 :
var me = this;
- 191 :
- 192 :
var store = Ext.create("Voyant.data.store.DocumentTermsBuffered", {parentPanel: this});
- 193 :
- 194 :
Ext.apply(me, {
- 195 :
title: this.localize('title'),
- 196 :
emptyText: this.localize("emptyText"),
- 197 :
store : store,
- 198 :
selModel: Ext.create('Ext.selection.CheckboxModel', {
- 199 :
listeners: {
- 200 :
selectionchange: {
- 201 :
fn: function(sm, selections) {
- 202 :
this.getApplication().dispatchEvent('documentTermsClicked', this, selections);
- 203 :
},
- 204 :
scope: this
- 205 :
}
- 206 :
},
- 207 :
pruneRemoved: false,
- 208 :
mode: 'SIMPLE'
- 209 :
}),
- 210 :
dockedItems: [{
- 211 :
dock: 'bottom',
- 212 :
xtype: 'toolbar',
- 213 :
overflowHandler: 'scroller',
- 214 :
items: [{
- 215 :
xtype: 'querysearchfield'
- 216 :
}, {
- 217 :
xtype: 'totalpropertystatus'
- 218 :
},{
- 219 :
xtype: 'corpusdocumentselector'
- 220 :
}]
- 221 :
}],
- 222 :
columns: [{
- 223 :
text: '#',
- 224 :
width: 30,
- 225 :
dataIndex: 'docIndex',
- 226 :
sortable: true,
- 227 :
renderer: function(v) {return v+1;} // 0-based to 1-based
- 228 :
},{
- 229 :
text: this.localize("term"),
- 230 :
dataIndex: 'term',
- 231 :
tooltip: this.localize("termTip"),
- 232 :
sortable: true,
- 233 :
flex: 1,
- 234 :
xtype: 'coloredtermfield',
- 235 :
useCategoriesMenu: true
- 236 :
},{
- 237 :
text: this.localize("rawFreq"),
- 238 :
dataIndex: 'rawFreq',
- 239 :
tooltip: this.localize("rawFreqTip"),
- 240 :
width: 'autoSize',
- 241 :
sortable: true
- 242 :
},{
- 243 :
text: this.localize("relativeFreq"),
- 244 :
tooltip: this.localize("relativeFreqTip"),
- 245 :
dataIndex: 'relativeFreq',
- 246 :
width: 'autoSize',
- 247 :
sortable: true,
- 248 :
renderer: function(val) {
- 249 :
return Ext.util.Format.number(val*1000000, "0,000")
- 250 :
}
- 251 :
},{
- 252 :
text: this.localize("tfidf"),
- 253 :
tooltip: this.localize("tfidfTip"),
- 254 :
dataIndex: 'tfidf',
- 255 :
width: 'autoSize',
- 256 :
sortable: true,
- 257 :
hidden: true,
- 258 :
renderer: Ext.util.Format.numberRenderer('0,000.000')
- 259 :
},{
- 260 :
text: this.localize("zscore"),
- 261 :
tooltip: this.localize("zscoreTip"),
- 262 :
dataIndex: 'zscore',
- 263 :
width: 'autoSize',
- 264 :
sortable: true,
- 265 :
hidden: true,
- 266 :
renderer: Ext.util.Format.numberRenderer('0,000.000')
- 267 :
},{
- 268 :
xtype: 'widgetcolumn',
- 269 :
text: this.localize("trend"),
- 270 :
tooltip: this.localize('trendTip'),
- 271 :
flex: 1,
- 272 :
dataIndex: 'distributions',
- 273 :
widget: {
- 274 :
xtype: 'sparklineline'
- 275 :
}
- 276 :
}],
- 277 :
- 278 :
listeners: {
- 279 :
termsClicked: {
- 280 :
fn: function(src, terms) {
- 281 :
if (this.getStore().getCorpus()) { // make sure we have a corpus
- 282 :
var queryTerms = [];
- 283 :
terms.forEach(function(term) {
- 284 :
if (Ext.isString(term)) {queryTerms.push(term);}
- 285 :
else if (term.term) {queryTerms.push(term.term);}
- 286 :
else if (term.getTerm) {queryTerms.push(term.getTerm());}
- 287 :
});
- 288 :
if (queryTerms.length > 0) {
- 289 :
this.setApiParams({
- 290 :
docIndex: undefined,
- 291 :
docId: undefined,
- 292 :
query: queryTerms
- 293 :
});
- 294 :
if (this.isVisible()) {
- 295 :
if (this.isVisible()) {
- 296 :
this.getStore().load({params: this.getApiParams()});
- 297 :
}
- 298 :
}
- 299 :
}
- 300 :
}
- 301 :
},
- 302 :
scope: this
- 303 :
}
- 304 :
}
- 305 :
});
- 306 :
- 307 :
me.callParent(arguments);
- 308 :
- 309 :
me.getStore().getProxy().setExtraParam("withDistributions", true);
- 310 :
- 311 :
}
- 312 :
- 313 :
});