IOS app webview SVG ClipPath问题

Abd*_*eed 9 javascript svg ios d3.js

我正在使用d3 v4渲染SVG图形.我在几个元素上使用了clipPath<path>.我在rect元素上有平移行为,而clipPath正在帮助隐藏一些路径元素.在android中平移时.clipPath可以根据需要运行,但是在iOS中进行平移时,绘图会变得很时髦.见下文:

之前

之前

PANNING之后

我用以下代码实现了SVG剪辑:

   this.line = d3.line()
    .curve(d3.curveMonotoneX)
    .x((d) => this.xScale(this.getDate(d)))
    .y((d) => this.yScale(d.kWh));

this.area = d3.area()
    .curve(d3.curveMonotoneX)
    .x((d) => {
        return this.xScale(this.getDate(d))
    })
    .y0(this.height)
    .y1((d) => this.yScale(d.kWh));

// Definition for clipPath
this.svg.append("defs").append("clipPath")
    .attr("id", "clip")
    .append("rect")
    .attr("width", this.width)
    .attr('transform', 'translate(0,-20)')
    .attr("height", this.height + 20);
// clipPath added to area
var areaPath = this.focus.append("path")
    .datum(this.data)
    .attr("class", "area")
    .attr('height', this.height)
    .attr('fill-opacity', .2)
    .attr('clip-path', 'url(#clip)')
    .attr("d", this.area)
    .attr("transform", "translate(0," + 80 + ")")
    .style("fill", "url(#gradient)");
// clipPath added to the line
var linePath = this.focus.append('path')
    .datum(this.data)
    .attr('class', 'line')
    .attr('fill', 'none')
    .attr('clip-path', 'url(#clip)')
    .attr('stroke', '#31B5BB')
    .attr('stroke-width', '2px')
    .attr("transform", "translate(0," + 80 + ")")
    .attr('d', this.line);
Run Code Online (Sandbox Code Playgroud)

他是变焦时缩放的摘录.

    private zoomed = () => {

        if (this.isMinZooming) return;

        let diff,
            domain,
            minBuffer,
            maxBuffer,
            t;

        t = d3.event.transform;
        // loose mobile events
        if (isNaN(t.k)) return;

        this.xScale.domain(t.rescaleX(this.x2Scale).domain());
        diff = this.daydiff(this.xScale.domain()[0], this.xScale.domain()[1]);

        // Redraw Axis
        this.xAxis = d3.axisBottom(this.xScale).tickSize(0).tickFormat(d3.timeFormat('%b'));
        this.focus.select(".axis--x").call(this.xAxis);

        // Redraw Paths. This is where the redraw function gets messy in the iOS webview.
        this.focus.select(".area").attr("d", this.area);
        this.focus.select('.line').attr('d', this.line);

        ...
}
Run Code Online (Sandbox Code Playgroud)

使用clipPath时有没有人遇到过同样的问题?

Abd*_*eed 0

我想通了这个问题。这是一个如此愚蠢的错误。我在 css 文件中的某处定义:

.area{
   clip-path: url(#clip);
}
Run Code Online (Sandbox Code Playgroud)

在所有浏览器中,这都适用于<rect><path>,但对于 ,iOS webview它会呈现上述显示错误。

我不是在一个单独的文件中定义它 ,而是为我想要应用它的CSS所有内容内联定义它:SVG Object

  var areaPath = this.focus.append("path")
        ...
        .attr('clip-path', 'url(#clip)') //defining it inline
Run Code Online (Sandbox Code Playgroud)

这个错误让我发疯,但我很高兴我找到了解决方案。