-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced_analysis_tool.html
More file actions
1307 lines (1145 loc) · 58.1 KB
/
advanced_analysis_tool.html
File metadata and controls
1307 lines (1145 loc) · 58.1 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Perceptual Mapping Analysis Tool</title>
<!-- GitHub Pages deployment -->
<!-- Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-VCVEW5VYX7"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-VCVEW5VYX7');
</script>
<!-- External libraries -->
<script src="https://cdn.jsdelivr.net/npm/papaparse@5.4.1/papaparse.min.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
margin: 0;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
padding: 30px;
border-radius: 15px;
box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}
h1 {
color: #333;
text-align: center;
margin-bottom: 10px;
font-size: 2.5em;
}
.subtitle {
text-align: center;
color: #666;
margin-bottom: 40px;
font-size: 1.2em;
}
.step {
margin-bottom: 30px;
padding: 25px;
border: 2px solid #e8ecf0;
border-radius: 12px;
background: #fafbfc;
transition: all 0.3s ease;
}
.step.active {
border-color: #4CAF50;
background: #f8fff8;
}
.step.completed {
border-color: #4CAF50;
background: #f0f8f0;
}
.step-header {
font-size: 1.4em;
font-weight: 600;
margin-bottom: 15px;
color: #333;
}
.file-drop {
border: 3px dashed #ddd;
border-radius: 12px;
padding: 40px 20px;
text-align: center;
color: #666;
margin: 15px 0;
background: white;
transition: all 0.3s ease;
}
.file-drop.dragover {
border-color: #4CAF50;
background: #f8fff8;
color: #4CAF50;
}
.file-drop:hover {
border-color: #999;
background: #f9f9f9;
}
textarea {
width: calc(100% - 32px);
min-height: 200px;
padding: 15px;
border: 2px solid #e8ecf0;
border-radius: 8px;
font-family: 'Monaco', 'Menlo', monospace;
font-size: 14px;
line-height: 1.5;
resize: vertical;
display: block;
margin: 10px 0;
background-color: white;
}
input[type="text"], select {
width: calc(100% - 22px);
padding: 12px 15px;
border: 2px solid #e8ecf0;
border-radius: 8px;
margin: 8px 0;
font-size: 16px;
}
button {
background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
color: white;
border: none;
padding: 12px 25px;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
font-weight: 500;
transition: all 0.3s ease;
margin: 10px 5px 10px 0;
}
button:hover {
background: linear-gradient(135deg, #45a049 0%, #3d8b40 100%);
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}
button:disabled {
background: #e0e0e0;
color: #999;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.status-indicator {
display: inline-block;
width: 12px;
height: 12px;
border-radius: 50%;
margin-right: 8px;
}
.status-pending { background-color: #ffc107; }
.status-active { background-color: #2196f3; animation: pulse 2s infinite; }
.status-completed { background-color: #4caf50; }
@keyframes pulse {
0% { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0.7); }
70% { box-shadow: 0 0 0 10px rgba(33, 150, 243, 0); }
100% { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0); }
}
.analysis-summary {
background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%);
padding: 20px;
border-radius: 12px;
margin: 15px 0;
border-left: 5px solid #2196f3;
}
.hidden { display: none; }
.data-preview {
max-height: 300px;
overflow: auto;
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 8px;
padding: 15px;
margin: 15px 0;
font-family: 'Monaco', 'Menlo', monospace;
font-size: 12px;
}
.dimensions-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin: 20px 0;
}
.map-container {
margin: 20px 0;
padding: 20px;
background: white;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
#plotly-div {
width: 100%;
height: 600px;
}
.info-box {
background: #e8f4fd;
border: 1px solid #bee5eb;
border-radius: 8px;
padding: 15px;
margin: 15px 0;
}
.warning-box {
background: #fff3cd;
border: 1px solid #ffeaa7;
border-radius: 8px;
padding: 15px;
margin: 15px 0;
color: #856404;
}
.success-box {
background: #d4edda;
border: 1px solid #c3e6cb;
border-radius: 8px;
padding: 15px;
margin: 15px 0;
color: #155724;
}
#qualitative-text {
width: calc(100% - 32px) !important;
min-height: 200px !important;
display: block !important;
visibility: visible !important;
opacity: 1 !important;
box-sizing: border-box !important;
}
#text-word-counter {
font-size: 0.9em;
color: #666;
margin: 10px 0;
font-weight: 500;
}
.keyword-list {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 12px;
margin: 15px 0;
max-width: 100%;
}
.keyword-tag {
background: #e3f2fd;
padding: 8px 15px;
border-radius: 20px;
font-size: 0.9em;
display: flex;
align-items: center;
justify-content: space-between;
position: relative;
white-space: nowrap;
min-height: 32px;
width: 100%;
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="container">
<h1>🎯 Perceptual Mapping Analyzer</h1>
<p class="subtitle">Upload survey data to generate interactive perceptual maps and competitive analysis</p>
<!-- Step 1: Qualitative Research Input -->
<div class="step active" id="step1">
<div class="step-header">
<span class="status-indicator status-active"></span>
📝 Step 1: Qualitative Research Input (Optional)
</div>
<p><strong>Purpose:</strong> Generate research dimensions from qualitative data (interviews, surveys, etc.)</p>
<div class="file-drop" id="text-drop">
<div style="font-size: 48px; margin-bottom: 15px;">📝</div>
<p><strong>Drag & drop text files here</strong></p>
<p style="margin: 10px 0;">or</p>
<input type="file" id="text-file" accept=".txt" style="display: none;">
<button onclick="document.getElementById('text-file').click()">Browse Text Files</button>
</div>
<div style="margin: 20px 0;">
<h4 style="margin-bottom: 10px; color: #333;">📝 Paste Your Qualitative Text:</h4>
<textarea id="qualitative-text" placeholder="Paste your qualitative research data here (interviews, discussions, survey responses, etc.)...
Examples:
• Interview transcripts
• User feedback
• Product reviews
• Focus group notes
• Market research text
Start typing or paste text here..."></textarea>
</div>
<div class="info-box">
<strong>💡 Tip:</strong> This step helps identify key dimensions for your perceptual map. You can skip this and proceed directly to survey data upload.
</div>
<div id="text-word-counter" class="word-counter">0 words</div>
<button id="process-text-btn" disabled>🤖 Process Text & Extract Dimensions</button>
<button onclick="skipToSurveyData()" style="margin-left: 10px;">Skip to Survey Data →</button>
<div id="extracted-dimensions" class="analysis-summary hidden">
<h4>🎯 Extracted Dimensions:</h4>
<div id="dimensions-list"></div>
</div>
</div>
<!-- Step 2: Survey Data Upload -->
<div class="step" id="step2">
<div class="step-header">
<span class="status-indicator status-pending"></span>
📊 Step 2: Survey Data Upload
</div>
<p><strong>Requirements:</strong> CSV file with survey responses (30+ respondents, rating scale 1-9)</p>
<div class="file-drop" id="survey-drop">
<div style="font-size: 48px; margin-bottom: 15px;">📊</div>
<p><strong>Drag & drop your CSV file here</strong></p>
<p style="margin: 10px 0;">or</p>
<input type="file" id="survey-file" accept=".csv" style="display: none;">
<button onclick="document.getElementById('survey-file').click()">Browse CSV Files</button>
<button onclick="loadSampleData()" style="margin-left: 10px; background: #2196F3;">Load Sample Data</button>
</div>
<div id="data-preview" class="data-preview hidden"></div>
<div id="data-summary" class="analysis-summary hidden"></div>
</div>
<!-- Step 3: Map Configuration -->
<div class="step" id="step3">
<div class="step-header">
<span class="status-indicator status-pending"></span>
⚙️ Step 3: Configure Perceptual Map
</div>
<div class="dimensions-grid">
<div>
<label for="x-dimension"><strong>X-Axis Dimension:</strong></label>
<select id="x-dimension">
<option value="">Select dimension...</option>
</select>
</div>
<div>
<label for="y-dimension"><strong>Y-Axis Dimension:</strong></label>
<select id="y-dimension">
<option value="">Select dimension...</option>
</select>
</div>
</div>
<div class="info-box">
<strong>💡 Tip:</strong> Choose dimensions that represent different competitive aspects (e.g., Price vs Quality, Innovation vs Reliability)
</div>
<button id="generate-map-btn" disabled>Generate Perceptual Map</button>
</div>
<!-- Step 4: Results -->
<div class="step" id="step4">
<div class="step-header">
<span class="status-indicator status-pending"></span>
📈 Step 4: Interactive Perceptual Map
</div>
<div id="map-container" class="map-container hidden">
<div id="plotly-div"></div>
<div class="info-box">
<strong>🎯 How to read this map:</strong>
<ul>
<li><strong>Position:</strong> Each product's average score on the selected dimensions</li>
<li><strong>Bubble size:</strong> Number of survey responses for that product</li>
<li><strong>Quadrants:</strong> Different competitive positions based on the chosen dimensions</li>
</ul>
</div>
</div>
</div>
</div>
<script>
let surveyData = null;
let processedData = null;
// File upload handling
function setupFileUpload() {
const dropZone = document.getElementById('survey-drop');
const fileInput = document.getElementById('survey-file');
// Drag and drop events
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.classList.add('dragover');
});
dropZone.addEventListener('dragleave', (e) => {
e.preventDefault();
dropZone.classList.remove('dragover');
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('dragover');
const files = e.dataTransfer.files;
if (files.length > 0) {
handleFileUpload(files[0]);
}
});
fileInput.addEventListener('change', (e) => {
if (e.target.files.length > 0) {
handleFileUpload(e.target.files[0]);
}
});
}
function handleFileUpload(file) {
if (!file.name.toLowerCase().endsWith('.csv')) {
alert('Please upload a CSV file');
return;
}
// Read file as text first to debug
const reader = new FileReader();
reader.onload = function(e) {
const csvText = e.target.result;
console.log('Raw CSV content (first 500 chars):', csvText.substring(0, 500));
Papa.parse(csvText, {
header: true,
skipEmptyLines: true,
trimHeaders: true,
dynamicTyping: false, // Keep as strings initially to avoid conversion issues
complete: function(results) {
console.log('Papa Parse results:', results);
if (results.errors.length > 0) {
console.log('CSV parsing errors:', results.errors);
// Show all errors for debugging
alert('CSV parsing errors found:\n' + results.errors.map(err => `Row ${err.row}: ${err.message}`).join('\n'));
return;
}
if (!results.data || results.data.length === 0) {
alert('No data found in CSV file.');
return;
}
// More robust data filtering
surveyData = results.data.filter(row => {
const values = Object.values(row);
const hasData = values.some(val => val !== null && val !== undefined && val.toString().trim() !== '');
console.log('Row data:', row, 'Has data:', hasData);
return hasData;
});
console.log('Filtered survey data:', surveyData);
if (surveyData.length === 0) {
alert('No valid data rows found in CSV file. Please check the format.');
return;
}
displayDataPreview();
analyzeData();
updateStepStatus('step2', 'completed');
updateStepStatus('step3', 'active');
}
});
};
reader.readAsText(file);
}
function displayDataPreview() {
const preview = document.getElementById('data-preview');
const sample = surveyData.slice(0, 5);
let html = '<h4>Data Preview (first 5 rows):</h4><table border="1" style="width: 100%; font-size: 11px;">';
// Header
html += '<tr>';
Object.keys(sample[0]).forEach(key => {
html += `<th style="padding: 5px; background: #f0f0f0;">${key}</th>`;
});
html += '</tr>';
// Data rows
sample.forEach(row => {
html += '<tr>';
Object.values(row).forEach(val => {
html += `<td style="padding: 5px;">${val}</td>`;
});
html += '</tr>';
});
html += '</table>';
preview.innerHTML = html;
preview.classList.remove('hidden');
}
// Global variable to store extracted dimensions
let extractedQualitativeDimensions = [];
function analyzeData() {
if (!surveyData || surveyData.length === 0) return;
// Check for dimension mismatch between qualitative and quantitative data
checkDimensionAlignment();
// Find identifier column (product names)
const columns = Object.keys(surveyData[0]);
let identifierColumn = null;
// Look for columns that might contain product names
const identifierKeywords = ['phone', 'product', 'brand', 'model', 'device', 'name', 'item'];
for (const col of columns) {
if (identifierKeywords.some(keyword => col.toLowerCase().includes(keyword))) {
identifierColumn = col;
break;
}
}
if (!identifierColumn) {
identifierColumn = columns[0]; // Use first column as fallback
}
// Find rating columns (numeric columns that aren't the identifier)
const ratingColumns = columns.filter(col => {
if (col === identifierColumn) return false;
// Check if column contains numeric data
const sampleValues = surveyData.slice(0, 10).map(row => row[col]);
const numericValues = sampleValues.filter(val => !isNaN(parseFloat(val)) && isFinite(val));
return numericValues.length > sampleValues.length * 0.7; // At least 70% numeric
});
processedData = {
identifierColumn: identifierColumn,
ratingColumns: ratingColumns,
data: surveyData
};
// Populate dimension selectors
const xSelect = document.getElementById('x-dimension');
const ySelect = document.getElementById('y-dimension');
xSelect.innerHTML = '<option value="">Select dimension...</option>';
ySelect.innerHTML = '<option value="">Select dimension...</option>';
ratingColumns.forEach(col => {
const option1 = new Option(col.replace(/_/g, ' '), col);
const option2 = new Option(col.replace(/_/g, ' '), col);
xSelect.appendChild(option1);
ySelect.appendChild(option2);
});
// Display analysis summary
const summary = document.getElementById('data-summary');
summary.innerHTML = `
<h4>📊 Data Analysis Summary:</h4>
<p><strong>Total Responses:</strong> ${surveyData.length.toLocaleString()}</p>
<p><strong>Product Column:</strong> ${identifierColumn}</p>
<p><strong>Rating Dimensions:</strong> ${ratingColumns.length} (${ratingColumns.join(', ')})</p>
<p><strong>Unique Products:</strong> ${[...new Set(surveyData.map(row => row[identifierColumn]))].length}</p>
`;
summary.classList.remove('hidden');
// Enable map generation when both dimensions are selected
function checkDimensions() {
const xDim = document.getElementById('x-dimension').value;
const yDim = document.getElementById('y-dimension').value;
document.getElementById('generate-map-btn').disabled = !xDim || !yDim || xDim === yDim;
}
document.getElementById('x-dimension').addEventListener('change', checkDimensions);
document.getElementById('y-dimension').addEventListener('change', checkDimensions);
}
function generatePerceptualMap() {
const xDim = document.getElementById('x-dimension').value;
const yDim = document.getElementById('y-dimension').value;
if (!xDim || !yDim || xDim === yDim) {
alert('Please select different dimensions for X and Y axes');
return;
}
// Aggregate data by product (same logic as Python version)
const productGroups = {};
const identifierCol = processedData.identifierColumn;
processedData.data.forEach(row => {
const product = row[identifierCol];
if (!product) return;
const xVal = parseFloat(row[xDim]);
const yVal = parseFloat(row[yDim]);
if (isNaN(xVal) || isNaN(yVal)) return;
if (!productGroups[product]) {
productGroups[product] = {
xValues: [],
yValues: [],
count: 0
};
}
productGroups[product].xValues.push(xVal);
productGroups[product].yValues.push(yVal);
productGroups[product].count++;
});
// Calculate averages for each product
const plotData = [];
Object.keys(productGroups).forEach(product => {
const group = productGroups[product];
const avgX = group.xValues.reduce((a, b) => a + b, 0) / group.xValues.length;
const avgY = group.yValues.reduce((a, b) => a + b, 0) / group.yValues.length;
plotData.push({
product: product,
x: avgX,
y: avgY,
frequency: group.count,
size: 100 + Math.min(700, group.count * 8) * 1.95 // 50% + 30% = 95% larger bubbles
});
});
// Create Plotly visualization
createPlotlyMap(plotData, xDim, yDim);
updateStepStatus('step3', 'completed');
updateStepStatus('step4', 'active');
document.getElementById('map-container').classList.remove('hidden');
}
function createPlotlyMap(plotData, xDim, yDim) {
// Prepare data for Plotly - markers only (no text)
const trace = {
x: plotData.map(d => d.x),
y: plotData.map(d => d.y),
text: plotData.map(d => `${d.product}<br>Responses: ${d.frequency}`),
mode: 'markers', // Remove text mode - we'll use annotations instead
marker: {
size: plotData.map(d => Math.sqrt(d.size) / 2 * 1.3), // 30% larger bubbles for Plotly
color: plotData.map((d, i) => {
// Color by brand (first word of product name)
const brand = d.product.split(/[\s-]/)[0];
const colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA726', '#AB47BC', '#66BB6A', '#EF5350', '#26A69A'];
return colors[brand.charCodeAt(0) % colors.length];
}),
opacity: 0.8,
line: {
color: 'black',
width: 1.5
}
},
hovertemplate: '<b>%{text}</b><br>' +
xDim.replace(/_/g, ' ') + ': %{x:.1f}<br>' +
yDim.replace(/_/g, ' ') + ': %{y:.1f}<extra></extra>'
};
// Create custom annotations for labels with leader lines
const labelAnnotations = plotData.map((d, i) => {
const brand = d.product.split(/[\s-]/)[0];
const colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA726', '#AB47BC', '#66BB6A', '#EF5350', '#26A69A'];
const bubbleColor = colors[brand.charCodeAt(0) % colors.length];
// Calculate bubble radius in data units (approximate)
const bubbleRadius = Math.sqrt(d.size) / 2 * 1.3;
const radiusInDataUnits = bubbleRadius * 0.01; // Rough conversion
// Position label to the left at reduced distance (half of previous)
const labelOffset = radiusInDataUnits + 0.15; // Reduced from 0.3 to 0.15
const labelX = d.x - labelOffset;
// Convert hex color to rgba for transparency
function hexToRgba(hex, alpha) {
const r = parseInt(hex.slice(1, 3), 16);
const g = parseInt(hex.slice(3, 5), 16);
const b = parseInt(hex.slice(5, 7), 16);
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}
const borderColor = hexToRgba(bubbleColor, 0.9); // Same color as bubble, 90% opacity
return {
x: labelX,
y: d.y,
text: d.product,
showarrow: true,
arrowhead: 2, // More visible arrowhead
arrowsize: 1,
arrowwidth: 2,
arrowcolor: bubbleColor,
standoff: 4, // Distance from text to start of arrow
startstandoff: 4, // Distance from point to end of arrow
ax: d.x, // Point to the center of the circle
ay: d.y,
axref: 'x',
ayref: 'y',
font: {
size: 11,
color: 'white',
family: 'Arial, sans-serif'
},
bgcolor: bubbleColor,
opacity: 0.9,
bordercolor: borderColor, // Same color as bubble with transparency
borderwidth: 2,
borderpad: 6,
xanchor: 'right',
yanchor: 'middle'
};
});
// Calculate auto-zoom range
const xValues = plotData.map(d => d.x);
const yValues = plotData.map(d => d.y);
const xMin = Math.min(...xValues);
const xMax = Math.max(...xValues);
const yMin = Math.min(...yValues);
const yMax = Math.max(...yValues);
const xRange = Math.max(xMax - xMin, 0.5);
const yRange = Math.max(yMax - yMin, 0.5);
const xPadding = xRange * 0.1;
const yPadding = yRange * 0.1;
// Calculate means for reference lines
const xMean = xValues.reduce((a, b) => a + b, 0) / xValues.length;
const yMean = yValues.reduce((a, b) => a + b, 0) / yValues.length;
const layout = {
title: {
text: `Perceptual Map: ${xDim.replace(/_/g, ' ')} vs ${yDim.replace(/_/g, ' ')}<br><sub>Bubble size = Survey response frequency</sub>`,
font: { size: 16 }
},
xaxis: {
title: xDim.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase()),
range: [xMin - xPadding, xMax + xPadding],
showgrid: true,
gridwidth: 1,
gridcolor: 'rgba(128,128,128,0.3)'
},
yaxis: {
title: yDim.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase()),
range: [yMin - yPadding, yMax + yPadding],
showgrid: true,
gridwidth: 1,
gridcolor: 'rgba(128,128,128,0.3)'
},
shapes: [
// Reference lines
{
type: 'line',
x0: xMean, y0: yMin - yPadding,
x1: xMean, y1: yMax + yPadding,
line: { color: 'gray', width: 1, dash: 'dash' }
},
{
type: 'line',
x0: xMin - xPadding, y0: yMean,
x1: xMax + xPadding, y1: yMean,
line: { color: 'gray', width: 1, dash: 'dash' }
}
],
annotations: [
// Quadrant labels
{
x: xMax - xPadding/3, y: yMax - yPadding/3,
text: 'Leaders', showarrow: false,
bgcolor: 'lightgreen', opacity: 0.8,
bordercolor: 'black', borderwidth: 1
},
{
x: xMin + xPadding/3, y: yMax - yPadding/3,
text: 'Niche Players', showarrow: false,
bgcolor: 'lightblue', opacity: 0.8,
bordercolor: 'black', borderwidth: 1
},
{
x: xMin + xPadding/3, y: yMin + yPadding/3,
text: 'Challenged', showarrow: false,
bgcolor: 'lightcoral', opacity: 0.8,
bordercolor: 'black', borderwidth: 1
},
{
x: xMax - xPadding/3, y: yMin + yPadding/3,
text: 'Specialists', showarrow: false,
bgcolor: 'lightyellow', opacity: 0.8,
bordercolor: 'black', borderwidth: 1
}
].concat(labelAnnotations), // Add product labels with leader lines
showlegend: false,
plot_bgcolor: 'white',
paper_bgcolor: 'white'
};
const config = {
displayModeBar: true,
displaylogo: false,
modeBarButtonsToRemove: ['pan2d', 'lasso2d', 'select2d'],
responsive: true
};
Plotly.newPlot('plotly-div', [trace], layout, config);
}
function updateStepStatus(stepId, status) {
const step = document.getElementById(stepId);
const indicator = step.querySelector('.status-indicator');
// Remove all status classes
step.classList.remove('active', 'completed');
indicator.classList.remove('status-pending', 'status-active', 'status-completed');
// Add new status
step.classList.add(status === 'active' ? 'active' : status);
indicator.classList.add(`status-${status}`);
}
// Load sample data function with frequency data for realistic bubble sizing
function loadSampleData() {
const sampleData = [
// iPhone 15 Pro - High popularity (85 responses)
...Array.from({length: 85}, (_, i) => ({
phone_model: 'iPhone 15 Pro',
design: (8.5 + (Math.random() - 0.5) * 1.0).toFixed(1),
price_value: (6.2 + (Math.random() - 0.5) * 1.2).toFixed(1),
camera_quality: (9.1 + (Math.random() - 0.5) * 0.8).toFixed(1),
battery_life: (7.8 + (Math.random() - 0.5) * 1.0).toFixed(1),
performance: (9.2 + (Math.random() - 0.5) * 0.6).toFixed(1),
build_quality: (8.9 + (Math.random() - 0.5) * 0.8).toFixed(1),
user_interface: (8.7 + (Math.random() - 0.5) * 0.8).toFixed(1),
innovation: (8.4 + (Math.random() - 0.5) * 0.8).toFixed(1)
})),
// Samsung Galaxy S24 Ultra - High popularity (72 responses)
...Array.from({length: 72}, (_, i) => ({
phone_model: 'Samsung Galaxy S24 Ultra',
design: (8.4 + (Math.random() - 0.5) * 0.8).toFixed(1),
price_value: (6.5 + (Math.random() - 0.5) * 1.0).toFixed(1),
camera_quality: (9.0 + (Math.random() - 0.5) * 0.8).toFixed(1),
battery_life: (8.1 + (Math.random() - 0.5) * 0.8).toFixed(1),
performance: (8.9 + (Math.random() - 0.5) * 0.8).toFixed(1),
build_quality: (8.7 + (Math.random() - 0.5) * 0.8).toFixed(1),
user_interface: (8.2 + (Math.random() - 0.5) * 0.8).toFixed(1),
innovation: (8.6 + (Math.random() - 0.5) * 0.8).toFixed(1)
})),
// Samsung Galaxy A54 - Medium popularity (65 responses)
...Array.from({length: 65}, (_, i) => ({
phone_model: 'Samsung Galaxy A54',
design: (7.5 + (Math.random() - 0.5) * 1.0).toFixed(1),
price_value: (7.9 + (Math.random() - 0.5) * 0.8).toFixed(1),
camera_quality: (7.8 + (Math.random() - 0.5) * 1.0).toFixed(1),
battery_life: (8.5 + (Math.random() - 0.5) * 0.8).toFixed(1),
performance: (7.6 + (Math.random() - 0.5) * 1.0).toFixed(1),
build_quality: (7.8 + (Math.random() - 0.5) * 1.0).toFixed(1),
user_interface: (7.7 + (Math.random() - 0.5) * 1.0).toFixed(1),
innovation: (7.2 + (Math.random() - 0.5) * 1.0).toFixed(1)
})),
// iPhone 15 - Medium popularity (58 responses)
...Array.from({length: 58}, (_, i) => ({
phone_model: 'iPhone 15',
design: (8.2 + (Math.random() - 0.5) * 0.8).toFixed(1),
price_value: (6.8 + (Math.random() - 0.5) * 1.0).toFixed(1),
camera_quality: (8.7 + (Math.random() - 0.5) * 0.8).toFixed(1),
battery_life: (7.5 + (Math.random() - 0.5) * 1.0).toFixed(1),
performance: (8.8 + (Math.random() - 0.5) * 0.8).toFixed(1),
build_quality: (8.6 + (Math.random() - 0.5) * 0.8).toFixed(1),
user_interface: (8.5 + (Math.random() - 0.5) * 0.8).toFixed(1),
innovation: (8.1 + (Math.random() - 0.5) * 0.8).toFixed(1)
})),
// Samsung Galaxy S24 - Medium popularity (52 responses)
...Array.from({length: 52}, (_, i) => ({
phone_model: 'Samsung Galaxy S24',
design: (8.1 + (Math.random() - 0.5) * 0.8).toFixed(1),
price_value: (7.2 + (Math.random() - 0.5) * 0.8).toFixed(1),
camera_quality: (8.5 + (Math.random() - 0.5) * 0.8).toFixed(1),
battery_life: (8.0 + (Math.random() - 0.5) * 0.8).toFixed(1),
performance: (8.4 + (Math.random() - 0.5) * 0.8).toFixed(1),
build_quality: (8.3 + (Math.random() - 0.5) * 0.8).toFixed(1),
user_interface: (8.0 + (Math.random() - 0.5) * 0.8).toFixed(1),
innovation: (8.2 + (Math.random() - 0.5) * 0.8).toFixed(1)
})),
// Google Pixel 8 Pro - Lower popularity (45 responses)
...Array.from({length: 45}, (_, i) => ({
phone_model: 'Google Pixel 8 Pro',
design: (7.9 + (Math.random() - 0.5) * 1.0).toFixed(1),
price_value: (7.1 + (Math.random() - 0.5) * 0.8).toFixed(1),
camera_quality: (8.8 + (Math.random() - 0.5) * 0.6).toFixed(1),
battery_life: (7.4 + (Math.random() - 0.5) * 1.0).toFixed(1),
performance: (8.1 + (Math.random() - 0.5) * 0.8).toFixed(1),
build_quality: (8.2 + (Math.random() - 0.5) * 0.8).toFixed(1),
user_interface: (8.4 + (Math.random() - 0.5) * 0.8).toFixed(1),
innovation: (8.7 + (Math.random() - 0.5) * 0.6).toFixed(1)
})),
// Google Pixel 8 - Lower popularity (38 responses)
...Array.from({length: 38}, (_, i) => ({
phone_model: 'Google Pixel 8',
design: (7.6 + (Math.random() - 0.5) * 1.0).toFixed(1),
price_value: (7.8 + (Math.random() - 0.5) * 0.8).toFixed(1),
camera_quality: (8.5 + (Math.random() - 0.5) * 0.8).toFixed(1),
battery_life: (7.2 + (Math.random() - 0.5) * 1.0).toFixed(1),
performance: (7.9 + (Math.random() - 0.5) * 0.8).toFixed(1),
build_quality: (8.0 + (Math.random() - 0.5) * 0.8).toFixed(1),
user_interface: (8.2 + (Math.random() - 0.5) * 0.8).toFixed(1),
innovation: (8.4 + (Math.random() - 0.5) * 0.8).toFixed(1)
})),
// OnePlus 12 - Lower popularity (35 responses)
...Array.from({length: 35}, (_, i) => ({
phone_model: 'OnePlus 12',
design: (8.0 + (Math.random() - 0.5) * 0.8).toFixed(1),
price_value: (7.6 + (Math.random() - 0.5) * 0.8).toFixed(1),
camera_quality: (8.2 + (Math.random() - 0.5) * 0.8).toFixed(1),
battery_life: (8.3 + (Math.random() - 0.5) * 0.8).toFixed(1),
performance: (8.7 + (Math.random() - 0.5) * 0.6).toFixed(1),
build_quality: (8.4 + (Math.random() - 0.5) * 0.8).toFixed(1),
user_interface: (7.9 + (Math.random() - 0.5) * 0.8).toFixed(1),
innovation: (8.1 + (Math.random() - 0.5) * 0.8).toFixed(1)
})),
// Xiaomi 14 Pro - Lower popularity (32 responses)
...Array.from({length: 32}, (_, i) => ({
phone_model: 'Xiaomi 14 Pro',
design: (7.7 + (Math.random() - 0.5) * 1.0).toFixed(1),
price_value: (8.5 + (Math.random() - 0.5) * 0.6).toFixed(1),
camera_quality: (8.1 + (Math.random() - 0.5) * 0.8).toFixed(1),
battery_life: (8.2 + (Math.random() - 0.5) * 0.8).toFixed(1),
performance: (8.0 + (Math.random() - 0.5) * 0.8).toFixed(1),
build_quality: (7.9 + (Math.random() - 0.5) * 0.8).toFixed(1),
user_interface: (7.5 + (Math.random() - 0.5) * 1.0).toFixed(1),
innovation: (8.3 + (Math.random() - 0.5) * 0.8).toFixed(1)
})),
// OnePlus 11 - Low popularity (28 responses)
...Array.from({length: 28}, (_, i) => ({
phone_model: 'OnePlus 11',
design: (7.8 + (Math.random() - 0.5) * 1.0).toFixed(1),
price_value: (7.9 + (Math.random() - 0.5) * 0.8).toFixed(1),
camera_quality: (8.0 + (Math.random() - 0.5) * 0.8).toFixed(1),
battery_life: (8.1 + (Math.random() - 0.5) * 0.8).toFixed(1),
performance: (8.3 + (Math.random() - 0.5) * 0.8).toFixed(1),
build_quality: (8.1 + (Math.random() - 0.5) * 0.8).toFixed(1),
user_interface: (7.8 + (Math.random() - 0.5) * 1.0).toFixed(1),
innovation: (7.8 + (Math.random() - 0.5) * 1.0).toFixed(1)
})),
// Nothing Phone 2 - Low popularity (25 responses)
...Array.from({length: 25}, (_, i) => ({
phone_model: 'Nothing Phone 2',
design: (7.4 + (Math.random() - 0.5) * 1.0).toFixed(1),
price_value: (7.3 + (Math.random() - 0.5) * 0.8).toFixed(1),
camera_quality: (7.6 + (Math.random() - 0.5) * 1.0).toFixed(1),
battery_life: (7.9 + (Math.random() - 0.5) * 0.8).toFixed(1),
performance: (7.5 + (Math.random() - 0.5) * 1.0).toFixed(1),
build_quality: (7.6 + (Math.random() - 0.5) * 1.0).toFixed(1),
user_interface: (8.0 + (Math.random() - 0.5) * 0.8).toFixed(1),
innovation: (8.9 + (Math.random() - 0.5) * 0.4).toFixed(1)
})),
// Xiaomi Redmi Note 13 - Low popularity (22 responses)
...Array.from({length: 22}, (_, i) => ({
phone_model: 'Xiaomi Redmi Note 13',
design: (6.9 + (Math.random() - 0.5) * 1.2).toFixed(1),
price_value: (8.8 + (Math.random() - 0.5) * 0.4).toFixed(1),
camera_quality: (7.2 + (Math.random() - 0.5) * 1.0).toFixed(1),
battery_life: (8.7 + (Math.random() - 0.5) * 0.6).toFixed(1),
performance: (7.1 + (Math.random() - 0.5) * 1.0).toFixed(1),
build_quality: (7.2 + (Math.random() - 0.5) * 1.0).toFixed(1),
user_interface: (7.1 + (Math.random() - 0.5) * 1.0).toFixed(1),
innovation: (7.0 + (Math.random() - 0.5) * 1.0).toFixed(1)
}))
];
// Shuffle the data to make it more realistic
const shuffledData = sampleData.sort(() => Math.random() - 0.5);
surveyData = shuffledData;
console.log('Generated sample data with', surveyData.length, 'total responses');
console.log('Products and response counts:');
const productCounts = {};
surveyData.forEach(row => {
productCounts[row.phone_model] = (productCounts[row.phone_model] || 0) + 1;
});
console.log(productCounts);
displayDataPreview();
analyzeData();
updateStepStatus('step2', 'completed');
updateStepStatus('step3', 'active');
}
// Event listeners
document.getElementById('generate-map-btn').addEventListener('click', generatePerceptualMap);
// Skip to survey data function
function skipToSurveyData() {