enhance(client): improve chart rendering
This commit is contained in:
		
							parent
							
								
									bd7662e5e4
								
							
						
					
					
						commit
						0b462feff6
					
				
					 3 changed files with 29 additions and 6 deletions
				
			
		|  | @ -95,6 +95,11 @@ export default defineComponent({ | ||||||
| 			required: false, | 			required: false, | ||||||
| 			default: false | 			default: false | ||||||
| 		}, | 		}, | ||||||
|  | 		bar: { | ||||||
|  | 			type: Boolean, | ||||||
|  | 			required: false, | ||||||
|  | 			default: false | ||||||
|  | 		}, | ||||||
| 		aspectRatio: { | 		aspectRatio: { | ||||||
| 			type: Number, | 			type: Number, | ||||||
| 			required: false, | 			required: false, | ||||||
|  | @ -187,7 +192,7 @@ export default defineComponent({ | ||||||
| 			Chart.defaults.color = getComputedStyle(document.documentElement).getPropertyValue('--fg'); | 			Chart.defaults.color = getComputedStyle(document.documentElement).getPropertyValue('--fg'); | ||||||
| 
 | 
 | ||||||
| 			chartInstance = new Chart(chartEl.value, { | 			chartInstance = new Chart(chartEl.value, { | ||||||
| 				type: 'line', | 				type: props.bar ? 'bar' : 'line', | ||||||
| 				data: { | 				data: { | ||||||
| 					labels: new Array(props.limit).fill(0).map((_, i) => getDate(i).toLocaleString()).slice().reverse(), | 					labels: new Array(props.limit).fill(0).map((_, i) => getDate(i).toLocaleString()).slice().reverse(), | ||||||
| 					datasets: data.series.map((x, i) => ({ | 					datasets: data.series.map((x, i) => ({ | ||||||
|  | @ -195,12 +200,13 @@ export default defineComponent({ | ||||||
| 						label: x.name, | 						label: x.name, | ||||||
| 						data: x.data.slice().reverse(), | 						data: x.data.slice().reverse(), | ||||||
| 						pointRadius: 0, | 						pointRadius: 0, | ||||||
| 						tension: 0, |  | ||||||
| 						borderWidth: 2, | 						borderWidth: 2, | ||||||
| 						borderColor: x.color ? x.color : getColor(i), | 						borderColor: x.color ? x.color : getColor(i), | ||||||
| 						borderDash: x.borderDash || [], | 						borderDash: x.borderDash || [], | ||||||
| 						borderJoinStyle: 'round', | 						borderJoinStyle: 'round', | ||||||
| 						backgroundColor: alpha(x.color ? x.color : getColor(i), 0.1), | 						backgroundColor: alpha(x.color ? x.color : getColor(i), 0.1), | ||||||
|  | 						barPercentage: 0.9, | ||||||
|  | 						categoryPercentage: 0.9, | ||||||
| 						fill: x.type === 'area', | 						fill: x.type === 'area', | ||||||
| 						hidden: !!x.hidden, | 						hidden: !!x.hidden, | ||||||
| 					})), | 					})), | ||||||
|  | @ -218,6 +224,7 @@ export default defineComponent({ | ||||||
| 					scales: { | 					scales: { | ||||||
| 						x: { | 						x: { | ||||||
| 							type: 'time', | 							type: 'time', | ||||||
|  | 							stacked: props.stacked, | ||||||
| 							time: { | 							time: { | ||||||
| 								stepSize: 1, | 								stepSize: 1, | ||||||
| 								unit: props.span === 'day' ? 'month' : 'day', | 								unit: props.span === 'day' ? 'month' : 'day', | ||||||
|  | @ -688,6 +695,21 @@ export default defineComponent({ | ||||||
| 			}; | 			}; | ||||||
| 		}; | 		}; | ||||||
| 
 | 
 | ||||||
|  | 		const fetchPerUserDriveChart = async (): Promise<typeof data> => { | ||||||
|  | 			const raw = await os.api('charts/user/drive', { userId: props.args.user.id, limit: props.limit, span: props.span }); | ||||||
|  | 			return { | ||||||
|  | 				series: [{ | ||||||
|  | 					name: 'Inc', | ||||||
|  | 					type: 'area', | ||||||
|  | 					data: format(raw.incSize), | ||||||
|  | 				}, { | ||||||
|  | 					name: 'Dec', | ||||||
|  | 					type: 'area', | ||||||
|  | 					data: format(raw.decSize), | ||||||
|  | 				}], | ||||||
|  | 			}; | ||||||
|  | 		}; | ||||||
|  | 
 | ||||||
| 		const fetchAndRender = async () => { | 		const fetchAndRender = async () => { | ||||||
| 			const fetchData = () => { | 			const fetchData = () => { | ||||||
| 				switch (props.src) { | 				switch (props.src) { | ||||||
|  | @ -718,6 +740,7 @@ export default defineComponent({ | ||||||
| 					case 'instance-drive-files-total': return fetchInstanceDriveFilesChart(true); | 					case 'instance-drive-files-total': return fetchInstanceDriveFilesChart(true); | ||||||
| 
 | 
 | ||||||
| 					case 'per-user-notes': return fetchPerUserNotesChart(); | 					case 'per-user-notes': return fetchPerUserNotesChart(); | ||||||
|  | 					case 'per-user-drive': return fetchPerUserDriveChart(); | ||||||
| 				} | 				} | ||||||
| 			}; | 			}; | ||||||
| 			fetching.value = true; | 			fetching.value = true; | ||||||
|  |  | ||||||
|  | @ -19,7 +19,7 @@ | ||||||
| 
 | 
 | ||||||
| 	<FormSection> | 	<FormSection> | ||||||
| 		<template #label>{{ $ts.statistics }}</template> | 		<template #label>{{ $ts.statistics }}</template> | ||||||
| 		<div ref="chart"></div> | 		<MkChart src="per-user-drive" :args="{ user: $i }" span="day" :limit="7 * 5" :bar="true" :stacked="true" :detailed="false" :aspect-ratio="6"/> | ||||||
| 	</FormSection> | 	</FormSection> | ||||||
| 
 | 
 | ||||||
| 	<FormSection> | 	<FormSection> | ||||||
|  | @ -45,8 +45,7 @@ import * as os from '@/os'; | ||||||
| import bytes from '@/filters/bytes'; | import bytes from '@/filters/bytes'; | ||||||
| import * as symbols from '@/symbols'; | import * as symbols from '@/symbols'; | ||||||
| import { defaultStore } from '@/store'; | import { defaultStore } from '@/store'; | ||||||
| 
 | import MkChart from '@/components/chart.vue'; | ||||||
| // TODO: render chart |  | ||||||
| 
 | 
 | ||||||
| export default defineComponent({ | export default defineComponent({ | ||||||
| 	components: { | 	components: { | ||||||
|  | @ -55,6 +54,7 @@ export default defineComponent({ | ||||||
| 		FormSection, | 		FormSection, | ||||||
| 		MkKeyValue, | 		MkKeyValue, | ||||||
| 		FormSplit, | 		FormSplit, | ||||||
|  | 		MkChart, | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
| 	emits: ['info'], | 	emits: ['info'], | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ | ||||||
| 	<template #header><i class="fas fa-chart-bar" style="margin-right: 0.5em;"></i>{{ $ts.activity }}</template> | 	<template #header><i class="fas fa-chart-bar" style="margin-right: 0.5em;"></i>{{ $ts.activity }}</template> | ||||||
| 
 | 
 | ||||||
| 	<div style="padding: 8px;"> | 	<div style="padding: 8px;"> | ||||||
| 		<MkChart src="per-user-notes" :args="{ user, withoutAll: true }" span="day" :limit="limit" :stacked="true" :detailed="false" :aspect-ratio="6"/> | 		<MkChart src="per-user-notes" :args="{ user, withoutAll: true }" span="day" :limit="limit" :bar="true" :stacked="true" :detailed="false" :aspect-ratio="5"/> | ||||||
| 	</div> | 	</div> | ||||||
| </MkContainer> | </MkContainer> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue