d3.js - 屏蔽形状以创建透明部分 [英] d3.js - masking shapes to create transparent sectio

查看:432
本文介绍了d3.js - 屏蔽形状以创建透明部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感兴趣的是学习如何创建d3.js一个透明的面具。

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

http://jsfiddle.net/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");


});


推荐答案

随意使用它来调整参数:

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);

修改示例: http://jsfiddle.net/59bunh8u/40/

另请参阅 SVG clipPath剪辑*外部*内容输出

这篇关于d3.js - 屏蔽形状以创建透明部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆