From d9cac96e5acdfa0fba6bb2bbf177c2300a0c0d7d Mon Sep 17 00:00:00 2001
From: Michael Lange
Date: Fri, 30 Oct 2020 14:22:32 -0700
Subject: [PATCH 1/4] Add new is-static chart tooltip variant and decouple from
charts
---
ui/app/styles/charts/tooltip.scss | 195 ++++++++++++++++--------------
1 file changed, 101 insertions(+), 94 deletions(-)
diff --git a/ui/app/styles/charts/tooltip.scss b/ui/app/styles/charts/tooltip.scss
index 2b5fd6419..82f74958b 100644
--- a/ui/app/styles/charts/tooltip.scss
+++ b/ui/app/styles/charts/tooltip.scss
@@ -1,109 +1,116 @@
.chart {
position: relative;
+}
- .chart-tooltip {
- position: absolute;
- top: 0;
- display: none;
- background: $white;
- color: rgba($black, 0.6);
- border: 1px solid $grey;
- min-width: 150px;
- margin-top: -10px;
- transform: translate(-50%, -100%);
- transition: 0.2s top ease-out, 0.2s left ease-out;
+.chart-tooltip {
+ position: absolute;
+ top: 0;
+ display: none;
+ background: $white;
+ color: rgba($black, 0.6);
+ border: 1px solid $grey;
+ min-width: 150px;
+ margin-top: -10px;
+ transform: translate(-50%, -100%);
+ transition: 0.2s top ease-out, 0.2s left ease-out;
+ pointer-events: none;
+ z-index: $z-tooltip;
+
+ &.is-snappy {
+ transition: 0.2s top ease-out, 0.05s left ease-out;
+ }
+
+ &::before {
pointer-events: none;
+ display: inline-block;
+ content: '';
+ width: 0;
+ height: 0;
+ border-top: 7px solid $grey;
+ border-right: 7px solid transparent;
+ border-left: 7px solid transparent;
+ position: absolute;
+ transform: translateX(-7px);
+ left: 50%;
+ bottom: -8px;
z-index: $z-tooltip;
+ }
- &.is-snappy {
- transition: 0.2s top ease-out, 0.05s left ease-out;
- }
+ &::after {
+ pointer-events: none;
+ display: inline-block;
+ content: '';
+ width: 0;
+ height: 0;
+ border-top: 6px solid $white;
+ border-right: 6px solid transparent;
+ border-left: 6px solid transparent;
+ position: absolute;
+ transform: translateX(-6px);
+ left: 50%;
+ bottom: -6px;
+ z-index: $z-tooltip;
+ }
- &::before {
- pointer-events: none;
- display: inline-block;
- content: '';
- width: 0;
- height: 0;
- border-top: 7px solid $grey;
- border-right: 7px solid transparent;
- border-left: 7px solid transparent;
- position: absolute;
- transform: translateX(-7px);
- left: 50%;
- bottom: -8px;
- z-index: $z-tooltip;
- }
+ &.active {
+ display: block;
+ }
- &::after {
- pointer-events: none;
- display: inline-block;
- content: '';
- width: 0;
- height: 0;
- border-top: 6px solid $white;
- border-right: 6px solid transparent;
- border-left: 6px solid transparent;
- position: absolute;
- transform: translateX(-6px);
- left: 50%;
- bottom: -6px;
- z-index: $z-tooltip;
- }
-
- &.active {
- display: block;
- }
-
- ol {
- list-style: none;
- }
-
- ol > li,
- p {
- display: flex;
- flex-flow: row;
- flex-wrap: nowrap;
- justify-content: space-between;
- padding: 0.25rem 0.5rem;
-
- span {
- display: inline-block;
- }
+ ol {
+ list-style: none;
+ &.is-static {
.label {
- white-space: nowrap;
- font-weight: $weight-bold;
color: $black;
- margin: 0;
-
- &.is-empty {
- color: rgba($grey, 0.6);
- }
- }
-
- .value {
- padding-left: 1em;
- }
- }
-
- ol > li {
- .label {
- color: rgba($black, 0.6);
- }
-
- &.active {
- color: $black;
- background: $white-ter;
-
- .label {
- color: $black;
- }
- }
-
- + li {
- border-top: 1px solid $grey-light;
+ background: $white;
}
}
}
+
+ ol > li,
+ p {
+ display: flex;
+ flex-flow: row;
+ flex-wrap: nowrap;
+ justify-content: space-between;
+ padding: 0.25rem 0.5rem;
+
+ span {
+ display: inline-block;
+ }
+
+ .label {
+ white-space: nowrap;
+ font-weight: $weight-bold;
+ color: $black;
+ margin: 0;
+
+ &.is-empty {
+ color: rgba($grey, 0.6);
+ }
+ }
+
+ .value {
+ padding-left: 1em;
+ }
+ }
+
+ ol > li {
+ .label {
+ color: rgba($black, 0.6);
+ }
+
+ &.active {
+ color: $black;
+ background: $white-ter;
+
+ .label {
+ color: $black;
+ }
+ }
+
+ + li {
+ border-top: 1px solid $grey-light;
+ }
+ }
}
From 654533229c6c6a42fbf0d29009ffb61e45a85eb3 Mon Sep 17 00:00:00 2001
From: Michael Lange
Date: Fri, 30 Oct 2020 14:22:58 -0700
Subject: [PATCH 2/4] Make the style-string property glimmer safe
---
ui/app/utils/properties/style-string.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ui/app/utils/properties/style-string.js b/ui/app/utils/properties/style-string.js
index 785a6162d..3f3a225f2 100644
--- a/ui/app/utils/properties/style-string.js
+++ b/ui/app/utils/properties/style-string.js
@@ -1,4 +1,4 @@
-import { computed } from '@ember/object';
+import { computed, get } from '@ember/object';
import { htmlSafe } from '@ember/template';
// An Ember.Computed property for transforming an object into an
@@ -8,7 +8,7 @@ import { htmlSafe } from '@ember/template';
// styleStr: styleStringProperty('styleProps') // color:#FF0;border-width:1px
export default function styleStringProperty(prop) {
return computed(prop, function() {
- const styles = this.get(prop);
+ const styles = get(this, prop);
let str = '';
if (styles) {
From b5044250e63d5dd6d17e80dbdc04cfee51359585 Mon Sep 17 00:00:00 2001
From: Michael Lange
Date: Fri, 30 Oct 2020 14:23:59 -0700
Subject: [PATCH 3/4] Add tooltips to the topo viz
---
ui/app/components/topo-viz.js | 22 ++++++
ui/app/components/topo-viz/node.js | 8 ++-
ui/app/templates/components/topo-viz.hbs | 27 +++++++
.../components/topo-viz/datacenter.hbs | 4 +-
ui/app/templates/components/topo-viz/node.hbs | 11 ++-
.../integration/components/topo-viz-test.js | 2 +
.../components/topo-viz/datacenter-test.js | 2 +
.../components/topo-viz/node-test.js | 71 +++++++++++++++++--
ui/tests/pages/components/topo-viz/node.js | 14 +++-
9 files changed, 151 insertions(+), 10 deletions(-)
diff --git a/ui/app/components/topo-viz.js b/ui/app/components/topo-viz.js
index 744b79970..8f51fb730 100644
--- a/ui/app/components/topo-viz.js
+++ b/ui/app/components/topo-viz.js
@@ -1,12 +1,16 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action, set } from '@ember/object';
+import { inject as service } from '@ember/service';
import { run } from '@ember/runloop';
import { scaleLinear } from 'd3-scale';
import { extent, deviation, mean } from 'd3-array';
import { line, curveBasis } from 'd3-shape';
+import styleStringProperty from '../utils/properties/style-string';
export default class TopoViz extends Component {
+ @service system;
+
@tracked element = null;
@tracked topology = { datacenters: [] };
@@ -16,6 +20,11 @@ export default class TopoViz extends Component {
@tracked edgeOffset = { x: 0, y: 0 };
@tracked viewportColumns = 2;
+ @tracked highlightAllocation = null;
+ @tracked tooltipProps = {};
+
+ @styleStringProperty('tooltipProps') tooltipStyle;
+
get isSingleColumn() {
if (this.topology.datacenters.length <= 1 || this.viewportColumns === 1) return true;
@@ -144,6 +153,19 @@ export default class TopoViz extends Component {
if (this.args.onNodeSelect) this.args.onNodeSelect(this.activeNode);
}
+ @action showTooltip(allocation, element) {
+ const bbox = element.getBoundingClientRect();
+ this.highlightAllocation = allocation;
+ this.tooltipProps = {
+ left: window.visualViewport.pageLeft + bbox.left + bbox.width / 2,
+ top: window.visualViewport.pageTop + bbox.top,
+ };
+ }
+
+ @action hideTooltip() {
+ this.highlightAllocation = null;
+ }
+
@action
associateAllocations(allocation) {
if (this.activeAllocation === allocation) {
diff --git a/ui/app/components/topo-viz/node.js b/ui/app/components/topo-viz/node.js
index 3bef48ee0..5b8d98d0d 100644
--- a/ui/app/components/topo-viz/node.js
+++ b/ui/app/components/topo-viz/node.js
@@ -89,8 +89,14 @@ export default class TopoVizNode extends Component {
}
@action
- highlightAllocation(allocation) {
+ highlightAllocation(allocation, { target }) {
this.activeAllocation = allocation;
+ this.args.onAllocationFocus && this.args.onAllocationFocus(allocation, target);
+ }
+
+ @action
+ allocationBlur() {
+ this.args.onAllocationBlur && this.args.onAllocationBlur();
}
@action
diff --git a/ui/app/templates/components/topo-viz.hbs b/ui/app/templates/components/topo-viz.hbs
index 4d78bd044..8953406f3 100644
--- a/ui/app/templates/components/topo-viz.hbs
+++ b/ui/app/templates/components/topo-viz.hbs
@@ -14,9 +14,36 @@
@isDense={{this.isDense}}
@heightScale={{this.topology.heightScale}}
@onAllocationSelect={{this.associateAllocations}}
+ @onAllocationFocus={{this.showTooltip}}
+ @onAllocationBlur={{this.hideTooltip}}
@onNodeSelect={{this.showNodeDetails}} />
+
+
{{#if this.activeAllocation}}
{{/unless}}
-