code: function(selector, attr, gradient) {
  
          var $selected = this.findBySelector(selector);
  
          // Generate a hash code from the stringified filter definition. This gives us
          // a unique filter ID for different definitions.
          var gradientId = gradient.type + this.paper.svg.id + joint.util.hashCode(JSON.stringify(gradient));
  
          // If the gradient already exists in the document,
          // we're done and we can just use it (reference it using `url()`).
          // If not, create one.
          if (!this.paper.svg.getElementById(gradientId)) {
  
              var gradientSVGString = [
                  '<' + gradient.type + '>',
                  _.map(gradient.stops, function(stop) {
                      return '<stop offset="' + stop.offset + '" stop-color="' + stop.color + '" stop-opacity="' + (_.isFinite(stop.opacity) ? stop.opacity : 1) + '" />'
                  }).join(''),
                  '</' + gradient.type + '>'
              ].join('');
              
              var gradientElement = V(gradientSVGString);
              if (gradient.attrs) { gradientElement.attr(gradient.attrs); }
              gradientElement.node.id = gradientId;
              V(this.paper.svg).defs().append(gradientElement);
          }
  
          $selected.each(function() {
              
              V(this).attr(attr, 'url(#' + gradientId + ')');
          });
      }
docs: `selector` is a CSS selector or `'.'`. `attr` is either a `'fill'` or `'stroke'`. `gradient` must be in the special JointJS gradient format: `{ type: <linearGradient|radialGradient>, stops: [ { offset: <offset>, color: <color> }, ... ]`. An example is: `{ fill: { type: 'linearGradient', stops: [ { offset: '10%', color: 'green' }, { offset: '50%', color: 'blue' } ] } }`.