Skip to content

Commit cbbe4c1

Browse files
Factor out reusable flame graph component (#3676)
The flame graph component used to display build instrumentation data can be reused to display a flame graph of tests using the test start time added in #3450. This PR factors our a common component which can be shared between these two use cases. In addition, I organized all of the shared chart components into a common directory in anticipation of further improvements.
1 parent 1c40c46 commit cbbe4c1

5 files changed

Lines changed: 233 additions & 195 deletions

File tree

resources/js/vue/components/BuildInstrumentationPage.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/>
1717

1818
<loading-indicator :is-loading="!allCommands">
19-
<CommandGanttChart :commands="formattedChartCommands" />
19+
<CommandFlameChart :commands="formattedChartCommands" />
2020
</loading-indicator>
2121
</div>
2222

@@ -46,14 +46,14 @@ import LoadingIndicator from './shared/LoadingIndicator.vue';
4646
import BuildSidebar from './shared/BuildSidebar.vue';
4747
import gql from 'graphql-tag';
4848
import FilterBuilder from './shared/FilterBuilder.vue';
49-
import CommandGanttChart from './shared/CommandGanttChart.vue';
49+
import CommandFlameChart from './shared/CommandFlameChart.vue';
5050
import { DateTime, Duration } from 'luxon';
51-
import LineChart from './shared/LineChart.vue';
51+
import LineChart from './shared/Charts/LineChart.vue';
5252
5353
export default {
5454
components: {
5555
LineChart,
56-
CommandGanttChart,
56+
CommandFlameChart,
5757
FilterBuilder,
5858
LoadingIndicator,
5959
BuildSummaryCard,

resources/js/vue/components/BuildTargetsPage.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<loading-indicator :is-loading="!build || !targets">
1818
<div class="tw-w-full tw-bg-base-100 tw-flex tw-flex-col tw-rounded-lg tw-border tw-border-gray-200 tw-p-4">
19-
<CommandGanttChart :commands="formattedCommands" />
19+
<CommandFlameChart :commands="formattedCommands" />
2020
</div>
2121
</loading-indicator>
2222

@@ -61,13 +61,13 @@ import LoadingIndicator from './shared/LoadingIndicator.vue';
6161
import BuildSidebar from './shared/BuildSidebar.vue';
6262
import gql from 'graphql-tag';
6363
import FilterBuilder from './shared/FilterBuilder.vue';
64-
import CommandGanttChart from './shared/CommandGanttChart.vue';
64+
import CommandFlameChart from './shared/CommandFlameChart.vue';
6565
import { DateTime, Duration } from 'luxon';
6666
import Utils from './shared/Utils';
6767
6868
export default {
6969
components: {
70-
CommandGanttChart,
70+
CommandFlameChart,
7171
FilterBuilder,
7272
LoadingIndicator,
7373
DataTable,
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<template>
2+
<v-chart
3+
class="tw-w-full"
4+
:option="chartOptions"
5+
:style="{ height: height + 'px' }"
6+
autoresize
7+
@click="$emit('click', $event)"
8+
/>
9+
</template>
10+
11+
<script>
12+
import { use } from 'echarts/core';
13+
import { CanvasRenderer } from 'echarts/renderers';
14+
import { CustomChart } from 'echarts/charts';
15+
import {
16+
GridComponent,
17+
TooltipComponent,
18+
DataZoomComponent,
19+
} from 'echarts/components';
20+
import VChart from 'vue-echarts';
21+
import Utils from '../Utils';
22+
23+
use([
24+
CanvasRenderer,
25+
CustomChart,
26+
GridComponent,
27+
TooltipComponent,
28+
DataZoomComponent,
29+
]);
30+
31+
export default {
32+
name: 'FlameChart',
33+
components: {
34+
VChart,
35+
},
36+
props: {
37+
data: {
38+
type: Array,
39+
required: true,
40+
},
41+
tracks: {
42+
type: Array,
43+
required: true,
44+
},
45+
overallStartTime: {
46+
type: Number,
47+
required: true,
48+
},
49+
overallEndTime: {
50+
type: Number,
51+
required: true,
52+
},
53+
height: {
54+
type: Number,
55+
required: true,
56+
},
57+
tooltipFormatter: {
58+
type: Function,
59+
required: true,
60+
},
61+
renderItem: {
62+
type: Function,
63+
required: true,
64+
},
65+
},
66+
emits: ['click'],
67+
computed: {
68+
chartOptions() {
69+
return {
70+
tooltip: {
71+
confine: true,
72+
trigger: 'item',
73+
extraCssText: 'max-width: 500px; white-space: normal;',
74+
formatter: this.tooltipFormatter,
75+
},
76+
grid: {
77+
top: '0px',
78+
left: '10px',
79+
right: '10px',
80+
bottom: '50px',
81+
},
82+
xAxis: {
83+
max: this.overallEndTime,
84+
type: 'time',
85+
axisLabel: {
86+
formatter: val => {
87+
const relativeTime = val - this.overallStartTime;
88+
return Utils.formatDuration(relativeTime);
89+
},
90+
},
91+
},
92+
yAxis: {
93+
show: false,
94+
type: 'category',
95+
data: this.tracks,
96+
inverse: true,
97+
},
98+
dataZoom: [
99+
{
100+
type: 'slider',
101+
filterMode: 'weakFilter',
102+
showDataShadow: false,
103+
bottom: 5,
104+
height: 15,
105+
},
106+
{
107+
type: 'inside',
108+
filterMode: 'weakFilter',
109+
},
110+
],
111+
series: [{
112+
type: 'custom',
113+
coordinateSystem: 'cartesian2d',
114+
data: this.data,
115+
large: true,
116+
progressive: 400,
117+
renderItem: this.renderItem,
118+
encode: {
119+
x: [1, 2],
120+
y: 0,
121+
},
122+
}],
123+
};
124+
},
125+
},
126+
};
127+
</script>

resources/js/vue/components/shared/LineChart.vue renamed to resources/js/vue/components/shared/Charts/LineChart.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,24 @@
77
</template>
88

99
<script>
10+
import { use } from 'echarts/core';
11+
import { CanvasRenderer } from 'echarts/renderers';
12+
import { LineChart } from 'echarts/charts';
13+
import {
14+
GridComponent,
15+
TooltipComponent,
16+
DataZoomComponent,
17+
} from 'echarts/components';
1018
import VChart from 'vue-echarts';
11-
import Utils from './Utils';
19+
import Utils from '../Utils';
20+
21+
use([
22+
CanvasRenderer,
23+
LineChart,
24+
GridComponent,
25+
TooltipComponent,
26+
DataZoomComponent,
27+
]);
1228
1329
export default {
1430
name: 'LineChart',

0 commit comments

Comments
 (0)