Skip to content

Commit

Permalink
Merge pull request #178 from gisce/70676/indicator-dynamic-conditions
Browse files Browse the repository at this point in the history
Indicator: allow dynamic icon and color
  • Loading branch information
ecarreras authored Mar 4, 2025
2 parents 0ec23d6 + 9694074 commit 92e8bd5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Indicator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Selection from "./Selection";
import { replaceEntities } from "./helpers/attributeParser";

class Indicator extends Selection {
_nolabel: boolean = true;
Expand Down Expand Up @@ -30,6 +31,11 @@ class Indicator extends Selection {
this._suffix = value;
}

_color: string = "";
get color(): string {
return this._color;
}

/**
* Action id
*/
Expand Down Expand Up @@ -58,8 +64,9 @@ class Indicator extends Selection {
this._suffix = "";
if (this._parsedWidgetProps) {
this._card = this._parsedWidgetProps.card || false;
this._icon = this._parsedWidgetProps.icon || "";
this._icon = replaceEntities(this._parsedWidgetProps.icon) || "";
this._suffix = this._parsedWidgetProps.suffix || "";
this._color = replaceEntities(this._parsedWidgetProps.color) || "";
}
if (props) {
if (props.action_id) {
Expand Down
16 changes: 16 additions & 0 deletions src/spec/Indicator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,20 @@ describe("An Indicator", () => {
const widget = widgetFactory.createWidget("indicator", props);
expect(widget.card).toBe(false);
});
it("should allow conditions in icon widget props", () => {
const widgetFactory = new WidgetFactory();
const props = {
widget_props: "{'icon': 'alert-triange:value>10;wallet:value==0'}",
};
const widget = widgetFactory.createWidget("indicator", props);
expect(widget.icon).toBe("alert-triange:value>10;wallet:value==0");
});
it("should allow color in widget props", () => {
const widgetFactory = new WidgetFactory();
const props = {
widget_props: "{'color': 'red'}",
};
const widget = widgetFactory.createWidget("indicator", props);
expect(widget.color).toBe("red");
});
});

0 comments on commit 92e8bd5

Please sign in to comment.