datastake-daf 0.6.265 β†’ 0.6.266

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,185 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import mapboxgl from 'mapbox-gl';
3
+ import 'mapbox-gl/dist/mapbox-gl.css';
4
+ import Style from './style';
5
+
6
+ /**
7
+ * SimpleGlobe - A simplified wrapper for the Globe component
8
+ *
9
+ * This component makes it easy to display project data as pins on a 3D globe.
10
+ * Just pass your project data and it will automatically create pins at the specified locations.
11
+ *
12
+ * @param {Array} projects - Array of project objects with location data
13
+ * @param {string} projects[].name - Project name
14
+ * @param {number} projects[].latitude - Latitude coordinate
15
+ * @param {number} projects[].longitude - Longitude coordinate
16
+ * @param {string} projects[].description - Project description (optional)
17
+ * @param {string} projects[].country - Country code (optional)
18
+ * @param {string} projects[].sectoralScope - Project sector (optional)
19
+ * @param {number} projects[].percentageCompletion - Completion percentage (optional)
20
+ * @param {Object} projects[].author - Author information (optional)
21
+ * @param {Object} mapConfig - Map configuration options (optional)
22
+ * @param {boolean} showSider - Whether to show the sidebar (default: false)
23
+ * @param {Function} onProjectClick - Callback when a project pin is clicked
24
+ */
25
+ const SimpleGlobe = ({
26
+ projects = [],
27
+ mapConfig = {},
28
+ showSider = false,
29
+ onProjectClick = () => {}
30
+ }) => {
31
+ const mapContainer = useRef(null);
32
+ const map = useRef(null);
33
+
34
+ useEffect(() => {
35
+ if (map.current) return; // Initialize map only once
36
+
37
+ console.log('πŸ—ΊοΈ [SIMPLE GLOBE] Creating map...');
38
+
39
+ // Set Mapbox access token
40
+ mapboxgl.accessToken = 'pk.eyJ1IjoicmVkaXM5OTkiLCJhIjoiY2x4YWV5MzA5MmtuZzJpcXM5Y201Z2E2YiJ9.m5bwPg-Tj4Akesl1yQUa3w';
41
+
42
+ // Create map with custom Straatos style
43
+ map.current = new mapboxgl.Map({
44
+ container: mapContainer.current,
45
+ style: 'mapbox://styles/pietragottardo/cm9tt9zfi00d101pg1vdx26si',
46
+ center: [0, 0],
47
+ zoom: mapConfig.maxZoom || 3,
48
+ projection: 'globe',
49
+ attributionControl: false
50
+ });
51
+
52
+ // Add markers when map loads
53
+ map.current.on('load', () => {
54
+ console.log('πŸ—ΊοΈ [SIMPLE GLOBE] Map loaded, adding markers...');
55
+
56
+ // Hide Mapbox logo and attribution completely
57
+ const mapContainer = map.current.getContainer();
58
+ const style = document.createElement('style');
59
+ style.textContent = `
60
+ .mapboxgl-ctrl-logo,
61
+ .mapboxgl-ctrl-attrib,
62
+ .mapboxgl-ctrl-bottom-left,
63
+ .mapboxgl-ctrl-bottom-right {
64
+ display: none !important;
65
+ }
66
+ `;
67
+ document.head.appendChild(style);
68
+
69
+ // Set the space background with stars
70
+ try {
71
+ map.current.setFog({
72
+ 'color': 'rgb(0, 0, 0)',
73
+ 'high-color': 'rgb(0, 0, 0)',
74
+ 'horizon-blend': 0.1,
75
+ 'space-color': 'rgb(0, 0, 0)',
76
+ 'star-intensity': 0.6
77
+ });
78
+ console.log('✨ [SIMPLE GLOBE] Space background with stars set');
79
+ } catch (e) {
80
+ console.log('⚠️ [SIMPLE GLOBE] Could not set fog, trying alternative...');
81
+ // Fallback: try simpler fog configuration
82
+ try {
83
+ map.current.setFog({
84
+ 'color': 'rgb(0, 0, 0)',
85
+ 'high-color': 'rgb(0, 0, 0)',
86
+ 'horizon-blend': 0.1
87
+ });
88
+ console.log('✨ [SIMPLE GLOBE] Alternative space background set');
89
+ } catch (e2) {
90
+ console.log('⚠️ [SIMPLE GLOBE] Could not set any fog configuration');
91
+ }
92
+ }
93
+
94
+ projects.forEach((project, index) => {
95
+ console.log(`πŸ“ [SIMPLE GLOBE] Adding marker ${index}:`, project);
96
+
97
+ // Create marker element
98
+ const el = document.createElement('div');
99
+ el.className = 'mapboxgl-marker';
100
+ el.style.width = '25px';
101
+ el.style.height = '25px';
102
+ el.style.backgroundColor = '#00809E';
103
+ el.style.borderRadius = '50%';
104
+ el.style.border = '2px solid white';
105
+ el.style.cursor = 'pointer';
106
+ el.style.boxShadow = '0px 3.45px 3.45px 0px #00000029';
107
+ el.style.display = 'flex';
108
+ el.style.alignItems = 'center';
109
+ el.style.justifyContent = 'center';
110
+ el.style.color = 'white';
111
+ el.style.fontWeight = 'bold';
112
+ el.style.fontSize = '12px';
113
+ el.innerHTML = `<span>${project.percentageCompletion || 0}</span>`;
114
+
115
+ // Create popup content using the same structure as minesitemap
116
+ const popupContent = `
117
+ <div class="daf-tooltip-cont">
118
+ <div class="daf-tooltip-head">
119
+ <div class="daf-tooltip-title">
120
+ <div>
121
+ <h4>${project.name}</h4>
122
+ <h5>${project.sectoralScope || 'Project'}</h5>
123
+ </div>
124
+ </div>
125
+ </div>
126
+ <div class="daf-tooltip-list">
127
+ <div class="daf-tooltip-list-item">
128
+ <span class="daf-tooltip-name">Country</span>
129
+ <span class="daf-tooltip-value">${project.country || 'N/A'}</span>
130
+ </div>
131
+ <div class="daf-tooltip-list-item">
132
+ <span class="daf-tooltip-name">Completion</span>
133
+ <span class="daf-tooltip-value">${project.percentageCompletion || 0}%</span>
134
+ </div>
135
+ <div class="daf-tooltip-list-item">
136
+ <span class="daf-tooltip-name">Author</span>
137
+ <span class="daf-tooltip-value">${project.author?.name || 'N/A'}</span>
138
+ </div>
139
+ <div class="daf-tooltip-list-item">
140
+ <span class="daf-tooltip-name">ID</span>
141
+ <span class="daf-tooltip-value">${project.datastakeId || 'N/A'}</span>
142
+ </div>
143
+ </div>
144
+ </div>
145
+ `;
146
+
147
+ // Create popup
148
+ const popup = new mapboxgl.Popup({
149
+ offset: 25,
150
+ closeButton: true,
151
+ closeOnClick: false
152
+ }).setHTML(popupContent);
153
+
154
+ // Add marker to map
155
+ const marker = new mapboxgl.Marker(el)
156
+ .setLngLat([project.longitude, project.latitude])
157
+ .setPopup(popup)
158
+ .addTo(map.current);
159
+
160
+ // Add click handler
161
+ el.addEventListener('click', () => {
162
+ console.log('πŸ“ [SIMPLE GLOBE] Marker clicked:', project);
163
+ onProjectClick(project);
164
+ });
165
+
166
+ console.log(`βœ… [SIMPLE GLOBE] Marker ${index} added at:`, [project.longitude, project.latitude]);
167
+ });
168
+ });
169
+
170
+ return () => {
171
+ if (map.current) {
172
+ map.current.remove();
173
+ map.current = null;
174
+ }
175
+ };
176
+ }, [projects, onProjectClick, mapConfig]);
177
+
178
+ return (
179
+ <Style>
180
+ <div ref={mapContainer} style={{ width: '100%', height: '100%' }} />
181
+ </Style>
182
+ );
183
+ };
184
+
185
+ export default SimpleGlobe;
@@ -0,0 +1,174 @@
1
+ import SimpleGlobe from "./SimpleGlobe";
2
+ import SimpleGlobeDebug from "./SimpleGlobeDebug";
3
+ import ThemeLayout from "../../ThemeLayout";
4
+ import Widget from "../Widget";
5
+
6
+ // Sample project data
7
+ const SAMPLE_PROJECTS = [
8
+ {
9
+ _id: "sample-1",
10
+ name: "Dakar Solar Initiative",
11
+ country: "SN",
12
+ datastakeId: "PRJ-SAMPLE-001",
13
+ sectoralScope: "energy",
14
+ percentageCompletion: 75,
15
+ projectDescription: "Large-scale solar energy project in Dakar region",
16
+ latitude: 14.7167,
17
+ longitude: -17.4677,
18
+ author: { name: "Dakar Energy Co." }
19
+ },
20
+ {
21
+ _id: "sample-2",
22
+ name: "Saint-Louis Wind Farm",
23
+ country: "SN",
24
+ datastakeId: "PRJ-SAMPLE-002",
25
+ sectoralScope: "energy",
26
+ percentageCompletion: 45,
27
+ projectDescription: "Wind energy project in Saint-Louis region",
28
+ latitude: 16.0167,
29
+ longitude: -16.4833,
30
+ author: { name: "Wind Power Solutions" }
31
+ },
32
+ {
33
+ _id: "sample-3",
34
+ name: "Casamance Reforestation",
35
+ country: "SN",
36
+ datastakeId: "PRJ-SAMPLE-003",
37
+ sectoralScope: "agricultureForestryAndOtherLandUse",
38
+ percentageCompletion: 60,
39
+ projectDescription: "Forest restoration project in Casamance region",
40
+ latitude: 12.5833,
41
+ longitude: -16.2667,
42
+ author: { name: "Green Casamance" }
43
+ },
44
+ {
45
+ _id: "sample-4",
46
+ name: "Lagos Tech Hub",
47
+ country: "NG",
48
+ datastakeId: "PRJ-SAMPLE-004",
49
+ sectoralScope: "technology",
50
+ percentageCompletion: 30,
51
+ projectDescription: "Technology innovation center in Lagos",
52
+ latitude: 6.5244,
53
+ longitude: 3.3792,
54
+ author: { name: "Lagos Tech Foundation" }
55
+ },
56
+ {
57
+ _id: "sample-5",
58
+ name: "Cairo Water Management",
59
+ country: "EG",
60
+ datastakeId: "PRJ-SAMPLE-005",
61
+ sectoralScope: "water",
62
+ percentageCompletion: 85,
63
+ projectDescription: "Water conservation project in Cairo",
64
+ latitude: 30.0444,
65
+ longitude: 31.2357,
66
+ author: { name: "Cairo Water Authority" }
67
+ }
68
+ ];
69
+
70
+ export default {
71
+ title: "Dashboard/Globe/SimpleGlobe",
72
+ component: SimpleGlobe,
73
+ tags: ["autodocs"],
74
+ args: {
75
+ projects: SAMPLE_PROJECTS,
76
+ showSider: false,
77
+ onProjectClick: (project) => console.log('Project clicked:', project)
78
+ },
79
+ decorators: [
80
+ (Story) => (
81
+ <div style={{ margin: "3em" }}>
82
+ <ThemeLayout>
83
+ <Widget title="Simple Globe with Project Pins" className="no-px no-pb-body">
84
+ <div style={{ width: '100%', height: '600px' }}>
85
+ <Story />
86
+ </div>
87
+ </Widget>
88
+ </ThemeLayout>
89
+ </div>
90
+ ),
91
+ ],
92
+ };
93
+
94
+ export const Default = {
95
+ name: "Default Project Globe",
96
+ args: {
97
+ projects: SAMPLE_PROJECTS,
98
+ showSider: false
99
+ }
100
+ };
101
+
102
+ export const TestSimple = {
103
+ name: "Test Simple Data",
104
+ args: {
105
+ projects: [
106
+ {
107
+ name: "Test Project 1",
108
+ latitude: 14.7167,
109
+ longitude: -17.4677,
110
+ percentageCompletion: 75,
111
+ projectDescription: "Test project in Dakar"
112
+ },
113
+ {
114
+ name: "Test Project 2",
115
+ latitude: 16.0167,
116
+ longitude: -16.4833,
117
+ percentageCompletion: 45,
118
+ projectDescription: "Test project in Saint-Louis"
119
+ }
120
+ ],
121
+ showSider: true
122
+ }
123
+ };
124
+
125
+ export const WithSidebar = {
126
+ name: "With Sidebar",
127
+ args: {
128
+ projects: SAMPLE_PROJECTS,
129
+ showSider: true
130
+ }
131
+ };
132
+
133
+ export const CustomMapConfig = {
134
+ name: "Custom Map Configuration",
135
+ args: {
136
+ projects: SAMPLE_PROJECTS,
137
+ showSider: true,
138
+ mapConfig: {
139
+ maxZoom: 6,
140
+ minZoom: 2
141
+ }
142
+ }
143
+ };
144
+
145
+ export const SingleProject = {
146
+ name: "Single Project",
147
+ args: {
148
+ projects: [SAMPLE_PROJECTS[0]],
149
+ showSider: true
150
+ }
151
+ };
152
+
153
+ export const EmptyState = {
154
+ name: "Empty State",
155
+ args: {
156
+ projects: [],
157
+ showSider: false
158
+ }
159
+ };
160
+
161
+ export const DebugVersion = {
162
+ name: "Debug Version (Direct Mapbox)",
163
+ render: () => (
164
+ <div style={{ margin: "3em" }}>
165
+ <ThemeLayout>
166
+ <Widget title="Debug Globe (Direct Mapbox)" className="no-px no-pb-body">
167
+ <div style={{ width: '100%', height: '600px' }}>
168
+ <SimpleGlobeDebug projects={SAMPLE_PROJECTS} />
169
+ </div>
170
+ </Widget>
171
+ </ThemeLayout>
172
+ </div>
173
+ )
174
+ };
@@ -0,0 +1,85 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import mapboxgl from 'mapbox-gl';
3
+ import 'mapbox-gl/dist/mapbox-gl.css';
4
+
5
+ const SimpleGlobeDebug = ({ projects = [] }) => {
6
+ const mapContainer = useRef(null);
7
+ const map = useRef(null);
8
+
9
+ useEffect(() => {
10
+ if (map.current) return; // Initialize map only once
11
+
12
+ // Set Mapbox access token
13
+ mapboxgl.accessToken = 'pk.eyJ1IjoicmVkaXM5OTkiLCJhIjoiY2x4YWV5MzA5MmtuZzJpcXM5Y201Z2E2YiJ9.m5bwPg-Tj4Akesl1yQUa3w';
14
+
15
+ console.log('πŸ—ΊοΈ [DEBUG] Creating map...');
16
+
17
+ // Create map
18
+ map.current = new mapboxgl.Map({
19
+ container: mapContainer.current,
20
+ style: 'mapbox://styles/mapbox/satellite-v9',
21
+ center: [0, 0],
22
+ zoom: 3,
23
+ projection: 'globe'
24
+ });
25
+
26
+ // Add markers when map loads
27
+ map.current.on('load', () => {
28
+ console.log('πŸ—ΊοΈ [DEBUG] Map loaded, adding markers...');
29
+
30
+ projects.forEach((project, index) => {
31
+ console.log(`πŸ“ [DEBUG] Adding marker ${index}:`, project);
32
+
33
+ // Create marker element
34
+ const el = document.createElement('div');
35
+ el.className = 'mapboxgl-marker';
36
+ el.style.width = '20px';
37
+ el.style.height = '20px';
38
+ el.style.backgroundColor = '#00809E';
39
+ el.style.borderRadius = '50%';
40
+ el.style.border = '2px solid white';
41
+ el.style.cursor = 'pointer';
42
+ el.style.boxShadow = '0px 3.45px 3.45px 0px #00000029';
43
+ el.style.display = 'flex';
44
+ el.style.alignItems = 'center';
45
+ el.style.justifyContent = 'center';
46
+ el.style.color = 'white';
47
+ el.style.fontWeight = 'bold';
48
+ el.innerHTML = `<span>${project.percentageCompletion || 0}</span>`;
49
+
50
+ // Create popup
51
+ const popup = new mapboxgl.Popup({ offset: 25 })
52
+ .setHTML(`
53
+ <div>
54
+ <h3>${project.name}</h3>
55
+ <p>${project.projectDescription || 'No description'}</p>
56
+ <p>Completion: ${project.percentageCompletion || 0}%</p>
57
+ </div>
58
+ `);
59
+
60
+ // Add marker to map
61
+ new mapboxgl.Marker(el)
62
+ .setLngLat([project.longitude, project.latitude])
63
+ .setPopup(popup)
64
+ .addTo(map.current);
65
+
66
+ console.log(`βœ… [DEBUG] Marker ${index} added at:`, [project.longitude, project.latitude]);
67
+ });
68
+ });
69
+
70
+ return () => {
71
+ if (map.current) {
72
+ map.current.remove();
73
+ map.current = null;
74
+ }
75
+ };
76
+ }, []);
77
+
78
+ return (
79
+ <div style={{ width: '100%', height: '600px', border: '2px solid #ccc' }}>
80
+ <div ref={mapContainer} style={{ width: '100%', height: '100%' }} />
81
+ </div>
82
+ );
83
+ };
84
+
85
+ export default SimpleGlobeDebug;
@@ -0,0 +1,75 @@
1
+ import React from 'react';
2
+ import SimpleGlobe from './SimpleGlobe';
3
+
4
+ // Your sample project data
5
+ const SAMPLE_PROJECTS = [
6
+ {
7
+ _id: "sample-1",
8
+ name: "Dakar Solar Initiative",
9
+ country: "SN",
10
+ datastakeId: "PRJ-SAMPLE-001",
11
+ sectoralScope: "energy",
12
+ percentageCompletion: 75,
13
+ projectDescription: "Large-scale solar energy project in Dakar region",
14
+ latitude: 14.7167,
15
+ longitude: -17.4677,
16
+ author: { name: "Dakar Energy Co." }
17
+ },
18
+ {
19
+ _id: "sample-2",
20
+ name: "Saint-Louis Wind Farm",
21
+ country: "SN",
22
+ datastakeId: "PRJ-SAMPLE-002",
23
+ sectoralScope: "energy",
24
+ percentageCompletion: 45,
25
+ projectDescription: "Wind energy project in Saint-Louis region",
26
+ latitude: 16.0167,
27
+ longitude: -16.4833,
28
+ author: { name: "Wind Power Solutions" }
29
+ },
30
+ {
31
+ _id: "sample-3",
32
+ name: "Casamance Reforestation",
33
+ country: "SN",
34
+ datastakeId: "PRJ-SAMPLE-003",
35
+ sectoralScope: "agricultureForestryAndOtherLandUse",
36
+ percentageCompletion: 60,
37
+ projectDescription: "Forest restoration project in Casamance region",
38
+ latitude: 12.5833,
39
+ longitude: -16.2667,
40
+ author: { name: "Green Casamance" }
41
+ }
42
+ ];
43
+
44
+ /**
45
+ * SimpleGlobeExample - Example usage of the SimpleGlobe component
46
+ *
47
+ * This shows how easy it is to display your project data as pins on a 3D globe.
48
+ * Just pass your project array to the SimpleGlobe component!
49
+ */
50
+ const SimpleGlobeExample = () => {
51
+ const handleProjectClick = (projectData) => {
52
+ console.log('Project clicked:', projectData);
53
+ // You can add your custom logic here, like:
54
+ // - Navigate to project details page
55
+ // - Show project information in a modal
56
+ // - Update application state
57
+ alert(`Clicked on: ${projectData.name}\nCompletion: ${projectData.percentageCompletion}%`);
58
+ };
59
+
60
+ return (
61
+ <div style={{ width: '100%', height: '600px' }}>
62
+ <SimpleGlobe
63
+ projects={SAMPLE_PROJECTS}
64
+ showSider={true}
65
+ onProjectClick={handleProjectClick}
66
+ mapConfig={{
67
+ maxZoom: 8,
68
+ minZoom: 2
69
+ }}
70
+ />
71
+ </div>
72
+ );
73
+ };
74
+
75
+ export default SimpleGlobeExample;
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import SimpleGlobe from './SimpleGlobe';
3
+
4
+ // Test with a simple, known working dataset
5
+ const TEST_PROJECTS = [
6
+ {
7
+ _id: "test-1",
8
+ name: "Test Project 1",
9
+ latitude: 14.7167,
10
+ longitude: -17.4677,
11
+ percentageCompletion: 75,
12
+ projectDescription: "Test project in Dakar"
13
+ },
14
+ {
15
+ _id: "test-2",
16
+ name: "Test Project 2",
17
+ latitude: 16.0167,
18
+ longitude: -16.4833,
19
+ percentageCompletion: 45,
20
+ projectDescription: "Test project in Saint-Louis"
21
+ }
22
+ ];
23
+
24
+ const SimpleGlobeTest = () => {
25
+ console.log('πŸ§ͺ [SIMPLE GLOBE TEST] Test projects:', TEST_PROJECTS);
26
+
27
+ const handleProjectClick = (projectData) => {
28
+ console.log('πŸ§ͺ [SIMPLE GLOBE TEST] Project clicked:', projectData);
29
+ alert(`Clicked: ${projectData.name} at ${projectData.gps?.latitude}, ${projectData.gps?.longitude}`);
30
+ };
31
+
32
+ return (
33
+ <div style={{ width: '100%', height: '600px', border: '2px solid #ccc' }}>
34
+ <h3>SimpleGlobe Test</h3>
35
+ <SimpleGlobe
36
+ projects={TEST_PROJECTS}
37
+ showSider={true}
38
+ onProjectClick={handleProjectClick}
39
+ mapConfig={{
40
+ maxZoom: 8,
41
+ minZoom: 2
42
+ }}
43
+ />
44
+ </div>
45
+ );
46
+ };
47
+
48
+ export default SimpleGlobeTest;