forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkEffect.tsx
More file actions
229 lines (213 loc) 路 6.23 KB
/
Copy pathNetworkEffect.tsx
File metadata and controls
229 lines (213 loc) 路 6.23 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
'use client';
import React, { useMemo, useState } from 'react';
import { Line } from 'react-chartjs-2';
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
PointElement,
LineElement,
Title,
Tooltip,
Legend,
} from 'chart.js';
import {
calculateValuePerUser,
metcalfeLawCurve,
detectCriticalMass,
calculateGeographicDensity,
calculateNetworkStrength,
} from '../../lib/network-metrics';
ChartJS.register(
CategoryScale,
LinearScale,
PointElement,
LineElement,
Title,
Tooltip,
Legend
);
interface NetworkEffectProps {
users: number[];
activity: number[];
timestamps: string[];
geographicData?: {
locations: Array<{
region: string;
userCount: number;
activityLevel: number;
}>;
};
}
export default function NetworkEffect({
users,
activity,
timestamps,
geographicData,
}: NetworkEffectProps) {
const [selectedMetric, setSelectedMetric] = useState<'value' | 'metcalfe'>('value');
const metrics = useMemo(() => {
const valuePerUser = calculateValuePerUser(users, activity);
const metcalfeValues = metcalfeLawCurve(users);
const criticalMassIndex = detectCriticalMass(valuePerUser);
const geographicDensity = geographicData
? calculateGeographicDensity(geographicData)
: {};
const networkStrength = calculateNetworkStrength({
valuePerUser,
metcalfeValues,
criticalMassIndex,
geographicDensity,
});
return {
valuePerUser,
metcalfeValues,
criticalMassIndex,
geographicDensity,
networkStrength,
};
}, [users, activity, geographicData]);
const chartData = useMemo(() => {
const datasets = [];
if (selectedMetric === 'value') {
datasets.push({
label: 'Value per User',
data: metrics.valuePerUser,
borderColor: 'rgb(75, 192, 192)',
backgroundColor: 'rgba(75, 192, 192, 0.5)',
tension: 0.3,
});
} else {
datasets.push({
label: 'Metcalfe Law Curve',
data: metrics.metcalfeValues,
borderColor: 'rgb(255, 99, 132)',
backgroundColor: 'rgba(255, 99, 132, 0.5)',
tension: 0.3,
});
}
if (metrics.criticalMassIndex !== null) {
datasets.push({
label: 'Critical Mass',
data: metrics.valuePerUser.map((_, index) =>
index === metrics.criticalMassIndex ? metrics.valuePerUser[index] : null
),
borderColor: 'rgb(255, 205, 86)',
backgroundColor: 'rgba(255, 205, 86, 0.8)',
pointRadius: 10,
pointHoverRadius: 15,
showLine: false,
});
}
return {
labels: timestamps,
datasets,
};
}, [metrics, selectedMetric, timestamps]);
const chartOptions = {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top' as const,
},
title: {
display: true,
text: 'Network Effect Visualization',
},
tooltip: {
callbacks: {
afterLabel: function (context: any) {
if (context.dataset.label === 'Critical Mass') {
return 'Inflection Point - Network effect accelerating';
}
return '';
},
},
},
},
scales: {
y: {
display: true,
title: {
display: true,
text: selectedMetric === 'value' ? 'Value per User' : 'Metcalfe Value',
},
},
x: {
display: true,
title: {
display: true,
text: 'Time',
},
},
},
};
return (
<div style={{ padding: '20px', backgroundColor: '#ffffff', borderRadius: '8px' }}>
<div style={{ marginBottom: '20px' }}>
<div style={{ display: 'flex', gap: '10px', marginBottom: '10px' }}>
<button
onClick={() => setSelectedMetric('value')}
style={{
padding: '8px 16px',
backgroundColor: selectedMetric === 'value' ? '#4CAF50' : '#e0e0e0',
color: selectedMetric === 'value' ? 'white' : 'black',
border: 'none',
borderRadius: '4px',
cursor: 'pointer',
}}
>
Value per User
</button>
<button
onClick={() => setSelectedMetric('metcalfe')}
style={{
padding: '8px 16px',
backgroundColor: selectedMetric === 'metcalfe' ? '#4CAF50' : '#e0e0e0',
color: selectedMetric === 'metcalfe' ? 'white' : 'black',
border: 'none',
borderRadius: '4px',
cursor: 'pointer',
}}
>
Metcalfe Law
</button>
</div>
</div>
<div style={{ height: '400px', marginBottom: '20px' }}>
<Line data={chartData} options={chartOptions} />
</div>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: '15px' }}>
<div style={{ padding: '15px', backgroundColor: '#f5f5f5', borderRadius: '6px' }}>
<h3 style={{ margin: '0 0 10px 0', fontSize: '14px', color: '#666' }}>
Network Strength Score
</h3>
<p style={{ margin: 0, fontSize: '24px', fontWeight: 'bold', color: '#333' }}>
{(metrics.networkStrength * 100).toFixed(1)}%
</p>
</div>
{metrics.criticalMassIndex !== null && (
<div style={{ padding: '15px', backgroundColor: '#fff3cd', borderRadius: '6px' }}>
<h3 style={{ margin: '0 0 10px 0', fontSize: '14px', color: '#856404' }}>
Critical Mass
</h3>
<p style={{ margin: 0, fontSize: '14px', color: '#856404' }}>
Detected at index {metrics.criticalMassIndex}
</p>
</div>
)}
{Object.keys(metrics.geographicDensity).length > 0 && (
<div style={{ padding: '15px', backgroundColor: '#d1ecf1', borderRadius: '6px' }}>
<h3 style={{ margin: '0 0 10px 0', fontSize: '14px', color: '#0c5460' }}>
Geographic Coverage
</h3>
<p style={{ margin: 0, fontSize: '14px', color: '#0c5460' }}>
{Object.keys(metrics.geographicDensity).length} regions
</p>
</div>
)}
</div>
</div>
);
}