mirror of
https://github.com/zaphar/Heracles.git
synced 2025-07-23 04:29:48 -04:00
feat: Allow formatting the yaxis tick marks
This commit is contained in:
parent
26782b2bfc
commit
349003bd6f
@ -3,12 +3,12 @@
|
|||||||
graphs:
|
graphs:
|
||||||
- title: Node cpu
|
- title: Node cpu
|
||||||
source: http://heimdall:9001
|
source: http://heimdall:9001
|
||||||
query: 'sum by (instance)(irate(node_cpu_seconds_total{mode="system",job="nodestats"}[5m])) * 100'
|
query: 'sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m]))'
|
||||||
query_type: Range
|
query_type: Range
|
||||||
span:
|
span:
|
||||||
end: now
|
end: now
|
||||||
duration: 1d
|
duration: 1d
|
||||||
step_duration: 1h
|
step_duration: 10min
|
||||||
name_label: instance
|
name_label: instance
|
||||||
- title: Test Dasbboard 2
|
- title: Test Dasbboard 2
|
||||||
span:
|
span:
|
||||||
@ -16,9 +16,11 @@
|
|||||||
duration: 2 days
|
duration: 2 days
|
||||||
step_duration: 1 minute
|
step_duration: 1 minute
|
||||||
graphs:
|
graphs:
|
||||||
- title: Node cpu
|
- title: Node cpu sytem percent
|
||||||
source: http://heimdall:9001
|
source: http://heimdall:9001
|
||||||
query: 'sum by (instance)(irate(node_cpu_seconds_total{mode="system",job="nodestats"}[5m])) * 100'
|
query: |
|
||||||
|
sum by (instance)(irate(node_cpu_seconds_total{mode="system",job="nodestats"}[5m])) / sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m]))
|
||||||
|
d3_tick_format: "~%"
|
||||||
query_type: Range
|
query_type: Range
|
||||||
name_label: instance
|
name_label: instance
|
||||||
- title: Node memory
|
- title: Node memory
|
||||||
|
@ -44,6 +44,7 @@ pub struct Graph {
|
|||||||
pub span: Option<GraphSpan>,
|
pub span: Option<GraphSpan>,
|
||||||
pub name_label: String,
|
pub name_label: String,
|
||||||
pub query_type: QueryType,
|
pub query_type: QueryType,
|
||||||
|
pub d3_tick_format: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn duration_from_string(duration_string: &str) -> Option<Duration> {
|
fn duration_from_string(duration_string: &str) -> Option<Duration> {
|
||||||
|
@ -82,7 +82,11 @@ pub fn graph_component(dash_idx: usize, graph_idx: usize, graph: &Graph) -> Mark
|
|||||||
html!(
|
html!(
|
||||||
div {
|
div {
|
||||||
h2 { (graph.title) }
|
h2 { (graph.title) }
|
||||||
timeseries-graph uri=(graph_data_uri) id=(graph_id) label=(graph.name_label) { }
|
@if graph.d3_tick_format.is_some() {
|
||||||
|
timeseries-graph uri=(graph_data_uri) id=(graph_id) label=(graph.name_label) d3-tick-format=(graph.d3_tick_format.as_ref().unwrap()) { }
|
||||||
|
} @else {
|
||||||
|
timeseries-graph uri=(graph_data_uri) id=(graph_id) label=(graph.name_label) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ class TimeseriesGraph extends HTMLElement {
|
|||||||
#end;
|
#end;
|
||||||
#duration;
|
#duration;
|
||||||
#step_duration;
|
#step_duration;
|
||||||
|
#d3TickFormat = "~s";
|
||||||
#targetNode = null;
|
#targetNode = null;
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -31,7 +32,7 @@ class TimeseriesGraph extends HTMLElement {
|
|||||||
this.#targetNode = this.appendChild(document.createElement("div"));
|
this.#targetNode = this.appendChild(document.createElement("div"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static observedAttributes = ['uri', 'width', 'height', 'poll-seconds', 'end', 'duration', 'step-duration'];
|
static observedAttributes = ['uri', 'width', 'height', 'poll-seconds', 'end', 'duration', 'step-duration', 'd3-tick-format'];
|
||||||
|
|
||||||
attributeChangedCallback(name, _oldValue, newValue) {
|
attributeChangedCallback(name, _oldValue, newValue) {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
@ -59,6 +60,9 @@ class TimeseriesGraph extends HTMLElement {
|
|||||||
case 'step-duration':
|
case 'step-duration':
|
||||||
this.#step_duration = newValue;
|
this.#step_duration = newValue;
|
||||||
break;
|
break;
|
||||||
|
case 'd3-tick-format':
|
||||||
|
this.#d3TickFormat = newValue;
|
||||||
|
break;
|
||||||
default: // do nothing;
|
default: // do nothing;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -74,6 +78,7 @@ class TimeseriesGraph extends HTMLElement {
|
|||||||
this.#end = this.getAttribute('end') || null;
|
this.#end = this.getAttribute('end') || null;
|
||||||
this.#duration = this.getAttribute('duration') || null;
|
this.#duration = this.getAttribute('duration') || null;
|
||||||
this.#step_duration = this.getAttribute('step-duration') || null;
|
this.#step_duration = this.getAttribute('step-duration') || null;
|
||||||
|
this.#d3TickFormat = this.getAttribute('d3-tick-format') || this.#d3TickFormat;
|
||||||
this.resetInterval()
|
this.resetInterval()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,8 +136,15 @@ class TimeseriesGraph extends HTMLElement {
|
|||||||
};
|
};
|
||||||
const layout = {
|
const layout = {
|
||||||
displayModeBar: false,
|
displayModeBar: false,
|
||||||
responsive: true
|
responsive: true,
|
||||||
|
yaxis: {
|
||||||
|
tickformat: this.#d3TickFormat,
|
||||||
|
//showticksuffix: 'all',
|
||||||
|
//ticksuffix: '%',
|
||||||
|
//exponentFormat: 'SI'
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
console.debug("layout", layout);
|
||||||
if (data.Series) {
|
if (data.Series) {
|
||||||
// https://plotly.com/javascript/reference/scatter/
|
// https://plotly.com/javascript/reference/scatter/
|
||||||
var traces = [];
|
var traces = [];
|
||||||
@ -155,7 +167,7 @@ class TimeseriesGraph extends HTMLElement {
|
|||||||
traces.push(trace);
|
traces.push(trace);
|
||||||
}
|
}
|
||||||
// https://plotly.com/javascript/plotlyjs-function-reference/#plotlyreact
|
// https://plotly.com/javascript/plotlyjs-function-reference/#plotlyreact
|
||||||
Plotly.react(this.getTargetNode(), traces, config, layout);
|
Plotly.react(this.getTargetNode(), traces, layout, config);
|
||||||
} else if (data.Scalar) {
|
} else if (data.Scalar) {
|
||||||
// https://plotly.com/javascript/reference/bar/
|
// https://plotly.com/javascript/reference/bar/
|
||||||
var traces = [];
|
var traces = [];
|
||||||
@ -173,7 +185,7 @@ class TimeseriesGraph extends HTMLElement {
|
|||||||
trace.y.push(series.value);
|
trace.y.push(series.value);
|
||||||
traces.push(trace);
|
traces.push(trace);
|
||||||
}
|
}
|
||||||
Plotly.react(this.getTargetNode(), traces, config, layout);
|
Plotly.react(this.getTargetNode(), traces, layout, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user