@@ -359,16 +359,31 @@ drawing.gradient = function(sel, gd, gradientID, type, colorscale, prop) {
359
359
*
360
360
* @param {object } sel: d3 selection to apply this pattern to
361
361
* You can use `selection.call(Drawing.pattern, ...)`
362
+ * @param {string } calledBy: option to know the caller component
362
363
* @param {DOM element } gd: the graph div `sel` is part of
363
364
* @param {string } patternID: a unique (within this plot) identifier
364
365
* for this pattern, so that we don't create unnecessary definitions
365
- * @param {string } bgcolor: background color for this pattern
366
- * @param {string } fgcolor: foreground color for this pattern
367
366
* @param {number } size: size of unit squares for repetition of this pattern
368
367
* @param {number } solidity: how solid lines of this pattern are
369
- * @param {string } prop: the property to apply to, 'fill' or 'stroke'
368
+ * @param {string } mcc: color when painted with colorscale
369
+ * @param {string } fillmode: fillmode for this pattern
370
+ * @param {string } bgcolor: background color for this pattern
371
+ * @param {string } fgcolor: foreground color for this pattern
372
+ * @param {number } fgopacity: foreground opacity for this pattern
370
373
*/
371
- drawing . pattern = function ( sel , gd , patternID , shape , bgcolor , fgcolor , size , solidity , prop ) {
374
+ drawing . pattern = function ( sel , calledBy , gd , patternID , shape , size , solidity , mcc , fillmode , bgcolor , fgcolor , fgopacity ) {
375
+ var isLegend = calledBy === 'legend' ;
376
+
377
+ if ( mcc ) {
378
+ if ( fillmode === 'overlay' ) {
379
+ bgcolor = mcc ;
380
+ fgcolor = Color . contrast ( bgcolor ) ;
381
+ } else {
382
+ bgcolor = undefined ;
383
+ fgcolor = mcc ;
384
+ }
385
+ }
386
+
372
387
var fullLayout = gd . _fullLayout ;
373
388
var fullID = 'p' + fullLayout . _uid + '-' + patternID ;
374
389
var width , height ;
@@ -392,6 +407,7 @@ drawing.pattern = function(sel, gd, patternID, shape, bgcolor, fgcolor, size, so
392
407
patternTag = 'path' ;
393
408
patternAttrs = {
394
409
'd' : path ,
410
+ 'opacity' : fgopacity ,
395
411
'stroke' : fgcolor ,
396
412
'stroke-width' : linewidth + 'px'
397
413
} ;
@@ -406,6 +422,7 @@ drawing.pattern = function(sel, gd, patternID, shape, bgcolor, fgcolor, size, so
406
422
patternTag = 'path' ;
407
423
patternAttrs = {
408
424
'd' : path ,
425
+ 'opacity' : fgopacity ,
409
426
'stroke' : fgcolor ,
410
427
'stroke-width' : linewidth + 'px'
411
428
} ;
@@ -423,6 +440,7 @@ drawing.pattern = function(sel, gd, patternID, shape, bgcolor, fgcolor, size, so
423
440
patternTag = 'path' ;
424
441
patternAttrs = {
425
442
'd' : path ,
443
+ 'opacity' : fgopacity ,
426
444
'stroke' : fgcolor ,
427
445
'stroke-width' : linewidth + 'px'
428
446
} ;
@@ -436,6 +454,7 @@ drawing.pattern = function(sel, gd, patternID, shape, bgcolor, fgcolor, size, so
436
454
patternTag = 'path' ;
437
455
patternAttrs = {
438
456
'd' : path ,
457
+ 'opacity' : fgopacity ,
439
458
'stroke' : fgcolor ,
440
459
'stroke-width' : linewidth + 'px'
441
460
} ;
@@ -449,6 +468,7 @@ drawing.pattern = function(sel, gd, patternID, shape, bgcolor, fgcolor, size, so
449
468
patternTag = 'path' ;
450
469
patternAttrs = {
451
470
'd' : path ,
471
+ 'opacity' : fgopacity ,
452
472
'stroke' : fgcolor ,
453
473
'stroke-width' : linewidth + 'px'
454
474
} ;
@@ -463,6 +483,7 @@ drawing.pattern = function(sel, gd, patternID, shape, bgcolor, fgcolor, size, so
463
483
patternTag = 'path' ;
464
484
patternAttrs = {
465
485
'd' : path ,
486
+ 'opacity' : fgopacity ,
466
487
'stroke' : fgcolor ,
467
488
'stroke-width' : linewidth + 'px'
468
489
} ;
@@ -480,14 +501,23 @@ drawing.pattern = function(sel, gd, patternID, shape, bgcolor, fgcolor, size, so
480
501
'cx' : width / 2 ,
481
502
'cy' : height / 2 ,
482
503
'r' : radius ,
504
+ 'opacity' : fgopacity ,
483
505
'fill' : fgcolor
484
506
} ;
485
507
break ;
486
508
}
487
509
510
+ var str = [
511
+ shape || 'noSh' ,
512
+ bgcolor || 'noBg' ,
513
+ fgcolor || 'noFg' ,
514
+ size ,
515
+ solidity
516
+ ] . join ( ';' ) ;
517
+
488
518
var pattern = fullLayout . _defs . select ( '.patterns' )
489
519
. selectAll ( '#' + fullID )
490
- . data ( [ shape + ';' + bgcolor + ';' + fgcolor + ';' + size + ';' + solidity ] , Lib . identity ) ;
520
+ . data ( [ str ] , Lib . identity ) ;
491
521
492
522
pattern . exit ( ) . remove ( ) ;
493
523
@@ -500,7 +530,9 @@ drawing.pattern = function(sel, gd, patternID, shape, bgcolor, fgcolor, size, so
500
530
'id' : fullID ,
501
531
'width' : width + 'px' ,
502
532
'height' : height + 'px' ,
503
- '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)' : ''
504
536
} ) ;
505
537
506
538
if ( bgcolor ) {
@@ -522,8 +554,8 @@ drawing.pattern = function(sel, gd, patternID, shape, bgcolor, fgcolor, size, so
522
554
. attr ( patternAttrs ) ;
523
555
} ) ;
524
556
525
- sel . style ( prop , getFullUrl ( fullID , gd ) )
526
- . style ( prop + ' -opacity', null ) ;
557
+ sel . style ( 'fill' , getFullUrl ( fullID , gd ) )
558
+ . style ( 'fill -opacity', null ) ;
527
559
528
560
sel . classed ( 'pattern_filled' , true ) ;
529
561
var className2query = function ( s ) {
@@ -693,18 +725,25 @@ drawing.singlePointStyle = function(d, sel, trace, fns, gd) {
693
725
[ [ 0 , gradientColor ] , [ 1 , fillColor ] ] , 'fill' ) ;
694
726
} else if ( patternShape ) {
695
727
var patternBGColor = drawing . getPatternAttr ( markerPattern . bgcolor , d . i , null ) ;
728
+ var patternFGColor = drawing . getPatternAttr ( markerPattern . fgcolor , d . i , null ) ;
729
+ var patternFGOpacity = markerPattern . fgopacity ;
696
730
var patternSize = drawing . getPatternAttr ( markerPattern . size , d . i , 8 ) ;
697
731
var patternSolidity = drawing . getPatternAttr ( markerPattern . solidity , d . i , 0.3 ) ;
698
- var perPointPattern = Lib . isArrayOrTypedArray ( markerPattern . shape ) ||
699
- Lib . isArrayOrTypedArray ( markerPattern . bgcolor ) ||
700
- Lib . isArrayOrTypedArray ( markerPattern . size ) ||
701
- Lib . isArrayOrTypedArray ( markerPattern . solidity ) ;
732
+ var perPointPattern = d . mcc ||
733
+ Lib . isArrayOrTypedArray ( markerPattern . shape ) ||
734
+ Lib . isArrayOrTypedArray ( markerPattern . bgcolor ) ||
735
+ Lib . isArrayOrTypedArray ( markerPattern . size ) ||
736
+ Lib . isArrayOrTypedArray ( markerPattern . solidity ) ;
702
737
703
738
var patternID = trace . uid ;
704
739
if ( perPointPattern ) patternID += '-' + d . i ;
705
740
706
- drawing . pattern ( sel , gd , patternID , patternShape , patternBGColor , fillColor ,
707
- patternSize , patternSolidity , 'fill' ) ;
741
+ drawing . pattern (
742
+ sel , 'point' , gd , patternID ,
743
+ patternShape , patternSize , patternSolidity ,
744
+ d . mcc , markerPattern . fillmode ,
745
+ patternBGColor , patternFGColor , patternFGOpacity
746
+ ) ;
708
747
} else {
709
748
Color . fill ( sel , fillColor ) ;
710
749
}
0 commit comments