import { css } from '@emotion/css'; import React, { FC } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { useStyles2 } from '@grafana/ui'; import { DimensionContext, ScalarDimensionConfig } from 'app/features/dimensions'; import { ScalarDimensionEditor } from 'app/features/dimensions/editors'; import { CanvasElementItem, CanvasElementProps } from '../element'; interface DroneSideData { pitchAngle?: number; } interface DroneSideConfig { pitchAngle?: ScalarDimensionConfig; } const DroneSideDisplay: FC> = (props) => { const styles = useStyles2(getStyles); const { data } = props; const droneSidePitchTransformStyle = `rotate(${data?.pitchAngle ? data.pitchAngle : 0}deg)`; return ( ); }; export const droneSideItem: CanvasElementItem = { id: 'droneSide', name: 'Drone Side', description: 'Drone Side', display: DroneSideDisplay, defaultSize: { width: 100, height: 100, }, getNewOptions: (options) => ({ ...options, }), // Called when data changes prepareData: (ctx: DimensionContext, cfg: DroneSideConfig) => { const data: DroneSideData = { pitchAngle: cfg?.pitchAngle ? ctx.getScalar(cfg.pitchAngle).value() : 0, }; return data; }, registerOptionsUI: (builder) => { const category = ['Drone Side']; builder.addCustomEditor({ category, id: 'pitchAngle', path: 'config.pitchAngle', name: 'Pitch Angle', editor: ScalarDimensionEditor, }); }, }; const getStyles = (theme: GrafanaTheme2) => ({ droneSide: css` transition: transform 0.4s; `, });