Skip to content

Commit

Permalink
Update README with Documentation (#35)
Browse files Browse the repository at this point in the history
* Update README with Documentation

* Add Panels Documentation

* Add Scoped Variables for Variables replacement
  • Loading branch information
mikhail-vl authored Mar 27, 2023
1 parent b7fcf3e commit a353ef3
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Changelog

## 2.2.0 (2023-03-24)
## 2.2.0 (2023-03-27)

### Features / Enhancements

- Update CI and Release workflows (#33)
- Update to Grafana 9.4.7 (#34)
- Update README with Documentation (#35)
- Add Scoped Variables for Variables replacement (#35)

## 2.1.0 (2022-12-29)

Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,19 @@ grafana-cli plugins install marcusolsson-static-datasource

## Documentation

- [Provisioning](https://volkovlabs.io/plugins/volkovlabs-static-datasource/provisioning)
- [Variables](https://volkovlabs.io/plugins/volkovlabs-static-datasource/variables)
| Section | Description |
| ---------------------------- | ------------------------------------------------------------ |
| [Provisioning](https://volkovlabs.io/plugins/volkovlabs-static-datasource/provisioning/) | Demonstrates how to automatically provision the Data Source. |
| [Variables](https://volkovlabs.io/plugins/volkovlabs-static-datasource/variables/) | Demonstrates how to use variables. |

### Panels

| Section | Description |
| -------------------------------- | ------------------------------------------------------------- |
| [Base64 Image/PDF](https://volkovlabs.io/plugins/volkovlabs-static-datasource/panels/image) | Demonstrates how to use the data source with image panels. |
| [Logs](https://volkovlabs.io/plugins/volkovlabs-static-datasource/panels/logs) | Demonstrates how to use the data source with logs panels. |
| [Node Graph](https://volkovlabs.io/plugins/volkovlabs-static-datasource/panels/graph) | Demonstrates how to use the data source with graph panels. |
| [Pie Chart](https://volkovlabs.io/plugins/volkovlabs-static-datasource/panels/pie) | Demonstrates how to use the data source with category panels. |

## Feedback

Expand Down
2 changes: 1 addition & 1 deletion src/datasource/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class DataSource extends DataSourceApi<StaticQuery, StaticDataSourceOptio
.filter((target) => !target.hide)
.filter((target) => target.frame)
.map((target) => ({ ...toDataFrame(target.frame), refId: target.refId }))
.map(interpolateVariables),
.map((target) => interpolateVariables(target, options.scopedVars)),
};
}

Expand Down
Binary file modified src/img/dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/img/light.png
Binary file not shown.
6 changes: 1 addition & 5 deletions src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@
"small": "img/logo.svg"
},
"screenshots": [
{
"name": "Explore",
"path": "img/dark.png"
},
{
"name": "Pie Chart",
"path": "img/light.png"
"path": "img/dark.png"
}
],
"updated": "%TODAY%",
Expand Down
10 changes: 6 additions & 4 deletions src/utils/variable.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { ArrayVector, DataFrame, FieldType } from '@grafana/data';
import { ArrayVector, DataFrame, FieldType, ScopedVars } from '@grafana/data';
import { getTemplateSrv } from '@grafana/runtime';

/**
* Interpolate variables in string fields.
* Interpolate variables in String fields.
*/
export const interpolateVariables = (frame: DataFrame) => {
export const interpolateVariables = (frame: DataFrame, scopedVars: ScopedVars) => {
for (let i = 0; i < frame.fields.length; i++) {
const field = frame.fields[i];

/**
* Update String fields
*/
if (field.type === FieldType.string) {
field.values = new ArrayVector(field.values.toArray().map((value) => getTemplateSrv().replace(value, {}, 'csv')));
field.values = new ArrayVector(
field.values.toArray().map((value) => getTemplateSrv().replace(value, scopedVars, 'csv'))
);
}

frame.fields[i] = field;
Expand Down

0 comments on commit a353ef3

Please sign in to comment.