-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7911 from hashicorp/f-ui/csi-availability-gauge
UI: CSI Availability Gauges
- Loading branch information
Showing
14 changed files
with
471 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import Component from '@ember/component'; | ||
import { computed } from '@ember/object'; | ||
import { assert } from '@ember/debug'; | ||
import { guidFor } from '@ember/object/internals'; | ||
import { run } from '@ember/runloop'; | ||
import d3Shape from 'd3-shape'; | ||
import WindowResizable from 'nomad-ui/mixins/window-resizable'; | ||
|
||
export default Component.extend(WindowResizable, { | ||
classNames: ['chart', 'gauge-chart'], | ||
|
||
value: null, | ||
complement: null, | ||
total: null, | ||
chartClass: 'is-info', | ||
|
||
width: 0, | ||
height: 0, | ||
|
||
percent: computed('value', 'complement', 'total', function() { | ||
assert( | ||
'Provide complement OR total to GaugeChart, not both.', | ||
this.complement != null || this.total != null | ||
); | ||
|
||
if (this.complement != null) { | ||
return this.value / (this.value + this.complement); | ||
} | ||
|
||
return this.value / this.total; | ||
}), | ||
|
||
fillId: computed(function() { | ||
return `gauge-chart-fill-${guidFor(this)}`; | ||
}), | ||
|
||
maskId: computed(function() { | ||
return `gauge-chart-mask-${guidFor(this)}`; | ||
}), | ||
|
||
radius: computed('width', function() { | ||
return this.width / 2; | ||
}), | ||
|
||
weight: 4, | ||
|
||
backgroundArc: computed('radius', 'weight', function() { | ||
const { radius, weight } = this; | ||
const arc = d3Shape | ||
.arc() | ||
.outerRadius(radius) | ||
.innerRadius(radius - weight) | ||
.cornerRadius(weight) | ||
.startAngle(-Math.PI / 2) | ||
.endAngle(Math.PI / 2); | ||
return arc(); | ||
}), | ||
|
||
valueArc: computed('radius', 'weight', 'percent', function() { | ||
const { radius, weight, percent } = this; | ||
|
||
const arc = d3Shape | ||
.arc() | ||
.outerRadius(radius) | ||
.innerRadius(radius - weight) | ||
.cornerRadius(weight) | ||
.startAngle(-Math.PI / 2) | ||
.endAngle(-Math.PI / 2 + Math.PI * percent); | ||
return arc(); | ||
}), | ||
|
||
didInsertElement() { | ||
this.updateDimensions(); | ||
}, | ||
|
||
updateDimensions() { | ||
const $svg = this.$('svg'); | ||
const width = $svg.width(); | ||
|
||
this.setProperties({ width, height: width / 2 }); | ||
}, | ||
|
||
windowResizeHandler() { | ||
run.once(this, this.updateDimensions); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
.gauge-chart { | ||
position: relative; | ||
display: block; | ||
width: auto; | ||
|
||
svg { | ||
display: block; | ||
margin: auto; | ||
width: 100%; | ||
max-width: 200px; | ||
height: 100%; | ||
} | ||
|
||
.background, | ||
.fill { | ||
transform: translate(50%, 100%); | ||
} | ||
|
||
.background { | ||
fill: $ui-gray-100; | ||
} | ||
|
||
@each $name, $pair in $colors { | ||
$color: nth($pair, 1); | ||
|
||
.canvas.is-#{$name} { | ||
.line { | ||
stroke: $color; | ||
} | ||
} | ||
|
||
linearGradient { | ||
&.is-#{$name} { | ||
> .start { | ||
stop-color: $color; | ||
stop-opacity: 0.2; | ||
} | ||
|
||
> .end { | ||
stop-color: $color; | ||
stop-opacity: 1; | ||
} | ||
} | ||
} | ||
} | ||
|
||
.metric { | ||
position: absolute; | ||
bottom: 0; | ||
width: 100%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,8 @@ | |
flex-grow: 0; | ||
} | ||
} | ||
|
||
&.is-bottom-aligned { | ||
align-items: flex-end; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
$ui-gray-100: #ebeef2; | ||
$ui-gray-200: #dce0e6; | ||
$ui-gray-300: #bac1cc; | ||
$ui-gray-400: #8e96a3; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<svg data-test-gauge-svg role="img" height={{height}}> | ||
<defs> | ||
<linearGradient x1="0" x2="1" y1="0" y2="0" class="{{chartClass}}" id="{{fillId}}"> | ||
<stop class="start" offset="0%" /> | ||
<stop class="end" offset="100%" /> | ||
</linearGradient> | ||
<clipPath id="{{maskId}}"> | ||
<path class="fill" d="{{valueArc}}" /> | ||
</clipPath> | ||
</defs> | ||
<g class="canvas {{chartClass}}"> | ||
<path class="background" d="{{backgroundArc}}" /> | ||
<rect class="area" x="0" y="0" width="100%" height="100%" fill="url(#{{fillId}})" clip-path="url(#{{maskId}})" /> | ||
</g> | ||
</svg> | ||
<div class="metric"> | ||
<h3 data-test-label class="label">{{label}}</h3> | ||
<p data-test-percentage class="value">{{format-percentage value total=total complement=complement}}</p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.