mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Geomap panel: Generate types (#61636)
This commit is contained in:
@@ -2,74 +2,23 @@ import { Map as OpenLayersMap } from 'ol';
|
||||
import BaseLayer from 'ol/layer/Base';
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
import { MapLayerOptions, FrameGeometrySourceMode } from '@grafana/schema';
|
||||
|
||||
import { EventBus } from '../events';
|
||||
import { GrafanaTheme2 } from '../themes';
|
||||
import { MatcherConfig, PanelData } from '../types';
|
||||
import { PanelData } from '../types';
|
||||
import { PanelOptionsEditorBuilder } from '../utils';
|
||||
import { RegistryItemWithOptions } from '../utils/Registry';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
* @deprecated use the type from schema
|
||||
*/
|
||||
export enum FrameGeometrySourceMode {
|
||||
Auto = 'auto', // Will scan fields and find best match
|
||||
Geohash = 'geohash',
|
||||
Coords = 'coords', // lon field, lat field
|
||||
Lookup = 'lookup', // keys > location
|
||||
// H3 = 'h3',
|
||||
// WKT = 'wkt,
|
||||
// geojson? geometry text
|
||||
}
|
||||
export { FrameGeometrySourceMode };
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
* @deprecated use the type from schema
|
||||
*/
|
||||
export interface FrameGeometrySource {
|
||||
mode: FrameGeometrySourceMode;
|
||||
|
||||
// Field mappings
|
||||
geohash?: string;
|
||||
latitude?: string;
|
||||
longitude?: string;
|
||||
h3?: string;
|
||||
wkt?: string;
|
||||
lookup?: string;
|
||||
|
||||
// Path to Gazetteer
|
||||
gazetteer?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets saved in panel json
|
||||
*
|
||||
* depending on the type, it may have additional config
|
||||
*
|
||||
* This exists in `grafana/data` so the types are well known and extendable but the
|
||||
* layout/frame is control by the map panel
|
||||
*
|
||||
* @alpha
|
||||
*/
|
||||
export interface MapLayerOptions<TConfig = any> {
|
||||
type: string;
|
||||
name: string; // configured unique display name
|
||||
|
||||
// Custom options depending on the type
|
||||
config?: TConfig;
|
||||
|
||||
// Common method to define geometry fields
|
||||
location?: FrameGeometrySource;
|
||||
|
||||
// Defines which data query refId is associated with the layer
|
||||
filterData?: MatcherConfig;
|
||||
|
||||
// Common properties:
|
||||
// https://openlayers.org/en/latest/apidoc/module-ol_layer_Base-BaseLayer.html
|
||||
// Layer opacity (0-1)
|
||||
opacity?: number;
|
||||
|
||||
// Check tooltip (defaults to true)
|
||||
tooltip?: boolean;
|
||||
}
|
||||
export type { FrameGeometrySource, MapLayerOptions } from '@grafana/schema';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
@@ -81,7 +30,7 @@ export interface MapLayerHandler<TConfig = any> {
|
||||
*/
|
||||
update?: (data: PanelData) => void;
|
||||
|
||||
/** Optional callback to cleaup before getting removed */
|
||||
/** Optional callback for cleanup before getting removed */
|
||||
dispose?: () => void;
|
||||
|
||||
/** return react node for the legend */
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export type { MatcherConfig } from '@grafana/schema';
|
||||
import { MonoTypeOperatorFunction } from 'rxjs';
|
||||
|
||||
import { RegistryItemWithOptions } from '../utils/Registry';
|
||||
@@ -80,10 +81,6 @@ export interface ValueMatcherInfo<TOptions = any> extends RegistryItemWithOption
|
||||
isApplicable: (field: Field) => boolean;
|
||||
getDefaultOptions: (field: Field) => TOptions;
|
||||
}
|
||||
export interface MatcherConfig<TOptions = any> {
|
||||
id: string;
|
||||
options?: TOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
|
||||
@@ -40,6 +40,43 @@ export interface DataQuery {
|
||||
refId: string;
|
||||
}
|
||||
|
||||
export interface MapLayerOptions {
|
||||
/**
|
||||
* Custom options depending on the type
|
||||
*/
|
||||
config?: unknown;
|
||||
/**
|
||||
* Defines a frame MatcherConfig that may filter data for the given layer
|
||||
*/
|
||||
filterData?: unknown;
|
||||
/**
|
||||
* Common method to define geometry fields
|
||||
*/
|
||||
location?: FrameGeometrySource;
|
||||
/**
|
||||
* configured unique display name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Common properties:
|
||||
* https://openlayers.org/en/latest/apidoc/module-ol_layer_Base-BaseLayer.html
|
||||
* Layer opacity (0-1)
|
||||
*/
|
||||
opacity?: number;
|
||||
/**
|
||||
* Check tooltip (defaults to true)
|
||||
*/
|
||||
tooltip?: boolean;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export enum FrameGeometrySourceMode {
|
||||
Auto = 'auto',
|
||||
Coords = 'coords',
|
||||
Geohash = 'geohash',
|
||||
Lookup = 'lookup',
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO docs
|
||||
*/
|
||||
@@ -595,6 +632,22 @@ export interface DataSourceRef {
|
||||
uid?: string;
|
||||
}
|
||||
|
||||
export interface FrameGeometrySource {
|
||||
/**
|
||||
* Path to Gazetteer
|
||||
*/
|
||||
gazetteer?: string;
|
||||
/**
|
||||
* Field mappings
|
||||
*/
|
||||
geohash?: string;
|
||||
latitude?: string;
|
||||
longitude?: string;
|
||||
lookup?: string;
|
||||
mode: FrameGeometrySourceMode;
|
||||
wkt?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO docs
|
||||
*/
|
||||
|
||||
33
packages/grafana-schema/src/common/geo.cue
Normal file
33
packages/grafana-schema/src/common/geo.cue
Normal file
@@ -0,0 +1,33 @@
|
||||
package common
|
||||
|
||||
MapLayerOptions: {
|
||||
type: string
|
||||
// configured unique display name
|
||||
name: string
|
||||
// Custom options depending on the type
|
||||
config?: _
|
||||
// Common method to define geometry fields
|
||||
location?: FrameGeometrySource
|
||||
// Defines a frame MatcherConfig that may filter data for the given layer
|
||||
filterData?: _
|
||||
// Common properties:
|
||||
// https://openlayers.org/en/latest/apidoc/module-ol_layer_Base-BaseLayer.html
|
||||
// Layer opacity (0-1)
|
||||
opacity?: int64
|
||||
// Check tooltip (defaults to true)
|
||||
tooltip?: bool
|
||||
} @cuetsy(kind="interface") @grafana(TSVeneer="type")
|
||||
|
||||
FrameGeometrySourceMode: "auto" | "geohash" |"coords" | "lookup" @cuetsy(kind="enum",memberNames="Auto|Geohash|Coords|Lookup")
|
||||
|
||||
FrameGeometrySource: {
|
||||
mode: FrameGeometrySourceMode
|
||||
// Field mappings
|
||||
geohash?: string
|
||||
latitude?: string
|
||||
longitude?: string
|
||||
wkt?: string
|
||||
lookup?: string
|
||||
// Path to Gazetteer
|
||||
gazetteer?: string
|
||||
} @cuetsy(kind="interface")
|
||||
@@ -1,7 +1,5 @@
|
||||
package common
|
||||
|
||||
// TODO break this up into individual files. Current limitation on this is codegen logic, imports, dependencies
|
||||
|
||||
// TODO docs
|
||||
AxisPlacement: "auto" | "top" | "right" | "bottom" | "left" | "hidden" @cuetsy(kind="enum")
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ export type {
|
||||
SpecialValueMap,
|
||||
ValueMappingResult,
|
||||
Transformation,
|
||||
MatcherConfig,
|
||||
RowPanel,
|
||||
GraphPanel,
|
||||
HeatmapPanel
|
||||
@@ -46,7 +45,6 @@ export {
|
||||
SpecialValueMatch,
|
||||
DashboardCursorSync,
|
||||
defaultDashboardCursorSync,
|
||||
defaultMatcherConfig,
|
||||
defaultRowPanel
|
||||
} from './raw/dashboard/x/dashboard_types.gen';
|
||||
|
||||
@@ -65,6 +63,7 @@ export type {
|
||||
DataSourceRef,
|
||||
Panel,
|
||||
FieldConfigSource,
|
||||
MatcherConfig,
|
||||
FieldConfig
|
||||
} from './veneer/dashboard.types';
|
||||
|
||||
@@ -83,6 +82,7 @@ export {
|
||||
VariableHide,
|
||||
defaultPanel,
|
||||
defaultFieldConfigSource,
|
||||
defaultMatcherConfig,
|
||||
defaultFieldConfig
|
||||
} from './veneer/dashboard.types';
|
||||
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import * as raw from '../common/common.gen';
|
||||
|
||||
import { MatcherConfig } from './dashboard.types';
|
||||
|
||||
export interface MapLayerOptions<TConfig = any> extends raw.MapLayerOptions {
|
||||
// Custom options depending on the type
|
||||
config?: TConfig;
|
||||
filterData?: MatcherConfig;
|
||||
}
|
||||
|
||||
export interface DataQuery extends raw.DataQuery {
|
||||
// TODO remove explicit nulls
|
||||
datasource?: raw.DataSourceRef | null;
|
||||
|
||||
@@ -43,6 +43,10 @@ export interface FieldConfigSource<TOptions = Record<string, unknown>> extends r
|
||||
defaults: FieldConfig<TOptions>;
|
||||
}
|
||||
|
||||
export interface MatcherConfig<TConfig = any> extends raw.MatcherConfig {
|
||||
options?: TConfig;
|
||||
}
|
||||
|
||||
export const defaultDashboard = raw.defaultDashboard as Dashboard;
|
||||
export const defaultVariableModel = {
|
||||
...raw.defaultVariableModel,
|
||||
@@ -60,3 +64,4 @@ export const defaultVariableModel = {
|
||||
export const defaultPanel: Partial<Panel> = raw.defaultPanel;
|
||||
export const defaultFieldConfig: Partial<FieldConfig> = raw.defaultFieldConfig;
|
||||
export const defaultFieldConfigSource: Partial<FieldConfigSource> = raw.defaultFieldConfigSource;
|
||||
export const defaultMatcherConfig: Partial<MatcherConfig> = raw.defaultMatcherConfig;
|
||||
|
||||
Reference in New Issue
Block a user