Skip to content

Commit 178e0a6

Browse files
committed
scale down patterns so that default sizes fit in legend icons
1 parent 38bd5ec commit 178e0a6

File tree

6 files changed

+10
-5
lines changed

6 files changed

+10
-5
lines changed

src/components/drawing/index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ drawing.gradient = function(sel, gd, gradientID, type, colorscale, prop) {
359359
*
360360
* @param {object} sel: d3 selection to apply this pattern to
361361
* You can use `selection.call(Drawing.pattern, ...)`
362+
* @param {string} calledBy: option to know the caller component
362363
* @param {DOM element} gd: the graph div `sel` is part of
363364
* @param {string} patternID: a unique (within this plot) identifier
364365
* for this pattern, so that we don't create unnecessary definitions
@@ -370,7 +371,9 @@ drawing.gradient = function(sel, gd, gradientID, type, colorscale, prop) {
370371
* @param {string} fgcolor: foreground color for this pattern
371372
* @param {number} fgopacity: foreground opacity for this pattern
372373
*/
373-
drawing.pattern = function(sel, gd, patternID, shape, size, solidity, mcc, fillmode, bgcolor, fgcolor, fgopacity) {
374+
drawing.pattern = function(sel, calledBy, gd, patternID, shape, size, solidity, mcc, fillmode, bgcolor, fgcolor, fgopacity) {
375+
var isLegend = calledBy === 'legend';
376+
374377
if(mcc) {
375378
if(fillmode === 'overlay') {
376379
bgcolor = mcc;
@@ -527,7 +530,9 @@ drawing.pattern = function(sel, gd, patternID, shape, size, solidity, mcc, fillm
527530
'id': fullID,
528531
'width': width + 'px',
529532
'height': height + 'px',
530-
'patternUnits': 'userSpaceOnUse'
533+
'patternUnits': 'userSpaceOnUse',
534+
// for legends scale down patterns just a bit so that default size (i.e 8) nicely fit in small icons
535+
'patternTransform': isLegend ? 'scale(0.8)' : ''
531536
});
532537

533538
if(bgcolor) {
@@ -734,7 +739,7 @@ drawing.singlePointStyle = function(d, sel, trace, fns, gd) {
734739
if(perPointPattern) patternID += '-' + d.i;
735740

736741
drawing.pattern(
737-
sel, gd, patternID,
742+
sel, 'point', gd, patternID,
738743
patternShape, patternSize, patternSolidity,
739744
d.mcc, markerPattern.fillmode,
740745
patternBGColor, patternFGColor, patternFGOpacity

src/components/legend/style.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ module.exports = function style(s, gd, legend) {
366366
var patternBGColor = Drawing.getPatternAttr(markerPattern.bgcolor, 0, null);
367367
var patternFGColor = Drawing.getPatternAttr(markerPattern.fgcolor, 0, null);
368368
var patternFGOpacity = markerPattern.fgopacity;
369-
var patternSize = dimAttr(markerPattern.size, 6, 8);
369+
var patternSize = dimAttr(markerPattern.size, 8, 10);
370370
var patternSolidity = dimAttr(markerPattern.solidity, 0.5, 1);
371371
var patternID = 'legend-' + trace.uid;
372372
p.call(
373-
Drawing.pattern, gd, patternID,
373+
Drawing.pattern, 'legend', gd, patternID,
374374
patternShape, patternSize, patternSolidity,
375375
mcc, markerPattern.fillmode,
376376
patternBGColor, patternFGColor, patternFGOpacity

test/image/baselines/pattern_bars.png

247 Bytes
Loading
Loading
537 Bytes
Loading
61 Bytes
Loading

0 commit comments

Comments
 (0)