Skip to content

Commit e2ee0af

Browse files
committed
things are a mess
1 parent c89c688 commit e2ee0af

File tree

10 files changed

+47
-85
lines changed

10 files changed

+47
-85
lines changed

src/MetricHandler.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,10 @@ export class MetricHandler {
1212

1313
this.WIGGLEROOM_PERCENTAGE = 0.05
1414
this.TIME_MARGIN_FACTOR = 1.00 / 3
15-
16-
this.initializeMetrics([])
17-
}
18-
19-
initializeMetrics (initialMetricNames) {
20-
this.store.commit('metrics/resetAll')
21-
for (let i = 0; i < initialMetricNames.length; ++i) {
22-
const curMetricName = initialMetricNames[i]
23-
window.MetricQWebView.addMetric(curMetricName)
24-
}
2515
}
2616

2717
doRequest (maxDataPoints) {
18+
if (maxDataPoints === 0) return
2819
const timeMargin = (this.stopTime.getUnix() - this.startTime.getUnix()) * this.TIME_MARGIN_FACTOR
2920
const metrics = []
3021
const errorProneMetrics = []

src/MetricQWebView.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@ class MetricQWebView {
4747
registerCallbacks(myCanvas)
4848
}
4949

50-
reinitialize (metricsArr, startTime, stopTime) {
51-
this.handler.initializeMetrics(metricsArr)
50+
async reinitialize (metrics, startTime, stopTime) {
51+
this.store.commit('metrics/resetAll')
52+
53+
for (const metric of metrics) {
54+
await this.addMetric(metric)
55+
}
56+
5257
this.handler.startTime.updateTime(startTime)
5358
this.handler.stopTime.updateTime(stopTime)
5459
}
@@ -197,7 +202,7 @@ function determineTimeRangeOfJsUrl (request) {
197202
return [timeStart, timeEnd]
198203
}
199204

200-
export function importMetricUrl () {
205+
export async function importMetricUrl () {
201206
const fragment = parseLocationHref()[1]
202207

203208
if (fragment.length === 0) return false
@@ -216,7 +221,9 @@ export function importMetricUrl () {
216221
return false
217222
}
218223
const timeRange = determineTimeRangeOfJsUrl(request)
219-
window.MetricQWebView.reinitialize(request.cntr, timeRange[0], timeRange[1])
224+
await window.MetricQWebView.reinitialize(request.cntr, timeRange[0], timeRange[1])
225+
window.MetricQWebView.store.dispatch('metrics/updateDrawStateGlobally', false)
226+
window.MetricQWebView.store.dispatch('metrics/setDistinctColors')
220227
return true
221228
} else if (fragment.startsWith('.')) {
222229
const splitted = fragment.split('*')

src/app.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,8 @@ export const mainApp = new Vue({
8383
},
8484
methods: {
8585
colorPaletteClicked () {
86-
const palette = distinctColors({ count: this.metricsList.length, lightMin: 25, lightMax: 75 }).values()
87-
this.metricsList.forEach((metric) => {
88-
const color = palette.next().value.css()
89-
this.$store.dispatch('metrics/updateColor', { metricKey: metric.key, color: color })
90-
})
86+
this.$store.dispatch('metrics/setDistinctColors')
87+
window.MetricQWebView.graticule.draw(false)
9188
},
9289
exportButtonClicked () {
9390
this.togglePopup('export')
@@ -103,6 +100,7 @@ export const mainApp = new Vue({
103100
},
104101
toggleMinMaxButton (evt) {
105102
this.$store.dispatch('metrics/updateDrawStateGlobally', evt.target.checked)
103+
window.MetricQWebView.graticule.draw(false)
106104
},
107105
...mapMutations([
108106
'togglePopup'

src/configuration.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export async function getMetricQBackendConfig () {
2323
type: 'GET',
2424
dataType: 'json'
2525
})
26-
config.backend = json.backend
27-
config.user = json.user
28-
config.password = json.password
29-
config.legacyCharts = json.legacyCharts
26+
config.backend = json.backend ?? config.backend
27+
config.user = json.user ?? config.user
28+
config.password = json.password ?? config.password
29+
config.legacyCharts = json.legacyCharts ?? config.legacyCharts
3030
} catch (exc) {
3131
console.log('Could not load backend config.')
3232
console.log(exc)

src/data-handling.js

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { crc32 } from '../lib/pseudo-crc32.js'
2-
import { hslToRgb } from '../lib/color-conversion.js'
31
import moment from 'moment'
42
import store from './store/'
53

@@ -209,7 +207,7 @@ export class DataCache {
209207
return units
210208
}
211209

212-
initializeCacheWithColor (metricName, newColor) {
210+
initializeCache (metricName) {
213211
const newCache = this.assureMetricExists(metricName)
214212
Object.keys(newCache.series).forEach((aggregate) => { this.newSeries(metricName, aggregate) })
215213
if (!newCache.band) {
@@ -218,18 +216,13 @@ export class DataCache {
218216
const toUpdate = [newCache.band]
219217
Object.keys(newCache.series).forEach((aggregate) => { toUpdate.push(newCache.series[aggregate]) })
220218

221-
toUpdate.forEach((val) => {
222-
val.styleOptions.color = newColor
223-
})
224-
225219
return newCache
226220
}
227221
}
228222

229223
class MetricCache {
230224
constructor (paramMetricQReference, paramMetricName) {
231225
this.name = paramMetricName
232-
this.color = determineColorForMetric(paramMetricName)
233226
this.series = {
234227
min: undefined,
235228
max: undefined,
@@ -340,29 +333,11 @@ class MetricCache {
340333
}
341334

342335
defaultBandStyling () {
343-
const options = matchStylingOptions('band')
344-
if (options.color === 'default') {
345-
options.color = this.color
346-
}
347-
return options
336+
return matchStylingOptions('band')
348337
}
349338

350339
defaultSeriesStyling (aggregateName) {
351-
const options = matchStylingOptions(aggregateName)
352-
if (options.color === 'default') {
353-
options.color = this.color
354-
}
355-
return options
356-
}
357-
358-
updateColor (color) {
359-
this.color = color
360-
this.band.styleOptions.color = color
361-
for (const key in this.series) {
362-
if (this.series[key]) {
363-
this.series[key].styleOptions.color = color
364-
}
365-
}
340+
return matchStylingOptions(aggregateName)
366341
}
367342
}
368343

@@ -577,7 +552,6 @@ class Point {
577552
constructor (paramTime, paramValue) {
578553
this.time = paramTime
579554
this.value = paramValue
580-
this.count = undefined
581555
}
582556

583557
clone () {
@@ -589,7 +563,6 @@ const stylingOptions = {
589563
avg: {
590564
title: 'AVG Series',
591565
skip: false,
592-
color: 'default',
593566
connect: 'next',
594567
width: 8,
595568
lineWidth: 2,
@@ -599,7 +572,6 @@ const stylingOptions = {
599572
min: {
600573
title: 'Min Series',
601574
skip: true,
602-
color: 'default',
603575
connect: 'next',
604576
width: 2,
605577
lineWidth: 2,
@@ -609,7 +581,6 @@ const stylingOptions = {
609581
max: {
610582
title: 'Max Series',
611583
skip: true,
612-
color: 'default',
613584
connect: 'next',
614585
width: 2,
615586
lineWidth: 2,
@@ -619,7 +590,6 @@ const stylingOptions = {
619590
raw: {
620591
title: 'Raw Series',
621592
skip: false,
622-
color: 'default',
623593
connect: 'none',
624594
width: 8,
625595
dots: true
@@ -628,7 +598,6 @@ const stylingOptions = {
628598
title: 'All Bands',
629599
skip: false,
630600
connect: 'next',
631-
color: 'default',
632601
alpha: 0.3
633602
}
634603
}
@@ -639,8 +608,3 @@ function matchStylingOptions (styleType) {
639608
}
640609
return JSON.parse(JSON.stringify(stylingOptions[styleType]))
641610
}
642-
643-
function determineColorForMetric (metricBaseName) {
644-
const rgb = hslToRgb((crc32(metricBaseName) >> 24 & 255) / 255.00, 1, 0.46)
645-
return 'rgb(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ')'
646-
}

src/graticule.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -725,10 +725,6 @@ export class Graticule {
725725
}
726726

727727
// second parse Options to be applied to ctx immediatly
728-
if (styleOptions.color !== undefined) {
729-
ctx.fillStyle = styleOptions.color
730-
ctx.strokeStyle = styleOptions.color
731-
}
732728
if (styleOptions.alpha !== undefined) {
733729
ctx.globalAlpha = parseFloat(styleOptions.alpha)
734730
}
@@ -747,6 +743,9 @@ export class Graticule {
747743
const curBand = this.data.metrics[i].band
748744
if (curBand) {
749745
const styleOptions = this.parseStyleOptions(curBand.styleOptions, ctx)
746+
const color = store.getters['metrics/getColor'](this.data.metrics[i].name)
747+
ctx.fillStyle = color
748+
ctx.strokeStyle = color
750749
if (styleOptions.skip || curBand.points.length === 0) {
751750
this.resetCtx(ctx)
752751
continue
@@ -826,11 +825,14 @@ export class Graticule {
826825
const curSeries = this.data.metrics[i].series[curAggregate]
827826
if (curSeries) {
828827
const styleOptions = this.parseStyleOptions(curSeries.styleOptions, ctx)
828+
const color = store.getters['metrics/getColor'](this.data.metrics[i].name)
829+
ctx.fillStyle = color
830+
ctx.strokeStyle = color
829831
if (styleOptions.skip || curSeries.points.length === 0) {
830832
this.resetCtx(ctx)
831833
continue
832834
}
833-
const offsiteCanvas = this.generateOffsiteDot(styleOptions)
835+
const offsiteCanvas = this.generateOffsiteDot(styleOptions, color)
834836

835837
for (let j = 0, x, y, previousX, previousY; j < curSeries.points.length; ++j) {
836838
x = graticuleDimensions.x + Math.round((curSeries.points[j].time - timeRange[0]) / timePerPixel)
@@ -951,8 +953,7 @@ export class Graticule {
951953
* which then we can use to paste it to wherever we need that kind
952954
* of symbol as a marker
953955
*/
954-
generateOffsiteDot (styleOptions) {
955-
const BODY = document.getElementsByTagName('body')[0]
956+
generateOffsiteDot (styleOptions, color) {
956957
const canvas = document.createElement('canvas')
957958
const ctxDimensions = [styleOptions.pointWidth,
958959
styleOptions.pointWidth]
@@ -967,8 +968,8 @@ export class Graticule {
967968
const canvasCtx = canvas.getContext('2d')
968969
if (styleOptions.drawDots) {
969970
canvasCtx.lineWidth = 1
970-
canvasCtx.fillStyle = styleOptions.color
971-
canvasCtx.strokeStyle = styleOptions.color
971+
canvasCtx.fillStyle = color
972+
canvasCtx.strokeStyle = color
972973
styleOptions.drawDots.func(canvasCtx, ctxDimensions[0], ctxDimensions[1])
973974
}
974975
return {

src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async function startup () {
1515
let imported = false
1616

1717
try {
18-
imported = importMetricUrl()
18+
imported = await importMetricUrl()
1919
} catch (exc) {
2020
Vue.toasted.error('Ungültige URL: Metriken konnten nicht hinzugefügt werden.', store.state.toastConfiguration)
2121
console.log('Could not import metrics.')

src/metric.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { hslToRgb } from '../lib/color-conversion.js'
22
import { crc32 } from '../lib/pseudo-crc32.js'
3-
import store from './store/'
43

54
// adapted from https://plot.ly/python/marker-style/
65
// not working:

src/store/metrics.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Vue from 'vue'
22
import store from '@/store/index'
33
import { MetricHelper } from '@/metric'
44
import * as Error from '@/errors'
5+
import distinctColors from 'distinct-colors'
56

67
export default {
78
namespaced: true,
@@ -26,6 +27,9 @@ export default {
2627
},
2728
get: (state) => (metricKey) => {
2829
return state.metrics[metricKey]
30+
},
31+
getColor: (state) => (metric) => {
32+
return state.metrics[metric].color
2933
}
3034
},
3135
mutations: {
@@ -197,17 +201,8 @@ export default {
197201
}
198202
commit('privateSet', { metricKey, metric: { unit: unit } })
199203
},
200-
updateColor ({ commit, state }, { metricKey, color }) {
204+
updateColor ({ commit }, { metricKey, color }) {
201205
commit('privateSet', { metricKey, metric: { color } })
202-
const name = state.metrics[metricKey].name
203-
const renderer = window.MetricQWebView
204-
if (renderer && renderer.graticule && renderer.graticule.data) {
205-
const metricCache = renderer.graticule.data.getMetricCache(name)
206-
if (metricCache) {
207-
metricCache.updateColor(color)
208-
renderer.graticule.draw(false)
209-
}
210-
}
211206
},
212207
redraw () {
213208
window.MetricQWebView.graticule.draw(false)
@@ -244,9 +239,16 @@ export default {
244239
}
245240
commit('privateSet', { metricKey, metric: newDrawStates })
246241
}
247-
window.MetricQWebView.graticule.draw(false)
248242
commit('setGlobalMinMax', newState, { root: true })
249243
},
244+
setDistinctColors ({ state, dispatch }) {
245+
const metrics = Object.keys(state.metrics)
246+
const palette = distinctColors({ count: metrics.length, lightMin: 25, lightMax: 75 }).values()
247+
metrics.forEach((metric) => {
248+
const color = palette.next().value.css()
249+
dispatch('updateColor', { metricKey: metric, color: color })
250+
})
251+
},
250252
updateDrawState ({ dispatch, commit }, { metricKey, drawState: { drawMin, drawAvg, drawMax } }) {
251253
commit('privateSet', { metricKey, metric: { drawMin, drawAvg, drawMax } })
252254
dispatch('checkGlobalDrawState')

src/ui/metric-popup.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export default {
219219
this.$store.dispatch('metrics/updateMarker', { metricKey, marker: paramMyMetric.marker })
220220
}
221221
// don't do a complete repaint
222-
// renderMetrics();
222+
window.MetricQWebView.graticule.draw(false)
223223
}
224224
}
225225
})(this.metric, this.newMetric)

0 commit comments

Comments
 (0)