@grafana/data#LinkModelSupplier TypeScript Examples
The following examples show how to use
@grafana/data#LinkModelSupplier.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: dataLinks.ts From grafana-chinese with Apache License 2.0 | 6 votes |
linkModelToContextMenuItems: (links: LinkModelSupplier<any>) => ContextMenuItem[] = links => {
return links.getLinks().map(link => {
return {
label: link.title,
// TODO: rename to href
url: link.href,
target: link.target,
icon: `fa ${link.target === '_self' ? 'fa-link' : 'fa-external-link'}`,
onClick: link.onClick,
};
});
}
Example #2
Source File: linkSuppliers.ts From grafana-chinese with Apache License 2.0 | 6 votes |
getPanelLinksSupplier = (value: PanelModel): LinkModelSupplier<PanelModel> => {
const links = value.links;
if (!links || links.length === 0) {
return undefined;
}
return {
getLinks: () => {
return links.map(link => {
return getLinkSrv().getDataLinkUIModel(link, value.scopedVars, value);
});
},
};
}
Example #3
Source File: graph.ts From grafana-chinese with Apache License 2.0 | 6 votes |
getContextMenuItemsSupplier = (
flotPosition: { x: number; y: number },
linksSupplier?: LinkModelSupplier<FieldDisplay>
): (() => ContextMenuGroup[]) => {
return () => {
// Fixed context menu items
const items: ContextMenuGroup[] = [
{
items: [
{
label: 'Add annotation',
icon: 'gicon gicon-annotation',
onClick: () => this.eventManager.updateTime({ from: flotPosition.x, to: null }),
},
],
},
];
if (!linksSupplier) {
return items;
}
const dataLinks = [
{
items: linksSupplier.getLinks(this.panel.scopedVars).map<ContextMenuItem>(link => {
return {
label: link.title,
url: link.href,
target: link.target,
icon: `fa ${link.target === '_self' ? 'fa-link' : 'fa-external-link'}`,
onClick: link.onClick,
};
}),
},
];
return [...items, ...dataLinks];
};
};
Example #4
Source File: linkSuppliers.ts From grafana-chinese with Apache License 2.0 | 5 votes |
getFieldLinksSupplier = (value: FieldDisplay): LinkModelSupplier<FieldDisplay> | undefined => {
const links = value.field.links;
if (!links || links.length === 0) {
return undefined;
}
return {
getLinks: (_scopedVars?: any) => {
const scopedVars: DataLinkScopedVars = {};
if (value.view) {
const { dataFrame } = value.view;
scopedVars['__series'] = {
value: {
name: dataFrame.name,
refId: dataFrame.refId,
},
text: 'Series',
};
const field = value.colIndex !== undefined ? dataFrame.fields[value.colIndex] : undefined;
if (field) {
console.log('Full Field Info:', field);
scopedVars['__field'] = {
value: {
name: field.name,
labels: field.labels,
},
text: 'Field',
};
}
if (!isNaN(value.rowIndex)) {
const { timeField } = getTimeField(dataFrame);
scopedVars['__value'] = {
value: {
raw: field.values.get(value.rowIndex),
numeric: value.display.numeric,
text: formattedValueToString(value.display),
time: timeField ? timeField.values.get(value.rowIndex) : undefined,
},
text: 'Value',
};
// Expose other values on the row
if (value.view) {
scopedVars['__data'] = {
value: {
name: dataFrame.name,
refId: dataFrame.refId,
fields: getFieldDisplayValuesProxy(dataFrame, value.rowIndex!),
},
text: 'Data',
};
}
} else {
// calculation
scopedVars['__value'] = {
value: {
raw: value.display.numeric,
numeric: value.display.numeric,
text: formattedValueToString(value.display),
calc: value.name,
},
text: 'Value',
};
}
} else {
console.log('VALUE', value);
}
return links.map(link => {
return getLinkSrv().getDataLinkUIModel(link, scopedVars, value);
});
},
};
}
Example #5
Source File: graph.ts From grafana-chinese with Apache License 2.0 | 5 votes |
onPlotClick(event: JQueryEventObject, pos: any, item: any) {
const scrollContextElement = this.elem.closest('.view') ? this.elem.closest('.view').get()[0] : null;
const contextMenuSourceItem = item;
if (this.panel.xaxis.mode !== 'time') {
// Skip if panel in histogram or series mode
return;
}
if ((pos.ctrlKey || pos.metaKey) && (this.dashboard.meta.canEdit || this.dashboard.meta.canMakeEditable)) {
// Skip if range selected (added in "plotselected" event handler)
if (pos.x !== pos.x1) {
return;
}
setTimeout(() => {
this.eventManager.updateTime({ from: pos.x, to: null });
}, 100);
return;
} else {
this.tooltip.clear(this.plot);
let linksSupplier: LinkModelSupplier<FieldDisplay>;
if (item) {
// pickup y-axis index to know which field's config to apply
const yAxisConfig = this.panel.yaxes[item.series.yaxis.n === 2 ? 1 : 0];
const dataFrame = this.ctrl.dataList[item.series.dataFrameIndex];
const field = dataFrame.fields[item.series.fieldIndex];
const dataIndex = this.getDataIndexWithNullValuesCorrection(item, dataFrame);
let links = this.panel.options.dataLinks || [];
if (field.config.links && field.config.links.length) {
// Append the configured links to the panel datalinks
links = [...links, ...field.config.links];
}
const fieldConfig = {
decimals: yAxisConfig.decimals,
links,
};
const fieldDisplay = getDisplayProcessor({
field: { config: fieldConfig, type: FieldType.number },
theme: getCurrentTheme(),
})(field.values.get(dataIndex));
linksSupplier = links.length
? getFieldLinksSupplier({
display: fieldDisplay,
name: field.name,
view: new DataFrameView(dataFrame),
rowIndex: dataIndex,
colIndex: item.series.fieldIndex,
field: fieldConfig,
})
: undefined;
}
this.scope.$apply(() => {
// Setting nearest CustomScrollbar element as a scroll context for graph context menu
this.contextMenu.setScrollContextElement(scrollContextElement);
this.contextMenu.setSource(contextMenuSourceItem);
this.contextMenu.setMenuItemsSupplier(this.getContextMenuItemsSupplier(pos, linksSupplier) as any);
this.contextMenu.toggleMenu(pos);
});
}
}