forked from odpi/happi-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhappi-graph-legend.js
170 lines (142 loc) · 3.74 KB
/
happi-graph-legend.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import {
PolymerElement,
html
} from '@polymer/polymer/polymer-element.js';
import '@polymer/iron-icons/iron-icons.js';
import '@polymer/paper-button/paper-button.js';
import { simpleSquareIcon } from './happi-graph-helpers';
class HappiGraphLegend extends PolymerElement {
static get properties() {
return {
iconsMap: {
type: Object,
value: {}
},
propertiesMap: {
type: Object,
value: {}
},
labels: {
type: Object,
value: []
},
graphNodes: {
type: Object,
value: {},
observer: '_graphNodesUpdate'
},
isMinimized: {
type: Boolean,
value: false
}
};
}
_graphNodesUpdate(newGraphNodes) {
let _nodes = newGraphNodes;
let propertiesMap = {};
if(_nodes.length) {
_nodes.map(n => {
propertiesMap[n.label] = n.icon;
n.properties.map(p => {
propertiesMap[p.groupName] = p.icon;
});
});
this.labels = [...Object.keys(propertiesMap)];
} else {
this.labels = [];
}
}
toggleMinimize() {
this.isMinimized = !this.isMinimized;
}
getIcon(groupName) {
if(this.propertiesMap[groupName] && this.iconsMap[this.propertiesMap[groupName].icon]) {
return this.iconsMap[this.propertiesMap[groupName].icon];
} else {
return simpleSquareIcon;
}
}
static get template() {
return html`
<style>
:host {
display: block;
font-size:12px;
font-family: var(--happi-graph-font-family);
}
img {
height:20px;
vertical-align:middle;
margin-right:5px;
}
.svg-icons {
color: var(--happi-graph-secondary-color);
background: rgb(var(--happi-graph-primary-color-rgb), 0.9);
padding:10px;
max-width:400px;
display: flex;
flex-flow: row wrap;
justify-content: space-around;
}
.svg-icon {
display: flex;
align-items: center;
flex-grow: 4;
margin:5px;
}
.svg-icon span {
margin-top:1px;
width:120px;
}
.dropdown {
display:flex;
justify-content:flex-end;
cursor: pointer;
}
paper-button {
margin: 0;
padding: 0.2em 0.2em 0.4em 0.57em;
font-size:15px;
color: var(--happi-graph-primary-color);
background-color: #f4f5f7;
text-transform: none;
--paper-button: {
@apply(--layout-vertical);
@apply(--layout-center-center);
};
}
paper-button.keyboard-focus {
font-weight: normal;
}
.label {
margin-top:4px;
}
.label iron-icon {
margin-top:-3px;
}
</style>
<paper-button on-click="toggleMinimize" class="dropdown">
<div class="label">
Legend
<template is="dom-if" if="[[ !isMinimized ]]">
<iron-icon icon="icons:expand-more"></iron-icon>
</template>
<template is="dom-if" if="[[ isMinimized ]]">
<iron-icon icon="icons:chevron-right"></iron-icon>
</template>
</div>
</paper-button>
<template is="dom-if" if="[[ isMinimized ]]" restamp="true">
<div class="svg-icons">
<template is="dom-repeat" items="{{ labels }}">
<div class="svg-icon">
<img src="data:image/svg+xml;utf8,[[ getIcon(item) ]]"/>
<span>[[ item ]]</span>
</div>
</template>
</div>
</template>
`;
}
}
window.customElements.define('happi-graph-legend', HappiGraphLegend);