Skip to content

Commit 76390c9

Browse files
committed
fix(topic-modeling): make top words slider functional
Previously slider only updated display value but didn't affect visualization. Now reads slider value in showTopicWordBars and createTopicCard, and updates visualization when slider changes
1 parent 4db5d35 commit 76390c9

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

demos/topic-modeling/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ <h3>Statistics</h3>
257257
const valueDisplay = document.getElementById(valueId);
258258
slider.addEventListener('input', (e) => {
259259
valueDisplay.textContent = e.target.value;
260+
261+
if (sliderId === 'top-words' && app.currentResults) {
262+
const viewMode = document.getElementById('view-mode').value;
263+
if (viewMode === 'overview') {
264+
app.visualizer.renderOverview(app.currentResults);
265+
} else if (viewMode === 'intertopic') {
266+
const topicIdx = parseInt(document.getElementById('selected-topic').value) || 0;
267+
app.visualizer.showTopicWordBars(topicIdx === 'all' ? 0 : topicIdx, app.currentResults);
268+
}
269+
}
260270
});
261271
}
262272

demos/topic-modeling/js/visualization.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,14 @@ export class TopicVisualizer {
5151
});
5252
}
5353

54-
/**
55-
* Create a topic card element
56-
*/
5754
createTopicCard(topic, topicIdx, results) {
5855
const card = document.createElement('div');
5956
card.className = 'topic-card';
6057
card.style.borderLeftColor = this.colors[topicIdx % this.colors.length];
6158
card.style.borderLeftWidth = '4px';
6259

63-
const topWords = topic.slice(0, 10);
60+
const topWordsCount = parseInt(document.getElementById('top-words')?.value || 10);
61+
const topWords = topic.slice(0, topWordsCount);
6462

6563
// Count documents where this is the dominant topic
6664
let dominantCount = 0;
@@ -396,11 +394,9 @@ export class TopicVisualizer {
396394
return coords;
397395
}
398396

399-
/**
400-
* Show top words for a topic as horizontal bars
401-
*/
402397
showTopicWordBars(topicIdx, results) {
403-
const topic = results.topics[topicIdx].slice(0, 15);
398+
const topWordsCount = parseInt(document.getElementById('top-words')?.value || 10);
399+
const topic = results.topics[topicIdx].slice(0, topWordsCount);
404400

405401
const trace = {
406402
y: topic.map(w => w.word).reverse(),

0 commit comments

Comments
 (0)