- 1 :
/**
- 2 :
* The Correlations tool enables an exploration of the extent to which term frequencies vary in sync (terms whose frequencies rise and fall together or inversely).
- 3 :
*
- 4 :
* @example
- 5 :
*
- 6 :
* let config = {
- 7 :
* columns: null,
- 8 :
* dir: null,
- 9 :
* docId: null,
- 10 :
* docIndex: null,
- 11 :
* minInDocumentsCountRatio: null,
- 12 :
* query: null,
- 13 :
* sort: null,
- 14 :
* stopList: null,
- 15 :
* termColors: null,
- 16 :
* withDistributions: null
- 17 :
* };
- 18 :
*
- 19 :
* loadCorpus("austen").tool("correlations", config);
- 20 :
*
- 21 :
*
- 22 :
* @class Correlations
- 23 :
* @tutorial correlations
- 24 :
* @memberof Tools
- 25 :
*/
- 26 :
Ext.define('Voyant.panel.Correlations', {
- 27 :
extend: 'Ext.grid.Panel',
- 28 :
mixins: ['Voyant.panel.Panel'],
- 29 :
alias: 'widget.correlations',
- 30 :
statics: {
- 31 :
i18n: {
- 32 :
},
- 33 :
api: {
- 34 :
/**
- 35 :
* @memberof Tools.Correlations
- 36 :
* @instance
- 37 :
* @property {query}
- 38 :
*/
- 39 :
query: undefined,
- 40 :
- 41 :
/**
- 42 :
* @memberof Tools.Correlations
- 43 :
* @instance
- 44 :
* @property {docId}
- 45 :
*/
- 46 :
docId: undefined,
- 47 :
- 48 :
/**
- 49 :
* @memberof Tools.Correlations
- 50 :
* @instance
- 51 :
* @property {docIndex}
- 52 :
*/
- 53 :
docIndex: undefined,
- 54 :
- 55 :
/**
- 56 :
* @memberof Tools.Correlations
- 57 :
* @instance
- 58 :
* @property {stopList}
- 59 :
* @default
- 60 :
*/
- 61 :
stopList: 'auto',
- 62 :
- 63 :
/**
- 64 :
* @memberof Tools.Correlations
- 65 :
* @instance
- 66 :
* @property {Number} minInDocumentsCountRatio The minimum coverage (as a percentage) for terms. For instance, if a corpus has 10 documents and the minimum coverage is 20%, at least two of the documents must contain the term or it will be ignored.
- 67 :
* @default
- 68 :
*/
- 69 :
minInDocumentsCountRatio: 100,
- 70 :
- 71 :
/**
- 72 :
* @memberof Tools.Correlations
- 73 :
* @instance
- 74 :
* @property {withDistributions}
- 75 :
* @default
- 76 :
*/
- 77 :
withDistributions: 'relative',
- 78 :
- 79 :
/**
- 80 :
* @memberof Tools.Correlations
- 81 :
* @instance
- 82 :
* @property {columns} columns 'sourceTerm', 'source-distributions', 'target-distributions', 'targetTerm', 'correlation', 'significance'
- 83 :
*/
- 84 :
columns: undefined,
- 85 :
- 86 :
/**
- 87 :
* @memberof Tools.Correlations
- 88 :
* @instance
- 89 :
* @property {sort}
- 90 :
*/
- 91 :
sort: undefined,
- 92 :
- 93 :
/**
- 94 :
* @memberof Tools.Correlations
- 95 :
* @instance
- 96 :
* @property {dir}
- 97 :
*/
- 98 :
dir: undefined,
- 99 :
- 100 :
/**
- 101 :
* @memberof Tools.Correlations
- 102 :
* @instance
- 103 :
* @property {termColors}
- 104 :
* @default
- 105 :
*/
- 106 :
termColors: 'categories'
- 107 :
},
- 108 :
glyph: 'xf0ce@FontAwesome'
- 109 :
},
- 110 :
config: {
- 111 :
options: [{xtype: 'stoplistoption'}, {xtype: 'categoriesoption'}, {xtype: 'termcolorsoption'}]
- 112 :
},
- 113 :
constructor: function() {
- 114 :
this.callParent(arguments);
- 115 :
this.mixins['Voyant.panel.Panel'].constructor.apply(this, arguments);
- 116 :
},
- 117 :
- 118 :
initComponent: function() {
- 119 :
var me = this;
- 120 :
- 121 :
Ext.apply(me, {
- 122 :
title: this.localize('title'),
- 123 :
emptyText: this.localize("emptyText"),
- 124 :
store: Ext.create("Voyant.data.store.TermCorrelationsBuffered", {
- 125 :
parentPanel: this,
- 126 :
leadingBufferZone: 100 // since these calls are expensive reduce buffer to 1 page
- 127 :
}),
- 128 :
- 129 :
columns: [{
- 130 :
text: this.localize("source"),
- 131 :
tooltip: this.localize("sourceTip"),
- 132 :
dataIndex: 'sourceTerm',
- 133 :
sortable: false,
- 134 :
xtype: 'coloredtermfield'
- 135 :
},{
- 136 :
xtype: 'widgetcolumn',
- 137 :
tooltip: this.localize("trendTip"),
- 138 :
width: 100,
- 139 :
dataIndex: 'source-distributions',
- 140 :
widget: {
- 141 :
xtype: 'sparklineline'
- 142 :
},
- 143 :
text: '←'
- 144 :
},{
- 145 :
xtype: 'widgetcolumn',
- 146 :
tooltip: this.localize("trendTip"),
- 147 :
width: 100,
- 148 :
dataIndex: 'target-distributions',
- 149 :
widget: {
- 150 :
xtype: 'sparklineline'
- 151 :
},
- 152 :
text: '→',
- 153 :
align: 'right'
- 154 :
},{
- 155 :
text: this.localize("target"),
- 156 :
tooltip: this.localize("targetTip"),
- 157 :
dataIndex: 'targetTerm',
- 158 :
sortable: false,
- 159 :
xtype: 'coloredtermfield'
- 160 :
},{
- 161 :
text: this.localize("correlation"),
- 162 :
tooltip: this.localize("correlationTip"),
- 163 :
dataIndex: 'correlation'
- 164 :
},{
- 165 :
text: this.localize("significance"),
- 166 :
tooltip: this.localize("significanceTip"),
- 167 :
dataIndex: 'significance'
- 168 :
}],
- 169 :
- 170 :
- 171 :
listeners: {
- 172 :
scope: this,
- 173 :
corpusSelected: function() {
- 174 :
this.setApiParams({docIndex: undefined, docId: undefined});
- 175 :
this.getStore().getProxy().setExtraParam('tool', 'corpus.CorpusTermCorrelations');
- 176 :
this.getStore().load();
- 177 :
},
- 178 :
- 179 :
documentsSelected: function(src, docs) {
- 180 :
var docIds = [];
- 181 :
var corpus = this.getStore().getCorpus();
- 182 :
docs.forEach(function(doc) {
- 183 :
docIds.push(corpus.getDocument(doc).getId())
- 184 :
}, this);
- 185 :
this.setApiParams({docId: docIds, docIndex: undefined})
- 186 :
this.getStore().getProxy().setExtraParam('tool', 'corpus.DocumentTermCorrelations');
- 187 :
this.getStore().load();
- 188 :
}
- 189 :
- 190 :
},
- 191 :
dockedItems: [{
- 192 :
dock: 'bottom',
- 193 :
xtype: 'toolbar',
- 194 :
overflowHandler: 'scroller',
- 195 :
items: [{
- 196 :
xtype: 'querysearchfield'
- 197 :
},{
- 198 :
xtype: 'totalpropertystatus'
- 199 :
}, {
- 200 :
xtype: 'tbspacer'
- 201 :
}, {
- 202 :
xtype: 'tbtext',
- 203 :
itemId: 'minInDocumentsCountRatioLabel',
- 204 :
text: me.localize('minInDocumentsCountRatioLabel')
- 205 :
}, {
- 206 :
xtype: 'slider',
- 207 :
increment: 5,
- 208 :
minValue: 0,
- 209 :
maxValue: 100,
- 210 :
width: 75,
- 211 :
listeners: {
- 212 :
afterrender: function(slider) {
- 213 :
slider.setValue(this.getApiParam("minInDocumentsCountRatio"))
- 214 :
slider.up('toolbar').getComponent("minInDocumentsCountRatioLabel").setText(new Ext.XTemplate(me.localize("minInDocumentsCountRatioLabel")).apply([this.getApiParam("minInDocumentsCountRatio")]));
- 215 :
},
- 216 :
changecomplete: function(slider, newvalue) {
- 217 :
this.setApiParams({minInDocumentsCountRatio: newvalue});
- 218 :
slider.up('toolbar').getComponent("minInDocumentsCountRatioLabel").setText(new Ext.XTemplate(me.localize("minInDocumentsCountRatioLabel")).apply([newvalue]));
- 219 :
this.getStore().load();
- 220 :
},
- 221 :
scope: this
- 222 :
}
- 223 :
},{
- 224 :
xtype: 'corpusdocumentselector'
- 225 :
}]
- 226 :
}]
- 227 :
});
- 228 :
- 229 :
me.on("loadedCorpus", function(src, corpus) {
- 230 :
if (corpus.getDocumentsCount()==1) { // switch to documents mode
- 231 :
this.getStore().getProxy().setExtraParam('tool', 'corpus.DocumentTermCorrelations');
- 232 :
}
- 233 :
if (this.isVisible()) {
- 234 :
this.getStore().load();
- 235 :
}
- 236 :
});
- 237 :
- 238 :
me.on("activate", function() { // load after tab activate (if we're in a tab panel)
- 239 :
if (this.getStore().getCorpus()) {this.getStore().load();}
- 240 :
}, this)
- 241 :
- 242 :
me.on("query", function(src, query) {
- 243 :
this.setApiParam("query", query);
- 244 :
this.getStore().load();
- 245 :
}, me);
- 246 :
- 247 :
me.callParent(arguments);
- 248 :
}
- 249 :
- 250 :
});