• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {addEphemeralTab} from '../../details/add_ephemeral_tab';
18import {Tab} from '../../../public/tab';
19import {ChartAttrs, renderChart, toTitleCase} from './chart';
20
21export function addChartTab(chart: ChartAttrs): void {
22  addEphemeralTab(`${chart.chartType}Tab`, new ChartTab(chart));
23}
24
25export class ChartTab implements Tab {
26  constructor(private readonly chart: ChartAttrs) {}
27
28  render() {
29    return m(
30      DetailsShell,
31      {
32        title:
33          this.chart.title !== undefined ? this.chart.title : this.getTitle(),
34        description: this.chart.description,
35      },
36      renderChart(this.chart),
37    );
38  }
39
40  getTitle(): string {
41    return `${toTitleCase(this.chart.columns[0])} ${toTitleCase(this.chart.chartType)}`;
42  }
43}
44