1// Copyright (C) 2024 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import m from 'mithril'; 16import {DetailsShell} from '../../../widgets/details_shell'; 17import {filterTitle} from '../sql/table/column'; 18import {addEphemeralTab} from '../../details/add_ephemeral_tab'; 19import {Tab} from '../../../public/tab'; 20import {Chart, renderChartComponent, toTitleCase} from './chart'; 21 22export function addChartTab(chart: Chart): void { 23 addEphemeralTab('histogramTab', new ChartTab(chart)); 24} 25 26export class ChartTab implements Tab { 27 constructor(private readonly chart: Chart) {} 28 29 render() { 30 return m( 31 DetailsShell, 32 { 33 title: this.getTitle(), 34 description: this.getDescription(), 35 }, 36 renderChartComponent(this.chart), 37 ); 38 } 39 40 getTitle(): string { 41 return `${toTitleCase(this.chart.config.columnTitle)} Histogram`; 42 } 43 44 private getDescription(): string { 45 let desc = `Count distribution for ${this.chart.config.tableDisplay ?? ''} table`; 46 47 if (this.chart.config.filters && this.chart.config.filters.length > 0) { 48 desc += ' where '; 49 desc += this.chart.config.filters.map((f) => filterTitle(f)).join(', '); 50 } 51 52 return desc; 53 } 54} 55