Skip to content

Commit

Permalink
Encode scaling factor into URL
Browse files Browse the repository at this point in the history
Old links can still be opened with a default scaling factor of one.
Aka. No scaling.
  • Loading branch information
bmario committed Oct 16, 2024
1 parent a88a2ba commit 0023303
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/MetricQWebView.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ class MetricQWebView {

updateMetricUrl () {
let encodedStr = '.' + this.handler.startTime.getValue() + '*' + this.handler.stopTime.getValue()
for (const metricKey of this.store.getters['metrics/getAllKeys']()) {
encodedStr += '*' + metricKey
for (const metric of this.store.getters['metrics/getAll']()) {
if (metric.factor !== 1 && metric.factor !== undefined) {
encodedStr += '*(' + metric.key + '~' + metric.factor + ')'
} else {
encodedStr += '*' + metric.key
}
}
encodedStr = encodeURIComponent(encodedStr)
window.location.href =
Expand Down Expand Up @@ -108,7 +112,13 @@ class MetricQWebView {

async addMetric (metricBase, description = undefined, oldMetric = undefined) {
try {
await this.store.dispatch('metrics/create', { metric: { ...oldMetric, name: metricBase, description: description, traces: [] } })
if (metricBase.startsWith('(') && metricBase.endsWith(')')) {
const [metric, factorStr] = metricBase.substring(1, metricBase.length - 1).split('~')
const factor = Number.parseFloat(factorStr)
await this.store.dispatch('metrics/create', { metric: { ...oldMetric, name: metric, description: description, traces: [], factor: factor } })
} else {
await this.store.dispatch('metrics/create', { metric: { ...oldMetric, name: metricBase, description: description, traces: [] } })
}
return true
} catch (error) {
if (error instanceof Error.DuplicateMetricError) {
Expand Down
2 changes: 1 addition & 1 deletion src/data-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class DataCache {
class MetricCache {
constructor (paramMetricQReference, paramMetricName) {
this.name = paramMetricName
this.factor = 1
this.factor = store.getters['metrics/getFactor'](this.name)
this.color = store.getters['metrics/getColor'](this.name)
this.series = {
min: undefined,
Expand Down
7 changes: 6 additions & 1 deletion src/store/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export default {
getUnit: (state) => (metric) => {
return state.metrics[metric].unit
},
getFactor: (state) => (metric) => {
return state.metrics[metric].factor
},
getPeakedMetric: (state) => () => {
return state.peakedMetric
}
Expand Down Expand Up @@ -169,7 +172,8 @@ export default {
drawMax,
drawAvg,
pointsAgg,
pointsRaw
pointsRaw,
factor
}
}) {
if (state.metrics[name] !== undefined) {
Expand All @@ -193,6 +197,7 @@ export default {
// maybe we changed the globale draw state?
dispatch('checkGlobalDrawState')
dispatch('updateUnit', { metricKey: name, unit, metadataObj })
dispatch('updateFactor', { metricKey: name, factor })
}
},
updateDescription ({ commit }, { metricKey, description, metadataObj }) {
Expand Down
1 change: 1 addition & 0 deletions src/ui/metric-popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export default {
factor = 1
}
this.$store.dispatch('metrics/updateFactor', { metricKey: this.metric.key, factor })
window.MetricQWebView.updateMetricUrl()
},
changeDraw (evt) {
if (this.metric.drawMin === false && this.metric.drawAvg === false && this.metric.drawMax === false) {
Expand Down

0 comments on commit 0023303

Please sign in to comment.