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 WindTurbineData { rpm?: number; } interface WindTurbineConfig { rpm?: ScalarDimensionConfig; } const WindTurbineDisplay: FC> = (props) => { const styles = useStyles2(getStyles); const { data } = props; const windTurbineAnimation = `spin ${data?.rpm ? 60 / Math.abs(data.rpm) : 0}s linear infinite`; return ( ); }; export const windTurbineItem: CanvasElementItem = { id: 'windTurbine', name: 'Wind Turbine', description: 'Spinny spinny', display: WindTurbineDisplay, defaultSize: { width: 100, height: 100, }, getNewOptions: (options) => ({ ...options, }), // Called when data changes prepareData: (ctx: DimensionContext, cfg: WindTurbineConfig) => { const data: WindTurbineData = { rpm: cfg?.rpm ? ctx.getScalar(cfg.rpm).value() : 0, }; return data; }, registerOptionsUI: (builder) => { const category = ['Wind Turbine']; builder.addCustomEditor({ category, id: 'rpm', path: 'config.rpm', name: 'RPM', editor: ScalarDimensionEditor, }); }, }; const getStyles = (theme: GrafanaTheme2) => ({ blade: css` @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } transform-origin: 94.663px 94.663px; transform: rotate(15deg); `, });