Skip to content

Commit 550998e

Browse files
committed
Fix logging of clicks
1 parent 903e38c commit 550998e

2 files changed

Lines changed: 27 additions & 18 deletions

File tree

client/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ function initEventListeners() {
10951095
const currentState = store.getState();
10961096
render(els, currentState);
10971097
applyVisibility(currentState);
1098+
activityLogger.logCellClick(currentState, 'twoWayTable');
10981099
});
10991100

11001101
els.heatmap.addEventListener('click', (event) => {
@@ -1124,6 +1125,7 @@ function initEventListeners() {
11241125
const updatedState = store.getState();
11251126
render(els, updatedState);
11261127
applyVisibility(updatedState);
1128+
activityLogger.logCellClick(updatedState, 'jointDistributionHeatmap');
11271129
});
11281130

11291131
window.addEventListener('resize', () => {

client/src/shell/activity-logger.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -223,24 +223,6 @@ function buildTwoStatus(state) {
223223
relationship: state.two.relationship ?? null,
224224
};
225225

226-
if (state.two.selectedCell) {
227-
const r = state.two.selectedCell.r;
228-
const c = state.two.selectedCell.c;
229-
const selectedCell = { r, c };
230-
if (trials > 0) {
231-
const jointCount = joint[r]?.[c] ?? 0;
232-
const pJoint = jointCount / trials;
233-
const pA = (countsA[r] ?? 0) / trials;
234-
const pB = (countsB[c] ?? 0) / trials;
235-
selectedCell.pJoint = pJoint;
236-
selectedCell.pA = pA;
237-
selectedCell.pB = pB;
238-
selectedCell.pAGivenB = pB > 0 ? pJoint / pB : null;
239-
selectedCell.pBGivenA = pA > 0 ? pJoint / pA : null;
240-
}
241-
data.selectedCell = selectedCell;
242-
}
243-
244226
const sections = normalizeSections(state.sections);
245227
if (sections.jointDistribution) {
246228
data.jointDistribution = {
@@ -325,10 +307,35 @@ export function createActivityLogger() {
325307
lastTrials = trials;
326308
}
327309

310+
function logCellClick(state, source) {
311+
if (state.mode !== 'two') return;
312+
if (!state.two.selectedCell) return;
313+
314+
const defA = state.two.definitionA;
315+
const defB = state.two.definitionB;
316+
if (!defA || !defB) return;
317+
318+
const r = state.two.selectedCell.r;
319+
const c = state.two.selectedCell.c;
320+
321+
postEvent({
322+
type: 'click',
323+
data: {
324+
source,
325+
cell: { r, c },
326+
labels: {
327+
a: defA.labels[r] ?? null,
328+
b: defB.labels[c] ?? null,
329+
},
330+
},
331+
});
332+
}
333+
328334
return {
329335
logAppStart,
330336
logSettingsChange,
331337
logRunReset,
332338
maybeLogStatus,
339+
logCellClick,
333340
};
334341
}

0 commit comments

Comments
 (0)