mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-20 03:30:50 +08:00
feat: implement dynamic chart line management with UI controls, internationalization, and enhanced data handling
This commit is contained in:
23
app.js
23
app.js
@@ -524,6 +524,8 @@ class CLIProxyManager {
|
|||||||
const tokensDayBtn = document.getElementById('tokens-day-btn');
|
const tokensDayBtn = document.getElementById('tokens-day-btn');
|
||||||
const costHourBtn = document.getElementById('cost-hour-btn');
|
const costHourBtn = document.getElementById('cost-hour-btn');
|
||||||
const costDayBtn = document.getElementById('cost-day-btn');
|
const costDayBtn = document.getElementById('cost-day-btn');
|
||||||
|
const addChartLineBtn = document.getElementById('add-chart-line');
|
||||||
|
const removeChartLineBtn = document.getElementById('remove-chart-line');
|
||||||
const chartLineSelects = document.querySelectorAll('.chart-line-select');
|
const chartLineSelects = document.querySelectorAll('.chart-line-select');
|
||||||
const modelPriceForm = document.getElementById('model-price-form');
|
const modelPriceForm = document.getElementById('model-price-form');
|
||||||
const resetModelPricesBtn = document.getElementById('reset-model-prices');
|
const resetModelPricesBtn = document.getElementById('reset-model-prices');
|
||||||
@@ -550,6 +552,12 @@ class CLIProxyManager {
|
|||||||
if (costDayBtn) {
|
if (costDayBtn) {
|
||||||
costDayBtn.addEventListener('click', () => this.switchCostPeriod('day'));
|
costDayBtn.addEventListener('click', () => this.switchCostPeriod('day'));
|
||||||
}
|
}
|
||||||
|
if (addChartLineBtn) {
|
||||||
|
addChartLineBtn.addEventListener('click', () => this.changeChartLineCount(1));
|
||||||
|
}
|
||||||
|
if (removeChartLineBtn) {
|
||||||
|
removeChartLineBtn.addEventListener('click', () => this.changeChartLineCount(-1));
|
||||||
|
}
|
||||||
if (chartLineSelects.length) {
|
if (chartLineSelects.length) {
|
||||||
chartLineSelects.forEach(select => {
|
chartLineSelects.forEach(select => {
|
||||||
select.addEventListener('change', (event) => {
|
select.addEventListener('change', (event) => {
|
||||||
@@ -558,6 +566,7 @@ class CLIProxyManager {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this.updateChartLineControlsUI();
|
||||||
if (modelPriceForm) {
|
if (modelPriceForm) {
|
||||||
modelPriceForm.addEventListener('submit', (event) => {
|
modelPriceForm.addEventListener('submit', (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -661,12 +670,20 @@ class CLIProxyManager {
|
|||||||
tokensChart = null;
|
tokensChart = null;
|
||||||
costChart = null;
|
costChart = null;
|
||||||
currentUsageData = null;
|
currentUsageData = null;
|
||||||
chartLineSelections = ['none', 'none', 'none'];
|
chartLineMaxCount = 9;
|
||||||
chartLineSelectIds = ['chart-line-select-0', 'chart-line-select-1', 'chart-line-select-2'];
|
chartLineVisibleCount = 3;
|
||||||
|
chartLineSelections = Array(3).fill('none');
|
||||||
|
chartLineSelectIds = Array.from({ length: 9 }, (_, idx) => `chart-line-select-${idx}`);
|
||||||
chartLineStyles = [
|
chartLineStyles = [
|
||||||
{ borderColor: '#3b82f6', backgroundColor: 'rgba(59, 130, 246, 0.15)' },
|
{ borderColor: '#3b82f6', backgroundColor: 'rgba(59, 130, 246, 0.15)' },
|
||||||
{ borderColor: '#a855f7', backgroundColor: 'rgba(168, 85, 247, 0.15)' },
|
{ borderColor: '#a855f7', backgroundColor: 'rgba(168, 85, 247, 0.15)' },
|
||||||
{ borderColor: '#10b981', backgroundColor: 'rgba(16, 185, 129, 0.15)' }
|
{ borderColor: '#10b981', backgroundColor: 'rgba(16, 185, 129, 0.15)' },
|
||||||
|
{ borderColor: '#f97316', backgroundColor: 'rgba(249, 115, 22, 0.15)' },
|
||||||
|
{ borderColor: '#ec4899', backgroundColor: 'rgba(236, 72, 153, 0.15)' },
|
||||||
|
{ borderColor: '#14b8a6', backgroundColor: 'rgba(20, 184, 166, 0.15)' },
|
||||||
|
{ borderColor: '#8b5cf6', backgroundColor: 'rgba(139, 92, 246, 0.15)' },
|
||||||
|
{ borderColor: '#f59e0b', backgroundColor: 'rgba(245, 158, 11, 0.15)' },
|
||||||
|
{ borderColor: '#22c55e', backgroundColor: 'rgba(34, 197, 94, 0.15)' }
|
||||||
];
|
];
|
||||||
modelPriceStorageKey = 'cli-proxy-model-prices-v2';
|
modelPriceStorageKey = 'cli-proxy-model-prices-v2';
|
||||||
modelPrices = {};
|
modelPrices = {};
|
||||||
|
|||||||
20
i18n.js
20
i18n.js
@@ -463,7 +463,17 @@ const i18n = {
|
|||||||
'usage_stats.chart_line_label_1': '曲线 1',
|
'usage_stats.chart_line_label_1': '曲线 1',
|
||||||
'usage_stats.chart_line_label_2': '曲线 2',
|
'usage_stats.chart_line_label_2': '曲线 2',
|
||||||
'usage_stats.chart_line_label_3': '曲线 3',
|
'usage_stats.chart_line_label_3': '曲线 3',
|
||||||
|
'usage_stats.chart_line_label_4': '曲线 4',
|
||||||
|
'usage_stats.chart_line_label_5': '曲线 5',
|
||||||
|
'usage_stats.chart_line_label_6': '曲线 6',
|
||||||
|
'usage_stats.chart_line_label_7': '曲线 7',
|
||||||
|
'usage_stats.chart_line_label_8': '曲线 8',
|
||||||
|
'usage_stats.chart_line_label_9': '曲线 9',
|
||||||
'usage_stats.chart_line_hidden': '不显示',
|
'usage_stats.chart_line_hidden': '不显示',
|
||||||
|
'usage_stats.chart_line_actions_label': '曲线数量',
|
||||||
|
'usage_stats.chart_line_add': '增加曲线',
|
||||||
|
'usage_stats.chart_line_remove': '减少曲线',
|
||||||
|
'usage_stats.chart_line_hint': '最多同时显示 9 条模型曲线',
|
||||||
'usage_stats.no_data': '暂无数据',
|
'usage_stats.no_data': '暂无数据',
|
||||||
'usage_stats.loading_error': '加载失败',
|
'usage_stats.loading_error': '加载失败',
|
||||||
'usage_stats.api_endpoint': 'API端点',
|
'usage_stats.api_endpoint': 'API端点',
|
||||||
@@ -1084,7 +1094,17 @@ const i18n = {
|
|||||||
'usage_stats.chart_line_label_1': 'Line 1',
|
'usage_stats.chart_line_label_1': 'Line 1',
|
||||||
'usage_stats.chart_line_label_2': 'Line 2',
|
'usage_stats.chart_line_label_2': 'Line 2',
|
||||||
'usage_stats.chart_line_label_3': 'Line 3',
|
'usage_stats.chart_line_label_3': 'Line 3',
|
||||||
|
'usage_stats.chart_line_label_4': 'Line 4',
|
||||||
|
'usage_stats.chart_line_label_5': 'Line 5',
|
||||||
|
'usage_stats.chart_line_label_6': 'Line 6',
|
||||||
|
'usage_stats.chart_line_label_7': 'Line 7',
|
||||||
|
'usage_stats.chart_line_label_8': 'Line 8',
|
||||||
|
'usage_stats.chart_line_label_9': 'Line 9',
|
||||||
'usage_stats.chart_line_hidden': 'Hide',
|
'usage_stats.chart_line_hidden': 'Hide',
|
||||||
|
'usage_stats.chart_line_actions_label': 'Lines to display',
|
||||||
|
'usage_stats.chart_line_add': 'Add line',
|
||||||
|
'usage_stats.chart_line_remove': 'Remove line',
|
||||||
|
'usage_stats.chart_line_hint': 'Show up to 9 model lines at once',
|
||||||
'usage_stats.no_data': 'No Data Available',
|
'usage_stats.no_data': 'No Data Available',
|
||||||
'usage_stats.loading_error': 'Loading Failed',
|
'usage_stats.loading_error': 'Loading Failed',
|
||||||
'usage_stats.api_endpoint': 'API Endpoint',
|
'usage_stats.api_endpoint': 'API Endpoint',
|
||||||
|
|||||||
59
index.html
59
index.html
@@ -958,25 +958,76 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 图表曲线选择 -->
|
<!-- 图表曲线选择 -->
|
||||||
<div class="usage-filter-bar">
|
<div class="usage-filter-bar" id="chart-line-bar">
|
||||||
<div class="usage-filter-group">
|
<div class="usage-filter-group usage-filter-actions">
|
||||||
|
<label data-i18n="usage_stats.chart_line_actions_label">曲线数量</label>
|
||||||
|
<div class="chart-line-actions">
|
||||||
|
<button type="button" class="btn btn-small" id="add-chart-line">
|
||||||
|
<i class="fas fa-plus"></i>
|
||||||
|
<span data-i18n="usage_stats.chart_line_add">增加曲线</span>
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-small btn-secondary" id="remove-chart-line">
|
||||||
|
<i class="fas fa-minus"></i>
|
||||||
|
<span data-i18n="usage_stats.chart_line_remove">减少曲线</span>
|
||||||
|
</button>
|
||||||
|
<span class="chart-line-count" id="chart-line-count">3/9</span>
|
||||||
|
</div>
|
||||||
|
<div class="chart-line-hint" data-i18n="usage_stats.chart_line_hint">最多显示 9 条模型曲线</div>
|
||||||
|
</div>
|
||||||
|
<div class="usage-filter-group chart-line-group" data-line-index="0">
|
||||||
<label for="chart-line-select-0" data-i18n="usage_stats.chart_line_label_1">曲线 1</label>
|
<label for="chart-line-select-0" data-i18n="usage_stats.chart_line_label_1">曲线 1</label>
|
||||||
<select id="chart-line-select-0" class="model-filter-select chart-line-select" data-line-index="0" disabled>
|
<select id="chart-line-select-0" class="model-filter-select chart-line-select" data-line-index="0" disabled>
|
||||||
<option value="none" data-i18n="usage_stats.chart_line_hidden">不显示</option>
|
<option value="none" data-i18n="usage_stats.chart_line_hidden">不显示</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="usage-filter-group">
|
<div class="usage-filter-group chart-line-group" data-line-index="1">
|
||||||
<label for="chart-line-select-1" data-i18n="usage_stats.chart_line_label_2">曲线 2</label>
|
<label for="chart-line-select-1" data-i18n="usage_stats.chart_line_label_2">曲线 2</label>
|
||||||
<select id="chart-line-select-1" class="model-filter-select chart-line-select" data-line-index="1" disabled>
|
<select id="chart-line-select-1" class="model-filter-select chart-line-select" data-line-index="1" disabled>
|
||||||
<option value="none" data-i18n="usage_stats.chart_line_hidden">不显示</option>
|
<option value="none" data-i18n="usage_stats.chart_line_hidden">不显示</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="usage-filter-group">
|
<div class="usage-filter-group chart-line-group" data-line-index="2">
|
||||||
<label for="chart-line-select-2" data-i18n="usage_stats.chart_line_label_3">曲线 3</label>
|
<label for="chart-line-select-2" data-i18n="usage_stats.chart_line_label_3">曲线 3</label>
|
||||||
<select id="chart-line-select-2" class="model-filter-select chart-line-select" data-line-index="2" disabled>
|
<select id="chart-line-select-2" class="model-filter-select chart-line-select" data-line-index="2" disabled>
|
||||||
<option value="none" data-i18n="usage_stats.chart_line_hidden">不显示</option>
|
<option value="none" data-i18n="usage_stats.chart_line_hidden">不显示</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="usage-filter-group chart-line-group chart-line-hidden" data-line-index="3">
|
||||||
|
<label for="chart-line-select-3" data-i18n="usage_stats.chart_line_label_4">曲线 4</label>
|
||||||
|
<select id="chart-line-select-3" class="model-filter-select chart-line-select" data-line-index="3" disabled>
|
||||||
|
<option value="none" data-i18n="usage_stats.chart_line_hidden">不显示</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="usage-filter-group chart-line-group chart-line-hidden" data-line-index="4">
|
||||||
|
<label for="chart-line-select-4" data-i18n="usage_stats.chart_line_label_5">曲线 5</label>
|
||||||
|
<select id="chart-line-select-4" class="model-filter-select chart-line-select" data-line-index="4" disabled>
|
||||||
|
<option value="none" data-i18n="usage_stats.chart_line_hidden">不显示</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="usage-filter-group chart-line-group chart-line-hidden" data-line-index="5">
|
||||||
|
<label for="chart-line-select-5" data-i18n="usage_stats.chart_line_label_6">曲线 6</label>
|
||||||
|
<select id="chart-line-select-5" class="model-filter-select chart-line-select" data-line-index="5" disabled>
|
||||||
|
<option value="none" data-i18n="usage_stats.chart_line_hidden">不显示</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="usage-filter-group chart-line-group chart-line-hidden" data-line-index="6">
|
||||||
|
<label for="chart-line-select-6" data-i18n="usage_stats.chart_line_label_7">曲线 7</label>
|
||||||
|
<select id="chart-line-select-6" class="model-filter-select chart-line-select" data-line-index="6" disabled>
|
||||||
|
<option value="none" data-i18n="usage_stats.chart_line_hidden">不显示</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="usage-filter-group chart-line-group chart-line-hidden" data-line-index="7">
|
||||||
|
<label for="chart-line-select-7" data-i18n="usage_stats.chart_line_label_8">曲线 8</label>
|
||||||
|
<select id="chart-line-select-7" class="model-filter-select chart-line-select" data-line-index="7" disabled>
|
||||||
|
<option value="none" data-i18n="usage_stats.chart_line_hidden">不显示</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="usage-filter-group chart-line-group chart-line-hidden" data-line-index="8">
|
||||||
|
<label for="chart-line-select-8" data-i18n="usage_stats.chart_line_label_9">曲线 9</label>
|
||||||
|
<select id="chart-line-select-8" class="model-filter-select chart-line-select" data-line-index="8" disabled>
|
||||||
|
<option value="none" data-i18n="usage_stats.chart_line_hidden">不显示</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 图表区域 -->
|
<!-- 图表区域 -->
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
const DEFAULT_MODEL_PRICE_STORAGE_KEY = 'cli-proxy-model-prices-v2';
|
const DEFAULT_MODEL_PRICE_STORAGE_KEY = 'cli-proxy-model-prices-v2';
|
||||||
const LEGACY_MODEL_PRICE_STORAGE_KEY = 'cli-proxy-model-prices';
|
const LEGACY_MODEL_PRICE_STORAGE_KEY = 'cli-proxy-model-prices';
|
||||||
const TOKENS_PER_PRICE_UNIT = 1_000_000;
|
const TOKENS_PER_PRICE_UNIT = 1_000_000;
|
||||||
|
const DEFAULT_CHART_LINE_COUNT = 3;
|
||||||
|
const MIN_CHART_LINE_COUNT = 1;
|
||||||
|
|
||||||
// 获取API密钥的统计信息
|
// 获取API密钥的统计信息
|
||||||
export async function getKeyStats(usageData = null) {
|
export async function getKeyStats(usageData = null) {
|
||||||
@@ -214,14 +216,101 @@ export function getModelNamesFromUsage(usage) {
|
|||||||
return Array.from(names).sort((a, b) => a.localeCompare(b));
|
return Array.from(names).sort((a, b) => a.localeCompare(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getChartLineMaxCount() {
|
||||||
|
const idCount = Array.isArray(this.chartLineSelectIds) ? this.chartLineSelectIds.length : 0;
|
||||||
|
const configuredMax = Number(this.chartLineMaxCount);
|
||||||
|
const fallback = idCount || DEFAULT_CHART_LINE_COUNT;
|
||||||
|
const resolvedMax = Number.isFinite(configuredMax) ? configuredMax : fallback;
|
||||||
|
if (idCount > 0) {
|
||||||
|
return Math.max(MIN_CHART_LINE_COUNT, Math.min(resolvedMax, idCount));
|
||||||
|
}
|
||||||
|
return Math.max(MIN_CHART_LINE_COUNT, resolvedMax);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getVisibleChartLineCount() {
|
||||||
|
const maxCount = this.getChartLineMaxCount();
|
||||||
|
const stored = Number(this.chartLineVisibleCount);
|
||||||
|
const base = Number.isFinite(stored)
|
||||||
|
? stored
|
||||||
|
: (Array.isArray(this.chartLineSelections) ? this.chartLineSelections.length : DEFAULT_CHART_LINE_COUNT);
|
||||||
|
const resolved = Math.min(Math.max(base, MIN_CHART_LINE_COUNT), maxCount);
|
||||||
|
this.chartLineVisibleCount = resolved;
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ensureChartLineSelectionLength(targetLength = null) {
|
||||||
|
const maxCount = this.getChartLineMaxCount();
|
||||||
|
const desiredLength = Math.min(
|
||||||
|
Math.max(targetLength ?? this.getVisibleChartLineCount(), MIN_CHART_LINE_COUNT),
|
||||||
|
maxCount
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!Array.isArray(this.chartLineSelections)) {
|
||||||
|
this.chartLineSelections = Array(desiredLength).fill('none');
|
||||||
|
return this.chartLineSelections;
|
||||||
|
}
|
||||||
|
|
||||||
|
const trimmed = this.chartLineSelections.slice(0, maxCount);
|
||||||
|
if (trimmed.length < desiredLength) {
|
||||||
|
this.chartLineSelections = [...trimmed, ...Array(desiredLength - trimmed.length).fill('none')];
|
||||||
|
} else if (trimmed.length > desiredLength) {
|
||||||
|
this.chartLineSelections = trimmed.slice(0, desiredLength);
|
||||||
|
} else {
|
||||||
|
this.chartLineSelections = trimmed;
|
||||||
|
}
|
||||||
|
return this.chartLineSelections;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateChartLineControlsUI() {
|
||||||
|
const maxCount = this.getChartLineMaxCount();
|
||||||
|
const visibleCount = this.getVisibleChartLineCount();
|
||||||
|
const counter = document.getElementById('chart-line-count');
|
||||||
|
if (counter) {
|
||||||
|
counter.textContent = `${visibleCount}/${maxCount}`;
|
||||||
|
}
|
||||||
|
const addBtn = document.getElementById('add-chart-line');
|
||||||
|
const removeBtn = document.getElementById('remove-chart-line');
|
||||||
|
if (addBtn) {
|
||||||
|
addBtn.disabled = visibleCount >= maxCount;
|
||||||
|
}
|
||||||
|
if (removeBtn) {
|
||||||
|
removeBtn.disabled = visibleCount <= MIN_CHART_LINE_COUNT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setChartLineVisibleCount(count) {
|
||||||
|
const maxCount = this.getChartLineMaxCount();
|
||||||
|
const nextCount = Math.min(Math.max(count, MIN_CHART_LINE_COUNT), maxCount);
|
||||||
|
const current = this.getVisibleChartLineCount();
|
||||||
|
if (nextCount === current) {
|
||||||
|
this.updateChartLineControlsUI();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.chartLineVisibleCount = nextCount;
|
||||||
|
this.ensureChartLineSelectionLength(nextCount);
|
||||||
|
this.updateChartLineSelectors(this.currentUsageData);
|
||||||
|
this.refreshChartsForSelections();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function changeChartLineCount(delta = 0) {
|
||||||
|
const current = this.getVisibleChartLineCount();
|
||||||
|
this.setChartLineVisibleCount(current + delta);
|
||||||
|
}
|
||||||
|
|
||||||
export function updateChartLineSelectors(usage) {
|
export function updateChartLineSelectors(usage) {
|
||||||
const modelNames = this.getModelNamesFromUsage(usage);
|
const modelNames = this.getModelNamesFromUsage(usage);
|
||||||
const selectors = this.chartLineSelectIds
|
const selectors = this.chartLineSelectIds
|
||||||
.map(id => document.getElementById(id))
|
.map(id => document.getElementById(id))
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
|
const availableCount = selectors.length || this.getChartLineMaxCount();
|
||||||
|
const visibleCount = Math.min(this.getVisibleChartLineCount(), availableCount);
|
||||||
|
this.chartLineVisibleCount = visibleCount;
|
||||||
|
this.ensureChartLineSelectionLength(visibleCount);
|
||||||
|
|
||||||
if (!selectors.length) {
|
if (!selectors.length) {
|
||||||
this.chartLineSelections = ['none', 'none', 'none'];
|
this.chartLineSelections = Array(visibleCount).fill('none');
|
||||||
|
this.updateChartLineControlsUI();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,23 +330,34 @@ export function updateChartLineSelectors(usage) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const hasModels = modelNames.length > 0;
|
const hasModels = modelNames.length > 0;
|
||||||
selectors.forEach(select => {
|
selectors.forEach((select, index) => {
|
||||||
|
const group = select.closest('.chart-line-group');
|
||||||
|
const isVisible = index < visibleCount;
|
||||||
|
if (group) {
|
||||||
|
group.classList.toggle('chart-line-hidden', !isVisible);
|
||||||
|
}
|
||||||
select.innerHTML = '';
|
select.innerHTML = '';
|
||||||
select.appendChild(optionsFragment());
|
select.appendChild(optionsFragment());
|
||||||
select.disabled = !hasModels;
|
select.disabled = !hasModels || !isVisible;
|
||||||
|
if (!isVisible) {
|
||||||
|
select.value = 'none';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!hasModels) {
|
if (!hasModels) {
|
||||||
this.chartLineSelections = ['none', 'none', 'none'];
|
this.chartLineSelections = Array(visibleCount).fill('none');
|
||||||
selectors.forEach(select => {
|
selectors.forEach((select, index) => {
|
||||||
|
const group = select.closest('.chart-line-group');
|
||||||
|
if (group) {
|
||||||
|
group.classList.toggle('chart-line-hidden', index >= visibleCount);
|
||||||
|
}
|
||||||
select.value = 'none';
|
select.value = 'none';
|
||||||
});
|
});
|
||||||
|
this.updateChartLineControlsUI();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextSelections = Array.isArray(this.chartLineSelections)
|
const nextSelections = this.ensureChartLineSelectionLength(visibleCount).slice(0, visibleCount);
|
||||||
? [...this.chartLineSelections]
|
|
||||||
: ['none', 'none', 'none'];
|
|
||||||
|
|
||||||
const validNames = new Set(modelNames);
|
const validNames = new Set(modelNames);
|
||||||
let hasActiveSelection = false;
|
let hasActiveSelection = false;
|
||||||
@@ -280,17 +380,17 @@ export function updateChartLineSelectors(usage) {
|
|||||||
this.chartLineSelections = nextSelections;
|
this.chartLineSelections = nextSelections;
|
||||||
selectors.forEach((select, index) => {
|
selectors.forEach((select, index) => {
|
||||||
const value = this.chartLineSelections[index] || 'none';
|
const value = this.chartLineSelections[index] || 'none';
|
||||||
select.value = value;
|
select.value = index < visibleCount ? value : 'none';
|
||||||
});
|
});
|
||||||
|
this.updateChartLineControlsUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleChartLineSelectionChange(index, value) {
|
export function handleChartLineSelectionChange(index, value) {
|
||||||
if (!Array.isArray(this.chartLineSelections)) {
|
const visibleCount = this.getVisibleChartLineCount();
|
||||||
this.chartLineSelections = ['none', 'none', 'none'];
|
if (index < 0 || index >= visibleCount) {
|
||||||
}
|
|
||||||
if (index < 0 || index >= this.chartLineSelections.length) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.ensureChartLineSelectionLength(visibleCount);
|
||||||
const normalized = value || 'none';
|
const normalized = value || 'none';
|
||||||
if (this.chartLineSelections[index] === normalized) {
|
if (this.chartLineSelections[index] === normalized) {
|
||||||
return;
|
return;
|
||||||
@@ -324,10 +424,9 @@ export function refreshChartsForSelections() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getActiveChartLineSelections() {
|
export function getActiveChartLineSelections() {
|
||||||
if (!Array.isArray(this.chartLineSelections)) {
|
const visibleCount = this.getVisibleChartLineCount();
|
||||||
this.chartLineSelections = ['none', 'none', 'none'];
|
const selections = this.ensureChartLineSelectionLength(visibleCount).slice(0, visibleCount);
|
||||||
}
|
return selections
|
||||||
return this.chartLineSelections
|
|
||||||
.map((value, index) => ({ model: value, index }))
|
.map((value, index) => ({ model: value, index }))
|
||||||
.filter(item => item.model && item.model !== 'none');
|
.filter(item => item.model && item.model !== 'none');
|
||||||
}
|
}
|
||||||
@@ -763,7 +862,7 @@ export function buildChartDataForMetric(period = 'day', metric = 'requests') {
|
|||||||
const activeSelections = this.getActiveChartLineSelections();
|
const activeSelections = this.getActiveChartLineSelections();
|
||||||
const datasets = activeSelections.map(selection => {
|
const datasets = activeSelections.map(selection => {
|
||||||
const values = dataByModel.get(selection.model) || new Array(labels.length).fill(0);
|
const values = dataByModel.get(selection.model) || new Array(labels.length).fill(0);
|
||||||
const style = this.chartLineStyles[selection.index] || this.chartLineStyles[0];
|
const style = this.chartLineStyles[selection.index % this.chartLineStyles.length] || this.chartLineStyles[0];
|
||||||
return {
|
return {
|
||||||
label: selection.model,
|
label: selection.model,
|
||||||
data: values,
|
data: values,
|
||||||
@@ -1361,6 +1460,12 @@ export const usageModule = {
|
|||||||
loadUsageStats,
|
loadUsageStats,
|
||||||
updateUsageOverview,
|
updateUsageOverview,
|
||||||
getModelNamesFromUsage,
|
getModelNamesFromUsage,
|
||||||
|
getChartLineMaxCount,
|
||||||
|
getVisibleChartLineCount,
|
||||||
|
ensureChartLineSelectionLength,
|
||||||
|
updateChartLineControlsUI,
|
||||||
|
setChartLineVisibleCount,
|
||||||
|
changeChartLineCount,
|
||||||
updateChartLineSelectors,
|
updateChartLineSelectors,
|
||||||
handleChartLineSelectionChange,
|
handleChartLineSelectionChange,
|
||||||
refreshChartsForSelections,
|
refreshChartsForSelections,
|
||||||
|
|||||||
29
styles.css
29
styles.css
@@ -3098,12 +3098,41 @@ input:checked+.slider:before {
|
|||||||
min-width: 220px;
|
min-width: 220px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.usage-filter-actions {
|
||||||
|
min-width: 260px;
|
||||||
|
}
|
||||||
|
|
||||||
.usage-filter-group label {
|
.usage-filter-group label {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.chart-line-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-line-count {
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-radius: 20px;
|
||||||
|
background: var(--bg-tertiary);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: 13px;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-line-hint {
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-line-group.chart-line-hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.model-filter-select {
|
.model-filter-select {
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
|
|||||||
Reference in New Issue
Block a user