Commit 59616dc7 authored by Phil Hughes's avatar Phil Hughes

Fixed up some code

Improved the design
Pulls the endpoint from the HAML
parent 8c66ced7
import d3 from 'd3'; import d3 from 'd3';
export default class Deployments { export default class Deployments {
constructor(width) { constructor(width, height) {
this.width = width; this.width = width;
this.height = height;
this.timeFormat = d3.time.format('%b %d, %Y, %H:%M%p'); this.timeFormat = d3.time.format('%b %d, %Y, %H:%M%p');
this.endpoint = document.getElementById('js-metrics').dataset.deploymentEndpoint;
} }
init(chartData) { init(chartData) {
...@@ -12,12 +15,14 @@ export default class Deployments { ...@@ -12,12 +15,14 @@ export default class Deployments {
this.x = d3.time.scale().range([0, this.width]); this.x = d3.time.scale().range([0, this.width]);
this.x.domain(d3.extent(this.chartData, d => d.time)); this.x.domain(d3.extent(this.chartData, d => d.time));
this.charts = d3.selectAll('.prometheus-graph .graph-container');
this.getData(); this.getData();
} }
getData() { getData() {
$.ajax({ $.ajax({
url: 'http://192.168.0.2:3000/root/hello-world/environments/21/deployments', url: this.endpoint,
dataType: 'JSON', dataType: 'JSON',
}) })
.done((data) => { .done((data) => {
...@@ -31,6 +36,8 @@ export default class Deployments { ...@@ -31,6 +36,8 @@ export default class Deployments {
id: deployment.id, id: deployment.id,
time: new Date(deployment.created_at), time: new Date(deployment.created_at),
sha: deployment.sha, sha: deployment.sha,
tag: deployment.tag,
ref: deployment.ref.name,
}); });
} }
}); });
...@@ -40,11 +47,8 @@ export default class Deployments { ...@@ -40,11 +47,8 @@ export default class Deployments {
} }
plotData() { plotData() {
const charts = d3.selectAll('.prometheus-graph .graph-container'); this.charts.each((d, i) => {
const chart = d3.select(this.charts[0][i]);
charts
.each((d, i) => {
const chart = d3.select(charts[0][i]);
this.createLine(chart); this.createLine(chart);
this.createDeployInfoBox(chart); this.createDeployInfoBox(chart);
...@@ -59,16 +63,14 @@ export default class Deployments { ...@@ -59,16 +63,14 @@ export default class Deployments {
.enter() .enter()
.append('g') .append('g')
.attr('class', d => `deploy-info-${d.id}`) .attr('class', d => `deploy-info-${d.id}`)
.attr('transform', d => `translate(${Math.floor(this.x(d.time)) + 1}, -1)`) .attr('transform', d => `translate(${Math.floor(this.x(d.time)) + 1}, 0)`)
.append('line') .append('line')
.attr('class', 'deployment-line') .attr('class', 'deployment-line')
.attr('stroke', '#000000')
.attr('stroke-width', '2')
.attr({ .attr({
x1: 0, x1: 0,
x2: 0, x2: 0,
y1: 0, y1: 0,
y2: chart.node().getBoundingClientRect().height - 22, y2: this.height,
}); });
} }
...@@ -76,29 +78,31 @@ export default class Deployments { ...@@ -76,29 +78,31 @@ export default class Deployments {
this.data.forEach((d) => { this.data.forEach((d) => {
const group = chart.select(`.deploy-info-${d.id}`) const group = chart.select(`.deploy-info-${d.id}`)
.append('svg') .append('svg')
.attr('class', 'rect-text-metric deploy-info-rect') .attr('x', 3)
.attr('x', '5')
.attr('y', '0')
.attr('width', 100)
.attr('height', 35);
group.append('rect')
.attr('class', 'rect-metric')
.attr('x', 0)
.attr('y', 0) .attr('y', 0)
.attr('rx', 3) .attr('height', 38);
.attr('width', '100%')
.attr('height', '100%') const rect = group.append('rect')
.attr('class', 'rect-text-metric deploy-info-rect rect-metric')
.attr('x', 1)
.attr('y', 1)
.attr('rx', 2)
.attr('height', 35);
const text = group.append('text') const text = group.append('text')
.attr('x', 5) .attr('x', 5)
.attr('y', '50%') .attr('y', '50%')
.attr('style', 'dominant-baseline: middle;') .attr('style', 'dominant-baseline: middle;')
.text((d) => { .text((d) => {
return `${d.sha.slice(0, 6)} - ${this.timeFormat(d.time)}`; const isTag = d.tag;
const refText = isTag ? d.ref : d.sha.slice(0, 6);
return `${refText} - ${this.timeFormat(d.time)}`;
}); });
group.attr('width', Math.floor(text.node().getBoundingClientRect().width) + 10); group.attr('width', Math.floor(text.node().getBoundingClientRect().width) + 14);
rect.attr('width', Math.floor(text.node().getBoundingClientRect().width) + 10);
}); });
} }
} }
...@@ -26,7 +26,7 @@ class PrometheusGraph { ...@@ -26,7 +26,7 @@ class PrometheusGraph {
this.width = parentContainerWidth - this.margin.left - this.margin.right; this.width = parentContainerWidth - this.margin.left - this.margin.right;
this.height = 400 - this.margin.top - this.margin.bottom; this.height = 400 - this.margin.top - this.margin.bottom;
this.backOffRequestCounter = 0; this.backOffRequestCounter = 0;
this.deployments = new Deployments(this.width); this.deployments = new Deployments(this.width, this.height);
this.configureGraph(); this.configureGraph();
this.init(); this.init();
...@@ -89,6 +89,7 @@ class PrometheusGraph { ...@@ -89,6 +89,7 @@ class PrometheusGraph {
.scale(y) .scale(y)
.ticks(this.commonGraphProperties.axis_no_ticks) .ticks(this.commonGraphProperties.axis_no_ticks)
.tickSize(-this.width) .tickSize(-this.width)
.outerTickSize(0)
.orient('left'); .orient('left');
this.createAxisLabelContainers(axisLabelContainer, key); this.createAxisLabelContainers(axisLabelContainer, key);
...@@ -237,7 +238,7 @@ class PrometheusGraph { ...@@ -237,7 +238,7 @@ class PrometheusGraph {
const rectTextMetric = chart.append('svg') const rectTextMetric = chart.append('svg')
.attr('class', 'rect-text-metric') .attr('class', 'rect-text-metric')
.attr('x', currentTimeCoordinate) .attr('x', currentTimeCoordinate)
.attr('y', -1); .attr('y', 0);
rectTextMetric.append('rect') rectTextMetric.append('rect')
.attr('class', 'rect-metric') .attr('class', 'rect-metric')
......
...@@ -213,6 +213,11 @@ ...@@ -213,6 +213,11 @@
} }
.selected-metric-line { .selected-metric-line {
stroke: $black; stroke: #8c8c8c;
stroke-width: 1; stroke-width: 1;
} }
.deployment-line {
stroke: #000;
stroke-width: 2;
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
= page_specific_javascript_bundle_tag('monitoring') = page_specific_javascript_bundle_tag('monitoring')
= render "projects/pipelines/head" = render "projects/pipelines/head"
%div{ class: container_class } #js-metrics{ class: container_class, data: { deployment_endpoint: namespace_project_environment_deployments_path(@project.namespace, @project, @environment, format: :json) } }
.top-area .top-area
.row .row
.col-sm-6 .col-sm-6
......
%div %div
%svg.graph-line-shadow
.top-area .top-area
.row .row
.col-sm-6 .col-sm-6
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment