Skip to content

Commit f46e662

Browse files
Refactor code
1 parent 931ea35 commit f46e662

2 files changed

Lines changed: 68 additions & 54 deletions

File tree

app.js

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,6 @@
141141
temporalInsights: [],
142142
temporalFocus: null,
143143
nextSessionId: 1,
144-
activeCompassLens: "movement",
145-
activeLensPreset: "",
146-
shellFilter: null,
147-
shellFilterEnabled: false,
148-
constellationZoom: 1,
149-
constellationPanX: 0,
150-
constellationPanY: 0,
151144
replayingSessionId: 0
152145
};
153146

@@ -745,13 +738,13 @@
745738
runtimeState.queryNarrative = "Session cleared. Restoring the default Impressionism opening scene.";
746739
runtimeState.temporalInsights = [];
747740
runtimeState.temporalFocus = null;
748-
runtimeState.activeLensPreset = "";
749-
runtimeState.activeCompassLens = "movement";
750-
runtimeState.shellFilterEnabled = false;
741+
browserAdapterState.activeLensPreset = "";
742+
browserAdapterState.activeCompassLens = "movement";
743+
browserAdapterState.shellFilterEnabled = false;
751744
runtimeState.multilingualEntityLabels = {};
752-
runtimeState.constellationZoom = 1;
753-
runtimeState.constellationPanX = 0;
754-
runtimeState.constellationPanY = 0;
745+
browserAdapterState.constellationZoom = 1;
746+
browserAdapterState.constellationPanX = 0;
747+
browserAdapterState.constellationPanY = 0;
755748
buildShellFilter();
756749
setActiveButton(modeButtons, modeButtons.find((button) => button.dataset.mode === "observatory"));
757750
renderConstellationZoomControls();
@@ -1438,11 +1431,11 @@
14381431
}
14391432

14401433
function selectedLensConfig(languageCode) {
1441-
const activePreset = runtimeState.activeLensPreset;
1434+
const activePreset = browserAdapterState.activeLensPreset;
14421435
if (activePreset && lensPresetContent[activePreset]) {
14431436
return lensPresetContent[activePreset][languageCode] || lensPresetContent[activePreset].en;
14441437
}
1445-
const activeLens = runtimeState.activeCompassLens || "movement";
1438+
const activeLens = browserAdapterState.activeCompassLens || "movement";
14461439
return (compassLensContent[activeLens] && (compassLensContent[activeLens][languageCode] || compassLensContent[activeLens].en)) || null;
14471440
}
14481441

@@ -1484,7 +1477,7 @@
14841477
}
14851478

14861479
function getEffectiveLensKey() {
1487-
const preset = runtimeState.activeLensPreset;
1480+
const preset = browserAdapterState.activeLensPreset;
14881481
if (preset === "lineage") {
14891482
return "influence";
14901483
}
@@ -1497,24 +1490,24 @@
14971490
if (preset === "cross-language") {
14981491
return "";
14991492
}
1500-
if (!runtimeState.shellFilterEnabled) {
1493+
if (!browserAdapterState.shellFilterEnabled) {
15011494
return "";
15021495
}
1503-
return runtimeState.activeCompassLens || "movement";
1496+
return browserAdapterState.activeCompassLens || "movement";
15041497
}
15051498

15061499
function buildShellFilter() {
1507-
const preset = runtimeState.activeLensPreset || "";
1500+
const preset = browserAdapterState.activeLensPreset || "";
15081501
const effectiveLens = getEffectiveLensKey();
1509-
runtimeState.shellFilter = {
1510-
lens: runtimeState.activeCompassLens || "",
1502+
browserAdapterState.shellFilter = {
1503+
lens: browserAdapterState.activeCompassLens || "",
15111504
preset,
15121505
effectiveLens
15131506
};
15141507
}
15151508

15161509
function nodeMatchesShellFilter(node, snapshot) {
1517-
const filter = runtimeState.shellFilter;
1510+
const filter = browserAdapterState.shellFilter;
15181511
if (!filter || (!filter.effectiveLens && !filter.preset)) {
15191512
return true;
15201513
}
@@ -1531,7 +1524,7 @@
15311524
}
15321525

15331526
function relationMatchesShellFilter(relation, visibleNodeIds) {
1534-
const filter = runtimeState.shellFilter;
1527+
const filter = browserAdapterState.shellFilter;
15351528
if (!filter || (!filter.effectiveLens && !filter.preset)) {
15361529
return true;
15371530
}
@@ -1607,7 +1600,7 @@
16071600
const legendEl = document.getElementById("constellation-legend");
16081601
if (!legendEl) return;
16091602
const selectedType = String((runtimeState.selectedEntity && runtimeState.selectedEntity.type) || "").toLowerCase();
1610-
const lens = runtimeState.activeCompassLens || "movement";
1603+
const lens = browserAdapterState.activeCompassLens || "movement";
16111604
const labels = getLegendLabels(selectedType, lens);
16121605
const set = (id, text) => { const el = document.getElementById(id); if (el) el.textContent = text || ""; };
16131606
set("legend-top", labels.top);
@@ -1626,7 +1619,7 @@
16261619
function updateCompassCore() {
16271620
const coreEl = document.querySelector(".compass-core");
16281621
if (!coreEl) return;
1629-
const activeLens = runtimeState.activeCompassLens || "movement";
1622+
const activeLens = browserAdapterState.activeCompassLens || "movement";
16301623
const entity = runtimeState.selectedEntity;
16311624

16321625
const labelEl = coreEl.querySelector(".compass-core-label");
@@ -1653,9 +1646,9 @@
16531646
}
16541647

16551648
function renderLensControls() {
1656-
const hasPreset = Boolean(runtimeState.activeLensPreset);
1649+
const hasPreset = Boolean(browserAdapterState.activeLensPreset);
16571650
compassPoleButtons.forEach((button) => {
1658-
const isActive = !hasPreset && button.dataset.lens === runtimeState.activeCompassLens;
1651+
const isActive = !hasPreset && button.dataset.lens === browserAdapterState.activeCompassLens;
16591652
button.classList.toggle("is-active", isActive);
16601653
button.classList.toggle("is-muted", hasPreset);
16611654
button.classList.toggle("is-primary", isActive);
@@ -1668,7 +1661,7 @@
16681661
}
16691662
});
16701663
lensPresetButtons.forEach((button) => {
1671-
const isActive = button.dataset.preset === runtimeState.activeLensPreset;
1664+
const isActive = button.dataset.preset === browserAdapterState.activeLensPreset;
16721665
button.classList.toggle("is-active", isActive);
16731666
button.classList.toggle("is-muted", !isActive && hasPreset);
16741667
});
@@ -1687,9 +1680,9 @@
16871680
}
16881681

16891682
async function applyShellLens(lens, preset = "", enableFilter = true) {
1690-
runtimeState.activeCompassLens = lens || runtimeState.activeCompassLens || "movement";
1691-
runtimeState.activeLensPreset = preset;
1692-
runtimeState.shellFilterEnabled = enableFilter;
1683+
browserAdapterState.activeCompassLens = lens || browserAdapterState.activeCompassLens || "movement";
1684+
browserAdapterState.activeLensPreset = preset;
1685+
browserAdapterState.shellFilterEnabled = enableFilter;
16931686
buildShellFilter();
16941687
renderLensControls();
16951688
updateLensNarrative();
@@ -1887,9 +1880,9 @@
18871880
}
18881881

18891882
function renderConstellationZoomControls() {
1890-
const zoom = runtimeState.constellationZoom || 1;
1891-
const panX = runtimeState.constellationPanX || 0;
1892-
const panY = runtimeState.constellationPanY || 0;
1883+
const zoom = browserAdapterState.constellationZoom || 1;
1884+
const panX = browserAdapterState.constellationPanX || 0;
1885+
const panY = browserAdapterState.constellationPanY || 0;
18931886
const transform = "translate(" + panX + "px, " + panY + "px) scale(" + zoom + ")";
18941887
if (constellationLinksEl) {
18951888
constellationLinksEl.style.transform = transform;
@@ -1917,7 +1910,7 @@
19171910
function renderConstellationMinimap() {
19181911
const canvas = document.getElementById("constellation-minimap");
19191912
if (!canvas) return;
1920-
const zoom = runtimeState.constellationZoom || 1;
1913+
const zoom = browserAdapterState.constellationZoom || 1;
19211914
const isVisible = zoom > 1.05;
19221915
canvas.classList.toggle("is-visible", isVisible);
19231916
if (!isVisible) return;
@@ -1961,8 +1954,8 @@
19611954
const constellationEl = document.querySelector(".constellation");
19621955
if (constellationEl) {
19631956
const cRect = constellationEl.getBoundingClientRect();
1964-
const panX = runtimeState.constellationPanX || 0;
1965-
const panY = runtimeState.constellationPanY || 0;
1957+
const panX = browserAdapterState.constellationPanX || 0;
1958+
const panY = browserAdapterState.constellationPanY || 0;
19661959
const panXPct = panX / cRect.width * 100;
19671960
const panYPct = panY / cRect.height * 100;
19681961
const xMin = Math.max(0, 50 + (-50 - panXPct) / zoom);
@@ -1976,7 +1969,7 @@
19761969
}
19771970

19781971
function setConstellationZoom(nextZoom) {
1979-
runtimeState.constellationZoom = clamp(nextZoom, 0.3, 2.5);
1972+
browserAdapterState.constellationZoom = clamp(nextZoom, 0.3, 2.5);
19801973
renderConstellationZoomControls();
19811974
}
19821975

@@ -2678,7 +2671,14 @@
26782671
graphe: {
26792672
noeuds: new Map(),
26802673
relations: []
2681-
}
2674+
},
2675+
activeCompassLens: "movement",
2676+
activeLensPreset: "",
2677+
shellFilterEnabled: false,
2678+
shellFilter: null,
2679+
constellationZoom: 1,
2680+
constellationPanX: 0,
2681+
constellationPanY: 0
26822682
};
26832683

26842684
if (chronologyLoadMoreEl) {
@@ -2711,20 +2711,20 @@
27112711

27122712
if (constellationZoomOutEl) {
27132713
constellationZoomOutEl.addEventListener("click", () => {
2714-
setConstellationZoom((runtimeState.constellationZoom || 1) - 0.2);
2714+
setConstellationZoom((browserAdapterState.constellationZoom || 1) - 0.2);
27152715
});
27162716
}
27172717

27182718
if (constellationZoomInEl) {
27192719
constellationZoomInEl.addEventListener("click", () => {
2720-
setConstellationZoom((runtimeState.constellationZoom || 1) + 0.2);
2720+
setConstellationZoom((browserAdapterState.constellationZoom || 1) + 0.2);
27212721
});
27222722
}
27232723

27242724
if (constellationZoomResetEl) {
27252725
constellationZoomResetEl.addEventListener("click", () => {
2726-
runtimeState.constellationPanX = 0;
2727-
runtimeState.constellationPanY = 0;
2726+
browserAdapterState.constellationPanX = 0;
2727+
browserAdapterState.constellationPanY = 0;
27282728
setConstellationZoom(1);
27292729
});
27302730
}
@@ -2740,7 +2740,7 @@
27402740
e.preventDefault();
27412741
const step = 0.15;
27422742
const delta = e.deltaY > 0 ? -step : step;
2743-
setConstellationZoom((runtimeState.constellationZoom || 1) + delta);
2743+
setConstellationZoom((browserAdapterState.constellationZoom || 1) + delta);
27442744
}, { passive: false });
27452745

27462746
let isPanning = false;
@@ -2754,8 +2754,8 @@
27542754
panStart = {
27552755
x: e.clientX,
27562756
y: e.clientY,
2757-
panX: runtimeState.constellationPanX || 0,
2758-
panY: runtimeState.constellationPanY || 0
2757+
panX: browserAdapterState.constellationPanX || 0,
2758+
panY: browserAdapterState.constellationPanY || 0
27592759
};
27602760
constellationEl.setPointerCapture(e.pointerId);
27612761
constellationEl.classList.add("is-panning");
@@ -2768,8 +2768,8 @@
27682768
}
27692769
const rect = constellationEl.getBoundingClientRect();
27702770
const maxPan = Math.max(rect.width, rect.height) * 0.6;
2771-
runtimeState.constellationPanX = Math.max(-maxPan, Math.min(maxPan, panStart.panX + (e.clientX - panStart.x)));
2772-
runtimeState.constellationPanY = Math.max(-maxPan, Math.min(maxPan, panStart.panY + (e.clientY - panStart.y)));
2771+
browserAdapterState.constellationPanX = Math.max(-maxPan, Math.min(maxPan, panStart.panX + (e.clientX - panStart.x)));
2772+
browserAdapterState.constellationPanY = Math.max(-maxPan, Math.min(maxPan, panStart.panY + (e.clientY - panStart.y)));
27732773
renderConstellationZoomControls();
27742774
});
27752775

@@ -2981,7 +2981,13 @@
29812981
total_noeuds: browserAdapterState.graphe.noeuds.size,
29822982
total_relations: browserAdapterState.graphe.relations.length
29832983
}
2984-
}
2984+
},
2985+
lentille_compas: browserAdapterState.activeCompassLens,
2986+
preset_lentille: browserAdapterState.activeLensPreset,
2987+
filtre_actif: browserAdapterState.shellFilterEnabled,
2988+
zoom_constellation: browserAdapterState.constellationZoom,
2989+
pan_constellation_x: browserAdapterState.constellationPanX,
2990+
pan_constellation_y: browserAdapterState.constellationPanY
29852991
};
29862992
}
29872993

@@ -3202,7 +3208,7 @@
32023208

32033209
function semanticLayoutSectors(selectedNode, nodes, relationByTarget, relationBySource) {
32043210
const selectedType = String((selectedNode && selectedNode.type) || "").toLowerCase();
3205-
const activeLens = runtimeState.activeCompassLens || "movement";
3211+
const activeLens = browserAdapterState.activeCompassLens || "movement";
32063212

32073213
const sectors = {
32083214
primary: { start: -150, end: 150, nodes: [], radii: [22, 32, 41, 47] },
@@ -3524,7 +3530,7 @@
35243530
const nodeEl = document.createElement("button");
35253531
nodeEl.type = "button";
35263532
nodeEl.dataset.nodeId = node.id;
3527-
nodeEl.className = "node " + constellationClassForType(node.type) + (node.id === selectedId ? " is-selected" : "") + (isContextDetail ? " is-context-detail" : "") + (snapshot.affichage_chargement && node.id === runtimeState.lastRequestedEntityId ? " is-loading" : "") + (isTemporalFocus ? " is-temporal-focus" : "") + (isMutedTemporally ? " is-muted-temporal" : "") + (runtimeState.shellFilter && runtimeState.shellFilter.effectiveLens && isFilterFocus ? " is-filter-focus" : "");
3533+
nodeEl.className = "node " + constellationClassForType(node.type) + (node.id === selectedId ? " is-selected" : "") + (isContextDetail ? " is-context-detail" : "") + (snapshot.affichage_chargement && node.id === runtimeState.lastRequestedEntityId ? " is-loading" : "") + (isTemporalFocus ? " is-temporal-focus" : "") + (isMutedTemporally ? " is-muted-temporal" : "") + (browserAdapterState.shellFilter && browserAdapterState.shellFilter.effectiveLens && isFilterFocus ? " is-filter-focus" : "");
35283534
nodeEl.style.left = position.x + "%";
35293535
nodeEl.style.top = position.y + "%";
35303536
const degree = nodeDegree.get(node.id) || 0;
@@ -4318,11 +4324,11 @@
43184324
lensPresetButtons.forEach((button) => {
43194325
button.addEventListener("click", async () => {
43204326
const preset = button.dataset.preset || "";
4321-
if (runtimeState.activeLensPreset === preset) {
4322-
await applyShellLens(runtimeState.activeCompassLens || "movement", "", false);
4327+
if (browserAdapterState.activeLensPreset === preset) {
4328+
await applyShellLens(browserAdapterState.activeCompassLens || "movement", "", false);
43234329
return;
43244330
}
4325-
await applyShellLens(runtimeState.activeCompassLens || "movement", preset, true);
4331+
await applyShellLens(browserAdapterState.activeCompassLens || "movement", preset, true);
43264332
});
43274333
});
43284334

src/ui/etat.multi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ observer var mode_langue_actif = "fr" # "fr" ou "en"
3434
observer var afficher_surfaces_paralleles = vrai # afficher cote a cote ou par onglets
3535
observer var entite_multilingue_focus = "" # id de l'entite en focus pour polyglot-studio
3636

37+
# Etat de la visualisation constellation (compas, zoom, panoramique)
38+
observer var lentille_compas = "movement"
39+
observer var preset_lentille = ""
40+
observer var filtre_actif = faux
41+
observer var zoom_constellation = 1
42+
observer var pan_constellation_x = 0
43+
observer var pan_constellation_y = 0
44+
3745
# Etat de pagination curseur pour le chargement progressif
3846
observer var curseur_artistes_mouvement = ""
3947
observer var a_page_suivante_artistes_mouvement = faux

0 commit comments

Comments
 (0)