mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
71 lines
2.5 KiB
TypeScript
71 lines
2.5 KiB
TypeScript
import { SelectableValue } from '@grafana/data';
|
|
import { DataFrame, GrafanaTheme2 } from '@grafana/data/src';
|
|
import { getColorDimension, getScalarDimension, getScaledDimension, getTextDimension } from 'app/features/dimensions';
|
|
import { getGrafanaDatasource } from 'app/plugins/datasource/grafana/datasource';
|
|
|
|
import { defaultStyleConfig, StyleConfig, StyleConfigState, StyleDimensions } from '../style/types';
|
|
|
|
export function getStyleDimension(
|
|
frame: DataFrame | undefined,
|
|
style: StyleConfigState,
|
|
theme: GrafanaTheme2,
|
|
customStyleConfig?: StyleConfig
|
|
) {
|
|
const dims: StyleDimensions = {};
|
|
if (customStyleConfig && Object.keys(customStyleConfig).length) {
|
|
dims.color = getColorDimension(frame, customStyleConfig.color ?? defaultStyleConfig.color, theme);
|
|
dims.size = getScaledDimension(frame, customStyleConfig.size ?? defaultStyleConfig.size);
|
|
dims.rotation = getScalarDimension(frame, customStyleConfig.rotation ?? defaultStyleConfig.rotation);
|
|
if (customStyleConfig.text && (customStyleConfig.text.field || customStyleConfig.text.fixed)) {
|
|
dims.text = getTextDimension(frame, customStyleConfig.text!);
|
|
}
|
|
} else {
|
|
if (style.fields) {
|
|
if (style.fields.color) {
|
|
dims.color = getColorDimension(frame, style.config.color ?? defaultStyleConfig.color, theme);
|
|
}
|
|
if (style.fields.size) {
|
|
dims.size = getScaledDimension(frame, style.config.size ?? defaultStyleConfig.size);
|
|
}
|
|
if (style.fields.text) {
|
|
dims.text = getTextDimension(frame, style.config.text!);
|
|
}
|
|
if (style.fields.rotation) {
|
|
dims.rotation = getScalarDimension(frame, style.config.rotation ?? defaultStyleConfig.rotation);
|
|
}
|
|
}
|
|
}
|
|
|
|
return dims;
|
|
}
|
|
|
|
let publicGeoJSONFiles: Array<SelectableValue<string>> | undefined = undefined;
|
|
|
|
export function getPublicGeoJSONFiles(): Array<SelectableValue<string>> {
|
|
if (!publicGeoJSONFiles) {
|
|
publicGeoJSONFiles = [];
|
|
initGeojsonFiles(); // async
|
|
}
|
|
return publicGeoJSONFiles;
|
|
}
|
|
|
|
// This will find all geojson files in the maps and gazetteer folders
|
|
async function initGeojsonFiles() {
|
|
const ds = await getGrafanaDatasource();
|
|
for (let folder of ['maps', 'gazetteer']) {
|
|
ds.listFiles(folder).subscribe({
|
|
next: (frame) => {
|
|
frame.forEach((item) => {
|
|
if (item.name.endsWith('.geojson')) {
|
|
const value = `public/${folder}/${item.name}`;
|
|
publicGeoJSONFiles!.push({
|
|
value,
|
|
label: value,
|
|
});
|
|
}
|
|
});
|
|
},
|
|
});
|
|
}
|
|
}
|