File size: 21,840 Bytes
ce65fef
 
 
 
fcb188b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce65fef
 
 
 
 
 
 
 
 
 
 
fcb188b
 
 
 
ce65fef
 
 
 
 
 
 
 
 
fcb188b
 
 
 
 
 
ce65fef
 
 
 
 
fcb188b
 
 
261f212
 
fcb188b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce65fef
 
 
 
fcb188b
 
3c9e74a
 
 
fcb188b
 
 
 
3c9e74a
fcb188b
 
3c9e74a
 
 
ce65fef
 
 
3c9e74a
 
 
 
fcb188b
 
 
 
 
 
 
 
 
 
 
ce65fef
 
fcb188b
ce65fef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fcb188b
ce65fef
 
 
 
 
 
 
 
 
 
fcb188b
 
 
 
ce65fef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fcb188b
ce65fef
fcb188b
 
 
ce65fef
 
 
fcb188b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce65fef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fcb188b
 
ce65fef
 
 
 
fcb188b
 
 
 
 
3c9e74a
 
ce65fef
 
fcb188b
 
 
 
 
 
 
 
ce65fef
3c9e74a
 
 
 
 
 
 
 
 
fca700e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fcb188b
 
ce65fef
fcb188b
 
 
 
ce65fef
fcb188b
 
 
 
ce65fef
 
fcb188b
 
 
 
ce65fef
fcb188b
ce65fef
fca700e
 
 
 
 
 
 
 
 
 
fcb188b
 
 
 
 
 
 
 
 
3c9e74a
 
 
ce65fef
 
fca700e
 
ce65fef
 
fcb188b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce65fef
 
 
 
 
 
 
 
 
 
 
 
fcb188b
ce65fef
 
 
 
 
 
 
 
 
 
 
261f212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce65fef
 
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
// Global data storage
let allModels = [];
let filteredModels = [];

// Vendor name mapping
const vendorNameMap = {
    'qwen': 'Qwen',
    'meta-llama': 'Meta',
    'x-ai': 'xAI',
    'z-ai': 'Zhipu AI',
    'google': 'Google',
    'openai': 'OpenAI',
    'anthropic': 'Anthropic',
    'mistralai': 'Mistral AI',
    'deepseek': 'DeepSeek',
    'alibaba': 'Alibaba',
    'amazon': 'Amazon',
    'microsoft': 'Microsoft',
    'nvidia': 'NVIDIA',
    'cohere': 'Cohere',
    'ai21': 'AI21 Labs',
    'minimax': 'MiniMax',
    'moonshotai': 'Moonshot AI',
    'stepfun-ai': 'StepFun',
    'inclusionai': 'Inclusion AI',
    'deepcogito': 'Deep Cogito',
    'baidu': 'Baidu',
    'nousresearch': 'Nous Research',
    'arcee-ai': 'Arcee AI',
    'inception': 'Inception',
    'sao10k': 'Sao10K',
    'thedrummer': 'TheDrummer',
    'tngtech': 'TNG Technology',
    'meituan': 'Meituan'
};

function normalizeVendorName(vendor) {
    return vendorNameMap[vendor] || vendor;
}

// Load and process CSV data
async function loadData() {
    try {
        const response = await fetch('quadrants.csv');
        const csvText = await response.text();

        Papa.parse(csvText, {
            header: true,
            dynamicTyping: true,
            complete: function(results) {
                allModels = results.data.filter(row => row.model_name);
                // Normalize vendor names
                allModels.forEach(model => {
                    model.displayVendor = normalizeVendorName(model.vendor);
                });
                filteredModels = [...allModels];
                initializeApp();
            }
        });
    } catch (error) {
        console.error('Error loading data:', error);
    }
}

// Sorting state
let currentSort = {
    column: 'model_name',
    direction: 'asc'
};

// Initialize all visualizations and features
function initializeApp() {
    updateStats();
    populateTable();
    setupTableControls();
    setupSorting();
    setupTabs();
    createQuadrantChart();
    createAllQuadrantsChart();
    createIndividualQuadrantCharts();
}

// Setup tab navigation
function setupTabs() {
    const tabButtons = document.querySelectorAll('.tab-button');
    const tabContents = document.querySelectorAll('.tab-content');

    tabButtons.forEach(button => {
        button.addEventListener('click', () => {
            const targetTab = button.dataset.tab;

            // Remove active class from all buttons and contents
            tabButtons.forEach(btn => btn.classList.remove('active'));
            tabContents.forEach(content => content.classList.remove('active'));

            // Add active class to clicked button and corresponding content
            button.classList.add('active');
            document.getElementById(`tab-${targetTab}`).classList.add('active');
        });
    });
}

// Update summary statistics
function updateStats() {
    const costs = allModels.map(m => m.avg_cost);
    const contexts = allModels.map(m => m.context_length);
    const inputPrices = allModels.map(m => m.input_price_usd_per_m);
    const outputPrices = allModels.map(m => m.output_price_usd_per_m);
    const multiples = allModels.map(m => m.output_input_multiple);
    const minContext = Math.min(...contexts);
    const maxContext = Math.max(...contexts);
    const vendors = new Set(allModels.map(m => m.displayVendor)).size;

    // Calculate medians
    const medianCost = median(costs);
    const medianContext = median(contexts);
    const medianInput = median(inputPrices);
    const medianOutput = median(outputPrices);
    const medianMultiple = median(multiples);

    document.getElementById('total-models').textContent = allModels.length;
    document.getElementById('vendors').textContent = vendors;
    document.getElementById('median-input').textContent = `$${medianInput.toFixed(2)}`;
    document.getElementById('median-output').textContent = `$${medianOutput.toFixed(2)}`;
    document.getElementById('median-multiple').textContent = `${medianMultiple.toFixed(2)}x`;
    document.getElementById('context-range').textContent = `${(minContext/1000).toFixed(0)}K - ${(maxContext/1000000).toFixed(1)}M`;

    // Update methodology section with actual median values
    document.getElementById('median-cost-display').textContent = `$${medianCost.toFixed(2)}/M tokens`;
    document.getElementById('median-context-display').textContent = `${(medianContext/1000).toFixed(0)}K tokens`;
}

// Calculate median for quadrant lines
function median(arr) {
    const sorted = [...arr].sort((a, b) => a - b);
    const mid = Math.floor(sorted.length / 2);
    return sorted.length % 2 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
}

// Create main quadrant scatter plot with division lines
function createQuadrantChart() {
    const ctx = document.getElementById('quadrantChart').getContext('2d');

    const quadrantColors = {
        'Low Cost / High Context': '#10b981',
        'High Cost / High Context': '#2563eb',
        'Low Cost / Low Context': '#f59e0b',
        'High Cost / Low Context': '#ef4444'
    };

    const datasets = Object.keys(quadrantColors).map(quadrant => {
        const models = allModels.filter(m => m.quadrant === quadrant);
        return {
            label: quadrant,
            data: models.map(m => ({
                x: m.avg_cost,
                y: m.context_length / 1000,
                model: m
            })),
            backgroundColor: quadrantColors[quadrant] + '80',
            borderColor: quadrantColors[quadrant],
            borderWidth: 2,
            pointRadius: 5,
            pointHoverRadius: 8
        };
    });

    // Calculate medians for quadrant lines
    const medianCost = median(allModels.map(m => m.avg_cost));
    const medianContext = median(allModels.map(m => m.context_length / 1000));

    new Chart(ctx, {
        type: 'scatter',
        data: { datasets },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                title: {
                    display: false
                },
                legend: {
                    display: true,
                    position: 'top'
                },
                tooltip: {
                    callbacks: {
                        label: function(context) {
                            const model = context.raw.model;
                            return [
                                model.model_name,
                                `Vendor: ${model.displayVendor}`,
                                `Context: ${(model.context_length / 1000).toFixed(0)}K tokens`,
                                `Input: $${model.input_price_usd_per_m.toFixed(2)}/M`,
                                `Output: $${model.output_price_usd_per_m.toFixed(2)}/M`,
                                `Avg: $${model.avg_cost.toFixed(2)}/M`
                            ];
                        }
                    }
                },
                annotation: {
                    annotations: {
                        verticalLine: {
                            type: 'line',
                            xMin: medianCost,
                            xMax: medianCost,
                            borderColor: '#64748b',
                            borderWidth: 2,
                            borderDash: [5, 5],
                            label: {
                                display: true,
                                content: `Median Cost: $${medianCost.toFixed(2)}`,
                                position: 'start'
                            }
                        },
                        horizontalLine: {
                            type: 'line',
                            yMin: medianContext,
                            yMax: medianContext,
                            borderColor: '#64748b',
                            borderWidth: 2,
                            borderDash: [5, 5],
                            label: {
                                display: true,
                                content: `Median Context: ${medianContext.toFixed(0)}K`,
                                position: 'end'
                            }
                        }
                    }
                }
            },
            scales: {
                x: {
                    type: 'logarithmic',
                    title: {
                        display: true,
                        text: 'Average Cost ($/M tokens, log scale)'
                    },
                    min: 0.01
                },
                y: {
                    title: {
                        display: true,
                        text: 'Context Window (K tokens)'
                    }
                }
            }
        },
        plugins: [window['chartjs-plugin-annotation']]
    });
}


// Get tier class for cost
function getCostTier(cost) {
    if (cost < 0.10) return 'cost-very-low';
    if (cost < 0.50) return 'cost-low';
    if (cost < 2.00) return 'cost-medium';
    if (cost < 40.00) return 'cost-high';
    return 'cost-very-high';  // $40+ per million tokens
}

// Get tier class for context
function getContextTier(context) {
    if (context < 32000) return 'context-small';
    if (context < 128000) return 'context-medium';
    if (context < 256000) return 'context-large';
    if (context < 1000000) return 'context-very-large';
    return 'context-ultra';
}

// Get tier class for output/input multiple
function getMultipleTier(multiple) {
    if (multiple <= 1) return 'multiple-equal';      // Equal or cheaper output
    if (multiple < 2) return 'multiple-low';         // Less than 2x
    if (multiple < 5) return 'multiple-medium';      // 2-5x (most common)
    if (multiple < 10) return 'multiple-high';       // 5-10x
    return 'multiple-very-high';                     // 10x+
}

// Clean up model name by removing redundant vendor prefix
function cleanModelName(modelName, vendor) {
    // Common patterns to remove
    const patterns = [
        new RegExp(`^${vendor}:\\s*`, 'i'),
        /^Qwen:\s*/i,
        /^Meta:\s*/i,
        /^Google:\s*/i,
        /^OpenAI:\s*/i,
        /^Anthropic:\s*/i,
        /^DeepSeek:\s*/i,
        /^Mistral:\s*/i,
        /^NVIDIA:\s*/i,
        /^Amazon:\s*/i,
        /^Microsoft:\s*/i,
        /^xAI:\s*/i,
        /^Zhipu AI:\s*/i,
        /^MoonshotAI:\s*/i,
        /^Moonshot AI:\s*/i,
        /^Alibaba:\s*/i
    ];

    let cleaned = modelName;
    for (const pattern of patterns) {
        cleaned = cleaned.replace(pattern, '');
    }
    return cleaned;
}

// Populate data table with color coding and vendor grouping
function populateTable(models = filteredModels) {
    const tbody = document.getElementById('table-body');

    // Sort models
    const sortedModels = [...models].sort((a, b) => {
        let aVal = a[currentSort.column];
        let bVal = b[currentSort.column];

        // Handle string comparisons
        if (typeof aVal === 'string') {
            aVal = aVal.toLowerCase();
            bVal = bVal.toLowerCase();
        }

        if (currentSort.direction === 'asc') {
            return aVal > bVal ? 1 : -1;
        } else {
            return aVal < bVal ? 1 : -1;
        }
    });

    let lastVendor = null;
    tbody.innerHTML = sortedModels.map((m, index) => {
        const isNewVendor = m.displayVendor !== lastVendor;
        lastVendor = m.displayVendor;
        const vendorClass = isNewVendor ? 'vendor-group-start' : '';

        return `
        <tr class="${vendorClass}" data-vendor="${m.displayVendor}">
            <td>${cleanModelName(m.model_name, m.displayVendor)}</td>
            <td class="vendor-cell">${m.displayVendor}</td>
            <td class="${getContextTier(m.context_length)}" style="font-weight: 600;">
                ${(m.context_length / 1000).toFixed(0)}K
            </td>
            <td class="${getCostTier(m.input_price_usd_per_m)}" style="font-weight: 600;">
                $${m.input_price_usd_per_m.toFixed(2)}
            </td>
            <td class="${getCostTier(m.output_price_usd_per_m)}" style="font-weight: 600;">
                $${m.output_price_usd_per_m.toFixed(2)}
            </td>
            <td class="${getMultipleTier(m.output_input_multiple)}" style="font-weight: 600;">
                ${m.output_input_multiple.toFixed(2)}x
            </td>
            <td><span class="quadrant-badge">${m.quadrant}</span></td>
        </tr>
    `;
    }).join('');
}

// Setup sorting functionality
function setupSorting() {
    const headers = document.querySelectorAll('th.sortable');

    headers.forEach(header => {
        header.addEventListener('click', () => {
            const column = header.dataset.sort;

            // Toggle direction if clicking same column
            if (currentSort.column === column) {
                currentSort.direction = currentSort.direction === 'asc' ? 'desc' : 'asc';
            } else {
                currentSort.column = column;
                currentSort.direction = 'asc';
            }

            // Update UI indicators
            headers.forEach(h => {
                h.classList.remove('sort-asc', 'sort-desc');
            });
            header.classList.add(`sort-${currentSort.direction}`);

            // Repopulate table
            populateTable(filteredModels);
        });
    });

    // Set initial sort indicator
    const initialHeader = document.querySelector(`th[data-sort="${currentSort.column}"]`);
    if (initialHeader) {
        initialHeader.classList.add('sort-asc');
    }
}

// Setup table filtering and search
function setupTableControls() {
    const searchInput = document.getElementById('search');
    const quadrantFilter = document.getElementById('quadrant-filter');

    function applyFilters() {
        const searchTerm = searchInput.value.toLowerCase();
        const quadrant = quadrantFilter.value;

        filteredModels = allModels.filter(m => {
            const matchesSearch = !searchTerm ||
                m.model_name.toLowerCase().includes(searchTerm) ||
                m.displayVendor.toLowerCase().includes(searchTerm);
            const matchesQuadrant = !quadrant || m.quadrant === quadrant;
            return matchesSearch && matchesQuadrant;
        });

        populateTable(filteredModels);
    }

    searchInput.addEventListener('input', applyFilters);
    quadrantFilter.addEventListener('change', applyFilters);
}

// Create all quadrants overview chart (same as main quadrant chart)
function createAllQuadrantsChart() {
    const ctx = document.getElementById('allQuadrantsChart').getContext('2d');

    const quadrantColors = {
        'Low Cost / High Context': '#10b981',
        'High Cost / High Context': '#2563eb',
        'Low Cost / Low Context': '#f59e0b',
        'High Cost / Low Context': '#ef4444'
    };

    const datasets = Object.keys(quadrantColors).map(quadrant => {
        const models = allModels.filter(m => m.quadrant === quadrant);
        return {
            label: quadrant,
            data: models.map(m => ({
                x: m.avg_cost,
                y: m.context_length / 1000,
                model: m
            })),
            backgroundColor: quadrantColors[quadrant] + '80',
            borderColor: quadrantColors[quadrant],
            borderWidth: 2,
            pointRadius: 5,
            pointHoverRadius: 8
        };
    });

    const medianCost = median(allModels.map(m => m.avg_cost));
    const medianContext = median(allModels.map(m => m.context_length / 1000));

    new Chart(ctx, {
        type: 'scatter',
        data: { datasets },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                title: {
                    display: false
                },
                legend: {
                    display: true,
                    position: 'top'
                },
                tooltip: {
                    callbacks: {
                        label: function(context) {
                            const model = context.raw.model;
                            return [
                                model.model_name,
                                `Vendor: ${model.displayVendor}`,
                                `Context: ${(model.context_length / 1000).toFixed(0)}K tokens`,
                                `Input: $${model.input_price_usd_per_m.toFixed(2)}/M`,
                                `Output: $${model.output_price_usd_per_m.toFixed(2)}/M`,
                                `Avg: $${model.avg_cost.toFixed(2)}/M`
                            ];
                        }
                    }
                },
                annotation: {
                    annotations: {
                        verticalLine: {
                            type: 'line',
                            xMin: medianCost,
                            xMax: medianCost,
                            borderColor: '#64748b',
                            borderWidth: 2,
                            borderDash: [5, 5],
                            label: {
                                display: true,
                                content: `Median: $${medianCost.toFixed(2)}`,
                                position: 'start'
                            }
                        },
                        horizontalLine: {
                            type: 'line',
                            yMin: medianContext,
                            yMax: medianContext,
                            borderColor: '#64748b',
                            borderWidth: 2,
                            borderDash: [5, 5],
                            label: {
                                display: true,
                                content: `Median: ${medianContext.toFixed(0)}K`,
                                position: 'end'
                            }
                        }
                    }
                }
            },
            scales: {
                x: {
                    type: 'logarithmic',
                    title: {
                        display: true,
                        text: 'Average Cost ($/M tokens, log scale)'
                    },
                    min: 0.01
                },
                y: {
                    title: {
                        display: true,
                        text: 'Context Window (K tokens)'
                    }
                }
            }
        },
        plugins: [window['chartjs-plugin-annotation']]
    });
}

// Create individual quadrant zoom charts
function createIndividualQuadrantCharts() {
    const quadrants = [
        { name: 'Low Cost / High Context', id: 'lchc', color: '#10b981' },
        { name: 'High Cost / High Context', id: 'hchc', color: '#2563eb' },
        { name: 'Low Cost / Low Context', id: 'lclc', color: '#f59e0b' },
        { name: 'High Cost / Low Context', id: 'hclc', color: '#ef4444' }
    ];

    quadrants.forEach(quadrant => {
        const ctx = document.getElementById(`quadrant-${quadrant.id}`).getContext('2d');
        const models = allModels.filter(m => m.quadrant === quadrant.name);

        if (models.length === 0) return;

        const data = models.map(m => ({
            x: m.avg_cost,
            y: m.context_length / 1000,
            model: m
        }));

        new Chart(ctx, {
            type: 'scatter',
            data: {
                datasets: [{
                    label: quadrant.name,
                    data: data,
                    backgroundColor: quadrant.color + '80',
                    borderColor: quadrant.color,
                    borderWidth: 2,
                    pointRadius: 6,
                    pointHoverRadius: 9
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    title: {
                        display: false
                    },
                    legend: {
                        display: false
                    },
                    tooltip: {
                        callbacks: {
                            label: function(context) {
                                const model = context.raw.model;
                                return [
                                    model.model_name,
                                    `Vendor: ${model.displayVendor}`,
                                    `Context: ${(model.context_length / 1000).toFixed(0)}K tokens`,
                                    `Input: $${model.input_price_usd_per_m.toFixed(2)}/M`,
                                    `Output: $${model.output_price_usd_per_m.toFixed(2)}/M`,
                                    `Avg: $${model.avg_cost.toFixed(2)}/M`
                                ];
                            }
                        }
                    }
                },
                scales: {
                    x: {
                        type: 'logarithmic',
                        title: {
                            display: true,
                            text: 'Average Cost ($/M tokens, log scale)',
                            font: {
                                size: 11
                            }
                        }
                    },
                    y: {
                        title: {
                            display: true,
                            text: 'Context (K tokens)',
                            font: {
                                size: 11
                            }
                        }
                    }
                }
            }
        });
    });
}

// Initialize on page load
document.addEventListener('DOMContentLoaded', loadData);