1// Copyright (C) 2023 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'; 16 17import {raf} from '../core/raf_scheduler'; 18import {Engine} from '../trace_processor/engine'; 19import {Editor} from '../widgets/editor'; 20import {VegaView} from '../widgets/vega_view'; 21 22import {globals} from './globals'; 23import {createPage} from './pages'; 24 25function getEngine(): Engine | undefined { 26 const engineId = globals.getCurrentEngine()?.id; 27 if (engineId === undefined) { 28 return undefined; 29 } 30 const engine = globals.engines.get(engineId)?.getProxy('VizPage'); 31 return engine; 32} 33 34let SPEC = ''; 35let ENGINE: Engine | undefined = undefined; 36 37export const VizPage = createPage({ 38 oncreate() { 39 ENGINE = getEngine(); 40 }, 41 42 view() { 43 return m( 44 '.viz-page', 45 m(VegaView, { 46 spec: SPEC, 47 engine: ENGINE, 48 data: {}, 49 }), 50 m(Editor, { 51 onUpdate: (text: string) => { 52 SPEC = text; 53 raf.scheduleFullRedraw(); 54 }, 55 }), 56 ); 57 }, 58}); 59