Skip to content

Commit d0faedf

Browse files
authored
Merge pull request #58 from jberryman/dev
web-app histogram improvements
2 parents 2e1cb0a + b273743 commit d0faedf

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

app/web-app/index.js

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,6 @@ const getColor = () => {
2929
const hist_points = ['min', 'p50', 'p75', 'p90', 'p99', 'p99_9', 'max']
3030
const hist_labels = ['min', '50%', '75%', '90%', '99%', '99.9%','max']
3131

32-
const makeChartJSDataset = (benchDataEntry) => {
33-
const label = benchDataEntry.name
34-
const data = hist_points.map((p) => benchDataEntry.histogram.json[p])
35-
return {
36-
label,
37-
data,
38-
fill: false,
39-
borderWidth: 1,
40-
pointRadius: 2.5,
41-
pointBackgroundColor: 'white',
42-
borderColor: getColor(),
43-
}
44-
}
45-
4632
const benchmarkEntryToTableValue = (item) => {
4733
return {
4834
name: item.name,
@@ -689,7 +675,7 @@ app.component('DataTable', {
689675
})
690676

691677
// Options for our hdr-histogram-style line chart, factored out for re-use:
692-
const makeLatencyLineChartOptions = (otherPlugins, enable_crosshair_zoom = true) => {
678+
const makeLatencyLineChartOptions = (minDataPoint, maxDataPoint, otherPlugins, enable_crosshair_zoom = true) => {
693679
return {
694680
tooltips: {
695681
mode: 'interpolate',
@@ -765,6 +751,8 @@ const makeLatencyLineChartOptions = (otherPlugins, enable_crosshair_zoom = true)
765751
labelString: 'Response Time (ms)',
766752
},
767753
ticks: {
754+
min: minDataPoint,
755+
max: maxDataPoint,
768756
maxTicksLimit: 10,
769757
padding: 5,
770758
fontSize: 12,
@@ -800,18 +788,42 @@ app.component('LatencyLineChart', {
800788
</div>
801789
`,
802790
setup(props) {
791+
// Collect these so we can properly scale our axes as tight as possible to data
792+
// (maybe new versions of chart.js make this less painful)
793+
var minDataPoint = Number.MAX_SAFE_INTEGER
794+
var maxDataPoint = Number.MIN_SAFE_INTEGER
795+
const makeDataset = (benchDataEntry) => {
796+
minDataPoint = Math.min(minDataPoint, benchDataEntry.histogram.json['min'])
797+
maxDataPoint = Math.max(maxDataPoint, benchDataEntry.histogram.json['max'])
798+
const label = benchDataEntry.name
799+
const data = hist_points.map((p) => benchDataEntry.histogram.json[p])
800+
return {
801+
label,
802+
data,
803+
fill: false,
804+
borderWidth: 1,
805+
pointRadius: 2.5,
806+
pointBackgroundColor: 'white',
807+
borderColor: getColor(),
808+
// Smooth lines, but monotone (no misleading up/down "swooping" to fit data points)
809+
cubicInterpolationMode: 'monotone',
810+
// tension: 0.4, //... I'm not convinced this actually does anything...
811+
}
812+
}
813+
803814
const chartElem = ref(null)
804815
onMounted(() => {
805816
const ctx = chartElem.value.getContext('2d')
817+
const datasets = props.benchData.map(makeDataset)
806818
const myChart = new Chart(ctx, {
807819
responsive: true,
808820
maintainAspectRatio: false,
809821
type: 'line',
810822
data: {
811823
labels: hist_labels,
812-
datasets: props.benchData.map(makeChartJSDataset),
824+
datasets,
813825
},
814-
options: makeLatencyLineChartOptions({}),
826+
options: makeLatencyLineChartOptions(minDataPoint, maxDataPoint, {}),
815827
})
816828
})
817829

@@ -846,7 +858,13 @@ app.component('MultiLatencyLineChart', {
846858
setup(props) {
847859
const chartElem = ref(null)
848860
onMounted(() => {
861+
// Collect these so we can properly scale our axes as tight as possible to data
862+
// (maybe new versions of chart.js make this less painful)
863+
var minDataPoint = Number.MAX_SAFE_INTEGER
864+
var maxDataPoint = Number.MIN_SAFE_INTEGER
849865
const makeDataset = (benchDataEntry, ix) => {
866+
minDataPoint = Math.min(minDataPoint, benchDataEntry['min'])
867+
maxDataPoint = Math.max(maxDataPoint, benchDataEntry['max'])
850868
const label = benchDataEntry.name
851869
const data = hist_points.map((p) => benchDataEntry[p])
852870
return {
@@ -857,8 +875,10 @@ app.component('MultiLatencyLineChart', {
857875
pointRadius: 0, // disable points, which looks cluttered
858876
// This is a heatmap-style red to blue color scheme which lets us show
859877
// the results "fading back in time":
860-
borderColor: redToBlue(ix, props.benchData.length)
878+
borderColor: redToBlue(ix, props.benchData.length),
861879
// pointBackgroundColor: 'white',
880+
// Smooth lines, but monotone (no misleading up/down "swooping" to fit data points)
881+
cubicInterpolationMode: 'monotone',
862882
}
863883
}
864884
// Options to allow zooming: https://www.chartjs.org/chartjs-plugin-zoom/
@@ -875,16 +895,17 @@ app.component('MultiLatencyLineChart', {
875895
}
876896

877897
const ctx = chartElem.value.getContext('2d')
898+
const datasets = props.benchData.map(makeDataset)
878899
const myChart = new Chart(ctx, {
879900
responsive: true,
880901
maintainAspectRatio: false,
881902
type: 'line',
882903
data: {
883904
labels: hist_labels,
884-
datasets: props.benchData.map(makeDataset),
905+
datasets,
885906
},
886907
// NOTE: this isn't really compatible with crosshair.zoom, so we disable that here:
887-
options: makeLatencyLineChartOptions(zoomOptions, false),
908+
options: makeLatencyLineChartOptions(minDataPoint, maxDataPoint, zoomOptions, false),
888909
// options: makeLatencyLineChartOptions({colorschemes: { scheme: "brewer.RdYlBu11" }}),
889910
})
890911
})

0 commit comments

Comments
 (0)