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 {stringifyJsonWithBigints} from '../../../../base/json_utils'; 17import {VegaView} from '../../vega_view'; 18import {HistogramState} from './state'; 19import {Spinner} from '../../../../widgets/spinner'; 20import {ChartConfig} from '../chart'; 21 22export class Histogram implements m.ClassComponent<ChartConfig> { 23 private readonly state: HistogramState; 24 25 constructor({attrs}: m.Vnode<ChartConfig>) { 26 this.state = new HistogramState( 27 attrs.engine, 28 attrs.query, 29 attrs.sqlColumn, 30 attrs.aggregationType, 31 ); 32 } 33 34 view() { 35 if (this.state.isLoading()) { 36 return m(Spinner); 37 } 38 39 return m( 40 'figure', 41 { 42 className: 'pf-histogram-view', 43 }, 44 m(VegaView, { 45 spec: stringifyJsonWithBigints(this.state.spec), 46 data: {}, 47 }), 48 ); 49 } 50 51 isLoading(): boolean { 52 return this.state.isLoading(); 53 } 54} 55