javascript - d3.js - masking shapes to create transparent sectio - Stack Overflow

I am interested in learning how to create a transparent mask with d3.js.This is where I am up to - how

I am interested in learning how to create a transparent mask with d3.js.

/

This is where I am up to - how would I create a subtraction mask on the red rectangle - also how could you style the red rectangle to take on more of a multiply style property?

$(document).ready(function() {

  var el = $(".mask"); //selector

  // Set the main elements for the series chart
  var svg = d3.select(el[0]).append("svg")
    .attr("class", "series")
    .attr("width", "800px")
    .attr("height", "500px")
    .append("g")
    .attr("transform", "translate(0,0)")


  var rect = svg
    .append("rect")
    .attr("x", 0)
    .attr("y", 0)
    .attr("width", 500)
    .attr("height", 500)
    .style("fill", "red")
    .style('opacity', 0.75)

  var rect = svg
    .append("circle").attr("cx", 250).attr("cy", 250).attr("r", 125).style("fill", "white");


});

I am interested in learning how to create a transparent mask with d3.js.

http://jsfiddle/59bunh8u/35/

This is where I am up to - how would I create a subtraction mask on the red rectangle - also how could you style the red rectangle to take on more of a multiply style property?

$(document).ready(function() {

  var el = $(".mask"); //selector

  // Set the main elements for the series chart
  var svg = d3.select(el[0]).append("svg")
    .attr("class", "series")
    .attr("width", "800px")
    .attr("height", "500px")
    .append("g")
    .attr("transform", "translate(0,0)")


  var rect = svg
    .append("rect")
    .attr("x", 0)
    .attr("y", 0)
    .attr("width", 500)
    .attr("height", 500)
    .style("fill", "red")
    .style('opacity', 0.75)

  var rect = svg
    .append("circle").attr("cx", 250).attr("cy", 250).attr("r", 125).style("fill", "white");


});
Share Improve this question asked Sep 6, 2016 at 22:57 The Old CountyThe Old County 13914 gold badges67 silver badges142 bronze badges 1
  • -- this shows promise -- jsfiddle/0g6pj8dm/1 – The Old County Commented Sep 7, 2016 at 2:00
Add a ment  | 

1 Answer 1

Reset to default 5

You need an SVG mask. Feel free to play with it to tweak the parameters:

  var mask = svgroot
     .append("defs")
     .append("mask")
     .attr("id", "myMask");

  mask.append("rect")
    .attr("x", 0)
    .attr("y", 0)
    .attr("width", 500)
    .attr("height", 500)
    .style("fill", "white")
    .style("opacity", 0.7);        

  mask.append("circle")
    .attr("cx", 300)
    .attr("cy", 300)
    .attr("r", 100);

Modified example: http://jsfiddle/59bunh8u/40/

See also SVG clipPath to clip the *outer* content out

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745491023a4629989.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信