Tôi đang sử dụng d3 v4
để hiển thị đồ họa SVG. Tôi đang sử dụng một clipPath trên một vài yếu tố <path>
. Tôi có hành vi panning trên một phần tử rect và clipPath đang giúp ẩn một số phần tử đường dẫn. Khi lướt qua trong android. ClipPath hoạt động khi cần thiết, nhưng khi panning trong iOS bản vẽ được render sôi nổi. Xem dưới đây:Ứng dụng webview cho iOS SVG ClipPath Issue
TRƯỚC
Tôi đã thực hiện clip SVG với đoạn mã sau:
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);
Ông là exce rpts từ zoom được gọi là zoom.
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);
...
}
Có ai có cùng vấn đề khi sử dụng clipPath không?
Tôi sẽ nói điều này là do thực tế là clipPath và các phần tử bạn đang cắt không được xác định trong cùng một hệ tọa độ và không chịu cùng biến đổi http://stackoverflow.com/a/38088473/1160916 – Ashitaka
@Ashitaka tại sao điều này làm việc cho mọi trình duyệt nhưng IOS? nó thậm chí hoạt động trong safari. Bạn có ý kiến gì không? – inspired