Skip to content

Commit 4e5adc1

Browse files
committed
#132 node opacity
1 parent 7edc196 commit 4e5adc1

File tree

8 files changed

+342
-146
lines changed

8 files changed

+342
-146
lines changed

src/components/Graph/GraphEditor.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ export default {
319319
},
320320
color: {
321321
type: 'constant',
322-
value: '#1F77B4'
322+
value: '#1F77B4',
323+
opacity: 100
323324
},
324325
label: {
325326
source: null,

src/components/Graph/NodeColorSettings.vue

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,20 @@
5757
</template>
5858
</Field>
5959

60+
<Field label="Opacity" fieldContainerClassName="test_node_opacity">
61+
<NumericInput
62+
:value="modelValue.opacity"
63+
:showSlider="true"
64+
:integerOnly="true"
65+
:max="100"
66+
:min="0"
67+
units="%"
68+
@update="updateSettings('opacity', $event)"
69+
/>
70+
</Field>
71+
6072
<Field
61-
v-if="
62-
modelValue.sourceUsage === 'map_to' || modelValue.type === 'calculated'
63-
"
73+
v-if="modelValue.type === 'map_to' || modelValue.type === 'calculated'"
6474
label="Color as"
6575
fieldContainerClassName="test_node_color_as"
6676
>
@@ -89,6 +99,7 @@
8999
<script>
90100
import { markRaw } from 'vue'
91101
import { applyPureReactInVue } from 'veaury'
102+
import NumericInput from 'react-chart-editor/lib/components/widgets/NumericInput'
92103
import Dropdown from 'react-chart-editor/lib/components/widgets/Dropdown'
93104
import RadioBlocks from 'react-chart-editor/lib/components/widgets/RadioBlocks'
94105
import ColorscalePicker from 'react-chart-editor/lib/components/widgets/ColorscalePicker'
@@ -98,6 +109,7 @@ import 'react-chart-editor/lib/react-chart-editor.css'
98109
99110
export default {
100111
components: {
112+
NumericInput: applyPureReactInVue(NumericInput),
101113
Dropdown: applyPureReactInVue(Dropdown),
102114
RadioBlocks: applyPureReactInVue(RadioBlocks),
103115
Field: applyPureReactInVue(Field),
@@ -134,19 +146,21 @@ export default {
134146
{ label: 'Map to', value: 'map_to' }
135147
]),
136148
defaultColorSettings: {
137-
constant: { value: '#1F77B4' },
149+
constant: { value: '#1F77B4', opacity: 100 },
138150
variable: {
139151
source: null,
140152
sourceUsage: 'map_to',
141153
colorscale: null,
142154
mode: 'categorical',
143-
colorscaleDirection: 'normal'
155+
colorscaleDirection: 'normal',
156+
opacity: 100
144157
},
145158
calculated: {
146159
method: 'degree',
147160
colorscale: null,
148161
mode: 'continious',
149-
colorscaleDirection: 'normal'
162+
colorscaleDirection: 'normal',
163+
opacity: 100
150164
}
151165
}
152166
}

src/lib/graphHelper.js

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,14 @@ function getUpdateSizeMethod(graph, sizeSettings) {
161161
}
162162
}
163163

164-
function getDirectVariableColorUpdateMethod(source) {
165-
return attributes =>
166-
(attributes.color = tinycolor(attributes.data[source]).toHexString())
164+
function getDirectVariableColorUpdateMethod(source, opacity = 100) {
165+
return attributes => {
166+
const color = tinycolor(attributes.data[source])
167+
const colorOpacity = color.getAlpha()
168+
attributes.color = color
169+
.setAlpha((opacity / 100) * colorOpacity)
170+
.toHex8String()
171+
}
167172
}
168173

169174
function getUpdateNodeColorMethod(graph, colorSettings) {
@@ -175,10 +180,16 @@ function getUpdateNodeColorMethod(graph, colorSettings) {
175180
colorscale,
176181
colorscaleDirection,
177182
mode,
178-
method
183+
method,
184+
opacity
179185
} = colorSettings
180186
if (type === 'constant') {
181-
return attributes => (attributes.color = value)
187+
const color = tinycolor(value)
188+
const colorOpacity = color.getAlpha()
189+
return attributes =>
190+
(attributes.color = color
191+
.setAlpha((opacity / 100) * colorOpacity)
192+
.toHex8String())
182193
} else if (type === 'variable') {
183194
return sourceUsage === 'map_to'
184195
? getColorMethod(
@@ -187,17 +198,19 @@ function getUpdateNodeColorMethod(graph, colorSettings) {
187198
(nodeId, attributes) => attributes.data[source],
188199
colorscale,
189200
colorscaleDirection,
190-
getNodeValueScale
201+
getNodeValueScale,
202+
opacity
191203
)
192-
: getDirectVariableColorUpdateMethod(source)
204+
: getDirectVariableColorUpdateMethod(source, opacity)
193205
} else {
194206
return getColorMethod(
195207
graph,
196208
mode,
197209
nodeId => graph[method](nodeId),
198210
colorscale,
199211
colorscaleDirection,
200-
getNodeValueScale
212+
getNodeValueScale,
213+
opacity
201214
)
202215
}
203216
}
@@ -244,8 +257,10 @@ function getColorMethod(
244257
sourceGetter,
245258
selectedColorscale,
246259
colorscaleDirection,
247-
valueScaleGetter
260+
valueScaleGetter,
261+
opacity = 100
248262
) {
263+
const opacityFactor = opacity / 100
249264
const valueScale = valueScaleGetter(graph, sourceGetter)
250265
let colorscale = selectedColorscale || DEFAULT_SCALE
251266
if (colorscaleDirection === 'reversed') {
@@ -261,7 +276,9 @@ function getColorMethod(
261276
)
262277
return (attributes, nodeId) => {
263278
const category = sourceGetter(nodeId, attributes)
264-
attributes.color = colorMap[category]
279+
attributes.color = tinycolor(colorMap[category])
280+
.setAlpha(opacityFactor)
281+
.toHex8String()
265282
}
266283
} else {
267284
const min = valueScale[0]
@@ -274,14 +291,18 @@ function getColorMethod(
274291
const value = sourceGetter(nodeId, attributes)
275292
const normalizedValue = (value - min) / (max - min)
276293
if (isNaN(normalizedValue)) {
277-
attributes.color = '#000000'
294+
attributes.color = tinycolor('#000000')
295+
.setAlpha(opacityFactor)
296+
.toHex8String()
278297
return
279298
}
280299
const exactMatch = normalizedColorscale.find(
281300
([value]) => value === normalizedValue
282301
)
283302
if (exactMatch) {
284-
attributes.color = tinycolor(exactMatch[1]).toHexString()
303+
attributes.color = tinycolor(exactMatch[1])
304+
.setAlpha(opacityFactor)
305+
.toHex8String()
285306
return
286307
}
287308

@@ -305,7 +326,9 @@ function getColorMethod(
305326
r: r0 + interpolationFactor * (r1 - r0),
306327
g: g0 + interpolationFactor * (g1 - g0),
307328
b: b0 + interpolationFactor * (b1 - b0)
308-
}).toHexString()
329+
})
330+
.setAlpha(opacityFactor)
331+
.toHex8String()
309332
}
310333
}
311334
}
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
export default {
22
_migrate(installedVersion, inquiries) {
3-
if (installedVersion === 1) {
4-
inquiries.forEach(inquire => {
5-
inquire.viewType = 'chart'
6-
inquire.viewOptions = inquire.chart
7-
delete inquire.chart
3+
if (installedVersion < 2) {
4+
inquiries.forEach(inquiry => {
5+
inquiry.viewType = 'chart'
6+
inquiry.viewOptions = inquiry.chart
7+
delete inquiry.chart
88
})
9-
return inquiries
109
}
10+
11+
if (installedVersion < 3) {
12+
inquiries.forEach(inquiry => {
13+
if (inquiry.viewType === 'graph') {
14+
inquiry.viewOptions.style.nodes.color.opacity = 100
15+
}
16+
})
17+
}
18+
19+
return inquiries
1120
}
1221
}

src/lib/storedInquiries/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const migrate = migration._migrate
77
const myInquiriesKey = 'myInquiries'
88

99
export default {
10-
version: 2,
10+
version: 3,
1111
myInquiriesKey,
1212
getStoredInquiries() {
1313
let myInquiries = JSON.parse(localStorage.getItem(myInquiriesKey))
@@ -21,7 +21,13 @@ export default {
2121
return []
2222
}
2323

24-
return (myInquiries && myInquiries.inquiries) || []
24+
if (myInquiries.version === 2) {
25+
myInquiries = migrate(2, myInquiries.inquiries)
26+
this.updateStorage(myInquiries)
27+
return myInquiries
28+
}
29+
30+
return myInquiries.inquiries || []
2531
},
2632

2733
duplicateInquiry(baseInquiry) {
@@ -82,11 +88,11 @@ export default {
8288

8389
importInquiries() {
8490
return fu.importFile().then(str => {
85-
const inquires = this.deserialiseInquiries(str)
91+
const inquiries = this.deserialiseInquiries(str)
8692

87-
events.send('inquiry.import', inquires.length)
93+
events.send('inquiry.import', inquiries.length)
8894

89-
return inquires
95+
return inquiries
9096
})
9197
},
9298
export(inquiryList, fileName) {

0 commit comments

Comments
 (0)