1const ShowMe = { 2 previousState: { 3 densityPlotDisabled: null, densityPlotSelected: null, 4 trendLinesDisabled: null, trendLinesSelected: null 5 }, 6 7 init: function() { 8 const self = this; 9 10 self.installMouseEnterButtonBehaviour(); 11 self.installClickDensityPlotButtonBehaviour(); 12 self.installClickTrendLineButtonBehaviour(); 13 }, 14 setToDefault: function() { 15 const self = this; 16 17 self.clearState(); 18 self.endPreview(); 19 self.lockDensityPlot(); 20 self.lockTrendLines(); 21 }, 22 23 // state 24 25 saveState: function() { 26 const self = this; 27 28 self.previousState.densityPlotDisabled = $('#vis-column .showme .density-plot.button').hasClass('disabled'); 29 self.previousState.densityPlotSelected = $('#vis-column .showme .density-plot.button').hasClass('selected'); 30 self.previousState.trendLinesDisabled = $('#vis-column .showme .trend-lines.button').hasClass('disabled'); 31 self.previousState.trendLinesSelected = $('#vis-column .showme .trend-lines.button').hasClass('selected'); 32 }, 33 clearState: function() { 34 const self = this; 35 36 self.previousState.densityPlotDisabled = null; 37 self.previousState.densityPlotSelected = null; 38 self.previousState.trendLinesDisabled = null; 39 self.previousState.trendLinesSelected = null; 40 }, 41 restoreState: function() { 42 const self = this; 43 44 if (self.previousState.densityPlotDisabled === null || 45 self.previousState.densityPlotSelected === null || 46 self.previousState.trendLinesDisabled === null || 47 self.previousState.trendLinesSelected === null) 48 return; 49 50 if (self.previousState.densityPlotDisabled) 51 $('#vis-column .showme .density-plot.button').addClass('disabled'); 52 if (!self.previousState.densityPlotDisabled) 53 $('#vis-column .showme .density-plot.button').removeClass('disabled'); 54 if (self.previousState.densityPlotSelected) 55 $('#vis-column .showme .density-plot.button').addClass('selected'); 56 if (!self.previousState.densityPlotSelected) 57 $('#vis-column .showme .density-plot.button').removeClass('selected'); 58 if (self.previousState.trendLinesDisabled) 59 $('#vis-column .showme .trend-lines.button').addClass('disabled'); 60 if (!self.previousState.trendLinesDisabled) 61 $('#vis-column .showme .trend-lines.button').removeClass('disabled'); 62 if (self.previousState.trendLinesSelected) 63 $('#vis-column .showme .trend-lines.button').addClass('selected'); 64 if (!self.previousState.trendLinesSelected) 65 $('#vis-column .showme .trend-lines.button').removeClass('selected'); 66 67 if (ShelfPane.inPreviewMode) 68 self.startPreview(); 69 if (!ShelfPane.inPreviewMode) 70 self.endPreview(); 71 }, 72 73 // preview 74 75 preview: function(visSpec) { 76 if (!('showMe' in visSpec)) { 77 ShowMe.lockDensityPlot(); 78 ShowMe.lockTrendLines(); 79 return; 80 } 81 82 let selectDensityPlot = visSpec.showMe.type == 'density'; 83 let selectTrendLines = visSpec.showMe.type == 'trend'; 84 let isPreview = visSpec.showMe.added; 85 86 if (selectDensityPlot) { 87 ShowMe.lockTrendLines(); 88 ShowMe.unlockDensityPlot(); 89 ShowMe.selectDensityPlot(); 90 } 91 92 if (selectTrendLines) { 93 ShowMe.lockDensityPlot(); 94 ShowMe.unlockTrendLines(); 95 ShowMe.selectTrendLines(); 96 } 97 98 if (isPreview) 99 ShowMe.startPreview(); 100 }, 101 startPreview: function() { 102 $('#vis-column .showme') 103 .addClass('preview'); 104 }, 105 endPreview: function() { 106 $('#vis-column .showme') 107 .removeClass('preview'); 108 }, 109 110 // init 111 112 installMouseEnterButtonBehaviour: function() { 113 $('#vis-column .showme .density-plot.button') 114 .on('mouseenter', onMouseEnterButton) 115 .on('mouseleave', onMouseLeaveButton); 116 $('#vis-column .showme .trend-lines.button') 117 .on('mouseenter', onMouseEnterButton) 118 .on('mouseleave', onMouseLeaveButton); 119 120 function onMouseEnterButton() { 121 let showMePosition = $('#vis-column .showme').position(); 122 let showMeWidth = $('#vis-column .showme').width(); 123 let showMeHeight = $('#vis-column .showme').height(); 124 let isCurrentButtonDensity = $(this).hasClass('density-plot'); 125 let description = ''; 126 127 // determine description 128 if (isCurrentButtonDensity) 129 description = '<div>For <span style="font-weight:bold">Density Plot</span>, you need at least:</div>' + 130 '<div>⢠A quantitative variable</div>' + 131 '<div>⢠A nominal variable (optional)</div>'; 132 if (!isCurrentButtonDensity) 133 description = '<div>To show <span style="font-weight:bold">Trend Lines</span>, you need at least:</div>' + 134 '<div>⢠two quantitative / temporal variables</div>' + 135 '<div>⢠A nominal variable (optional)</div>'; 136 137 // show description 138 $('#vis-column .showme-description') 139 .css('top', showMePosition.top + showMeHeight + 10) 140 .css('left', showMePosition.left) 141 .css('width', showMeWidth - 20) // 20 is padding 142 .html(description) 143 144 $('#vis-column .showme-description') 145 .css('display', 'none') 146 .fadeTo(200, 1) 147 } 148 149 function onMouseLeaveButton() { 150 $('#vis-column .showme-description') 151 .css('display', 'none') 152 .fadeOut(100); 153 } 154 }, 155 installClickDensityPlotButtonBehaviour: function() { 156 $('#vis-column .showme .density-plot.button') 157 .on('click', onClickButton); 158 159 function onClickButton() { 160 let isButtonEnabled = !$(this).hasClass('disabled'); 161 let isButtonSelected = $(this).hasClass('selected'); 162 163 if (isButtonEnabled && isButtonSelected) { 164 if (PreviewMode.isOn) { 165 Shelves.endPreview(); 166 Filters.endPreview(); 167 ShowMe.endPreview(); 168 PreviewMode.off(); 169 } 170 171 $(this).removeClass('selected'); 172 VisualizationPane.showLoader();
173 VisualizationPane.allowUpdating(); 174 VegaliteGenerator.generateSpecification(); // may block vis update 175 VisualizationPane.tryUpdating(); 176 177 DimensionMeasurePaneCapsules.clearAllSelection(); 178 LookAheadEventHandler.listenEvent(); 179 } 180 181 if (isButtonEnabled && !isButtonSelected) { 182 if (PreviewMode.isOn) { 183 Shelves.endPreview(); 184 Filters.endPreview(); 185 ShowMe.endPreview(); 186 PreviewMode.off(); 187 } 188 189 $(this).addClass('selected'); 190 ShowMe.lockTrendLines(); // make sure not both on 191 ShowMeHelpers.adjustSpecForDensityPlot(); 192 VisualizationPane.showLoader(); 193 VisualizationPane.allowUpdating(); 194 VegaliteGenerator.generateSpecification(); // may block vis update 195 VisualizationPane.tryUpdating(); 196 197 DimensionMeasurePaneCapsules.clearAllSelection(); 198 LookAheadEventHandler.listenEvent(); 199 } 200 } 201 }, 202 installClickTrendLineButtonBehaviour: function() { 203 $('#vis-column .showme .trend-lines.button') 204 .on('click', onClickButton); 205 206 function onClickButton() { 207 let isButtonEnabled = !$(this).hasClass('disabled'); 208 let isButtonSelected = $(this).hasClass('selected'); 209 210 if (isButtonEnabled && isButtonSelected) { 211 if (PreviewMode.isOn) { 212 Shelves.endPreview(); 213 Filters.endPreview(); 214 ShowMe.endPreview(); 215 PreviewMode.off(); 216 } 217 218 $(this).removeClass('selected'); 219 VisualizationPane.showLoader(); 220 VisualizationPane.allowUpdating(); 221 VegaliteGenerator.generateSpecification(); // may block vis update 222 VisualizationPane.tryUpdating(); 223 224 DimensionMeasurePaneCapsules.clearAllSelection(); 225 LookAheadEventHandler.listenEvent(); 226 } 227 228 if (isButtonEnabled && !isButtonSelected) { 229 if (PreviewMode.isOn) { 230 Shelves.endPreview(); 231 Filters.endPreview(); 232 ShowMe.endPreview(); 233 PreviewMode.off(); 234 } 235 236 $(this).addClass('selected'); 237 ShowMe.lockDensityPlot(); // make sure not both on 238 ShowMeHelpers.adjustSpecForTrendLines(); 239 VisualizationPane.showLoader(); 240 VisualizationPane.allowUpdating(); 241 VegaliteGenerator.generateSpecification(); // may block vis update 242 VisualizationPane.tryUpdating(); 243 244 DimensionMeasurePaneCapsules.clearAllSelection(); 245 LookAheadEventHandler.listenEvent(); 246 } 247 } 248 }, 249 250 // density plot 251 252 tryUnlockDensityPlot: function() { 253 const self = this; 254 let chosenAttrMatchesDensityPlotReq = ShowMeHelpers.areChosenAttrSatifyDensityPlotReq(); 255 let currentSpecMatchesDensityPlotTemplate = ShowMeHelpers.isCurrentSpecMatchesDensityPlotTemplate(); 256 let densityPlotButtonSelected = self.isDensityPlotSelected(); 257 258 if (densityPlotButtonSelected && currentSpecMatchesDensityPlotTemplate) 259 return; 260 if (chosenAttrMatchesDensityPlotReq) 261 ShowMe.unlockDensityPlot(); 262 if (!chosenAttrMatchesDensityPlotReq) 263 ShowMe.lockDensityPlot(); 264 }, 265 lockDensityPlot: function() { 266 $('#vis-column .showme .density-plot.button') 267 .removeClass('selected') 268 .addClass('disabled'); 269 }, 270 unlockDensityPlot: function() { 271 $('#vis-column .showme .density-plot.button') 272 .removeClass('disabled'); 273 $('#vis-column .showme .density-plot.button') 274 .removeClass('selected'); 275 }, 276 selectDensityPlot: function() { 277 $('#vis-column .showme .density-plot.button') 278 .addClass('selected'); 279 }, 280 isDensityPlotSelected: function() { 281 let isButtonEnabled = !$('#vis-column .showme .density-plot.button').hasClass('disabled') 282 let isButtonSelected = $('#vis-column .showme .density-plot.button').hasClass('selected') 283 284 return isButtonEnabled && isButtonSelected; 285 }, 286 287 // trend lines 288 289 tryUnlockTrendLines: function() { 290 const self = this; 291 let hasSelectedCapsules = DimensionMeasurePaneCapsules.hasSelection(); 292 let chosenAttrMatchesTrendLineReq = ShowMeHelpers.areChosenAttrSatifyTrendLineReq(); 293 let currentSpecMatchesTrendLineTemplate = ShowMeHelpers.isCurrentSpecMatchesTrendLineTemplate(); 294 let trendLineButtonSelected = self.isTrendLinesSelected(); 295 296 if (trendLineButtonSelected && currentSpecMatchesTrendLineTemplate) 297 return; 298 if (chosenAttrMatchesTrendLineReq || (currentSpecMatchesTrendLineTemplate && !hasSelectedCapsules)) 299 ShowMe.unlockTrendLines(); 300 if (!chosenAttrMatchesTrendLineReq && !(currentSpecMatchesTrendLineTemplate && !hasSelectedCapsules)) 301 ShowMe.lockTrendLines(); 302 }, 303 lockTrendLines: function() { 304 $('#vis-column .showme .trend-lines.button') 305 .removeClass('selected') 306 .addClass('disabled'); 307 }, 308 unlockTrendLines: function() { 309 $('#vis-column .showme .trend-lines.button') 310 .removeClass('disabled'); 311 $('#vis-column .showme .trend-lines.button') 312 .removeClass('selected'); 313 }, 314 selectTrendLines: function() { 315 $('#vis-column .showme .trend-lines.button') 316 .addClass('selected'); 317 }, 318 isTrendLinesSelected: function() { 319 let isButtonEnabled = !$('#vis-column .showme .trend-lines.button').hasClass('disabled') 320 let isButtonSelected = $('#vis-column .showme .trend-lines.button').hasClass('selected') 321 322 return isButtonEnabled && isButtonSelected; 323 } 324}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.