File size: 3,201 Bytes
6bda4a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b700c24
 
 
 
 
 
 
 
 
 
 
6bda4a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2fc4361
 
6bda4a6
 
 
 
 
 
2fc4361
 
 
 
 
 
6bda4a6
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware';

/**
 * Store Zustand pour gérer l'état global de DebugUMAP
 */
export const useDebugUMAPStore = create(
  devtools(
    persist(
      (set, get) => ({
      // === État des configurations ===
      configs: [],
      currentConfigIndex: 0,
      loading: false,
      error: null,

      // === État visuel ===
      useCategoryColors: true,
      baseGlyphSize: 0.25,
      darkMode: false,
      showCentroids: true,

      // === État des glyphes ===
      currentFonts: [],
      mappingFunctions: { mapX: null, mapY: null },
      glyphsLoaded: false,

      // === Actions pour les configurations ===
      setConfigs: (configs) => set({ configs }),
      setCurrentConfigIndex: (index) => set({ currentConfigIndex: index }),
      setLoading: (loading) => set({ loading }),
      setError: (error) => set({ error }),
      
      // === Action pour définir un résultat UMAP calculé en direct ===
      setLiveResult: (result) => {
        console.log('📍 Store: Définition du résultat UMAP en direct');
        // Remplace toutes les configs par ce résultat unique
        set({
          configs: [result],
          currentConfigIndex: 0,
          error: null
        });
      },

      // === Actions pour l'état visuel ===
      setUseCategoryColors: (useCategoryColors) => set({ useCategoryColors }),
      setBaseGlyphSize: (baseGlyphSize) => set({ baseGlyphSize }),
      setDarkMode: (darkMode) => set({ darkMode }),
      setShowCentroids: (showCentroids) => set({ showCentroids }),

      // === Actions pour les glyphes ===
      setCurrentFonts: (fonts) => set({ currentFonts: fonts }),
      setMappingFunctions: (functions) => set({ mappingFunctions: functions }),
      setGlyphsLoaded: (loaded) => set({ glyphsLoaded: loaded }),

      // === Actions composites ===
      resetToDefaults: () => set({
        currentConfigIndex: 0,
        useCategoryColors: true,
        baseGlyphSize: 0.25,
        darkMode: false,
        showCentroids: true,
        currentFonts: [],
        mappingFunctions: { mapX: null, mapY: null },
        glyphsLoaded: false,
        error: null
      }),

      // === Getters utiles ===
      getCurrentConfig: () => {
        const { configs, currentConfigIndex } = get();
        return configs[currentConfigIndex] || null;
      },

      getTotalConfigs: () => {
        const { configs } = get();
        return configs.length;
      }
    }),
    {
      name: 'debug-umap-persist',
      version: 2,
      partialize: (state) => ({
        useCategoryColors: state.useCategoryColors,
        baseGlyphSize: state.baseGlyphSize,
        darkMode: state.darkMode,
        showCentroids: state.showCentroids,
      }),
      migrate: (persisted) => ({
        useCategoryColors: persisted?.useCategoryColors ?? true,
        baseGlyphSize: persisted?.baseGlyphSize ?? 0.25,
        darkMode: persisted?.darkMode ?? false,
        showCentroids: persisted?.showCentroids ?? true,
      }),
    }
    ),
    {
      name: 'debug-umap-store', // Nom pour les devtools
    }
  )
);

// Export direct du store pour une utilisation simple