Skip to content

Commit 28ca15f

Browse files
jaydonkroossJaydon Krooss
andauthored
#1250: Add patterns to Resource Access visualizations (#1553)
* Create patterns for accessibility on resource access chart * Drop old commented lines, add pattern description * revert accessed resources to solid color * fix linting, add camelCase to pattern label * rename defs variable * clean up svg defs variable --------- Co-authored-by: Jaydon Krooss <jkrooss@m-dvf4tlw5mw.local>
1 parent 256a284 commit 28ca15f

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

assets/src/components/d3/createResourceAccessChart.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ const toolTip = tip.attr('class', 'd3-tip')
3838
})
3939

4040
function appendLegend (svg) {
41-
const legendBoxLength = 10
42-
const legendBoxTextInterval = 15
41+
const legendBoxLength = 13
42+
const legendBoxTextInterval = 20
4343
const legendInterval = 20
4444
const legendY = -50
4545

4646
const legendLabels = [
47-
['Resources I haven\'t viewed', notAccessedResourceColor],
47+
['Resources I haven\'t viewed', 'url(#notAccessedPattern)'],
4848
['Resources I\'ve viewed', accessedResourceColor]
4949
]
5050

@@ -190,7 +190,7 @@ function createResourceAccessChart ({ data, width, height, domElement }) {
190190
.attr('class', 'bar')
191191
.attr('fill', d => d.self_access_count > 0
192192
? accessedResourceColor
193-
: notAccessedResourceColor
193+
: 'url(#notAccessedPattern)'
194194
)
195195
.on('focus', (e, d) => {
196196
moveBrushOnFocus(e, d.resource_name)
@@ -210,7 +210,7 @@ function createResourceAccessChart ({ data, width, height, domElement }) {
210210
.enter()
211211
.append('text')
212212
.attr('class', 'label')
213-
.attr('x', d => mainXScale(d.total_percent) + 3 + mainMargin.left)
213+
.attr('x', d => mainXScale(d.total_percent) + 40 + mainMargin.left)
214214
.attr('y', d => mainYScale(d.resource_name) + mainYScale.bandwidth() / 2 + mainMargin.top)
215215
.attr('dx', -10)
216216
.attr('dy', '.35em')
@@ -286,7 +286,7 @@ function createResourceAccessChart ({ data, width, height, domElement }) {
286286
d3.select('.miniGroup').selectAll('.bar')
287287
.style('fill', d => d.self_access_count > 0
288288
? accessedResourceColor
289-
: notAccessedResourceColor
289+
: 'url(#notAccessedPattern)'
290290
)
291291
.style('opacity', d => selected.includes(d.resource_name)
292292
? 1
@@ -393,15 +393,35 @@ function createResourceAccessChart ({ data, width, height, domElement }) {
393393
.on('mousedown.brush', brushcenter)
394394
.on('touchstart.brush', brushcenter, { passive: true })
395395

396+
const svgDefinitions = svg.append('defs')
397+
396398
// Clips
397-
svg.append('defs')
399+
svgDefinitions
398400
.append('clipPath')
399401
.attr('id', 'clip')
400402
.append('rect')
401403
.attr('x', -mainMargin.left)
402404
.attr('width', mainWidth + mainMargin.left)
403405
.attr('height', mainHeight)
404406

407+
// Pattern for not accessed: black stripes on gray background
408+
svgDefinitions
409+
.append('pattern')
410+
.attr('id', 'notAccessedPattern')
411+
.attr('width', 10)
412+
.attr('height', 10)
413+
.attr('patternUnits', 'userSpaceOnUse')
414+
.attr('patternTransform', 'rotate(45)')
415+
.append('rect')
416+
.attr('width', 10)
417+
.attr('height', 10)
418+
.attr('fill', notAccessedResourceColor)
419+
svgDefinitions.select('#notAccessedPattern')
420+
.append('rect')
421+
.attr('width', 2)
422+
.attr('height', 10)
423+
.attr('fill', 'black')
424+
405425
// Inject data
406426
// Domain
407427
mainXScale.domain([0, d3.max(resourceData, d => d.total_percent)])
@@ -445,7 +465,7 @@ function createResourceAccessChart ({ data, width, height, domElement }) {
445465
.attr('class', 'bar')
446466
.attr('fill', d => d.self_access_count > 0
447467
? accessedResourceColor
448-
: notAccessedResourceColor
468+
: 'url(#notAccessedPattern)'
449469
)
450470

451471
// Add brush to main chart

0 commit comments

Comments
 (0)