Web: miekkie czolo rysowania wypelnien wykresu - maska feather zamiast twardego ciecia clip
This commit is contained in:
@@ -24,6 +24,8 @@ function ChartBackdrop() {
|
||||
const line2Ref = useRef<SVGPathElement>(null);
|
||||
const clipRef = useRef<SVGRectElement>(null);
|
||||
const clip2Ref = useRef<SVGRectElement>(null);
|
||||
const solidRef = useRef<SVGStopElement>(null);
|
||||
const fadeRef = useRef<SVGStopElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const wrap = wrapRef.current;
|
||||
@@ -31,7 +33,9 @@ function ChartBackdrop() {
|
||||
const line2 = line2Ref.current;
|
||||
const clip = clipRef.current;
|
||||
const clip2 = clip2Ref.current;
|
||||
if (!wrap || !line || !line2 || !clip || !clip2) return;
|
||||
const solid = solidRef.current;
|
||||
const fade = fadeRef.current;
|
||||
if (!wrap || !line || !line2 || !clip || !clip2 || !solid || !fade) return;
|
||||
// jsdom nie implementuje getTotalLength — bez scrubbingu w testach
|
||||
if (typeof line.getTotalLength !== 'function') return;
|
||||
|
||||
@@ -57,6 +61,9 @@ function ChartBackdrop() {
|
||||
line2.style.strokeDashoffset = String(len2 * (1 - e));
|
||||
clip.setAttribute('width', String(e * 1000));
|
||||
clip2.setAttribute('width', String(e * 1000));
|
||||
// pierzystem wypelnien mieknie ~80 jednostek przed czolkiem rysowania
|
||||
solid.setAttribute('offset', String(Math.max(e - 0.08, 0)));
|
||||
fade.setAttribute('offset', String(e));
|
||||
};
|
||||
|
||||
const run = () => {
|
||||
@@ -140,6 +147,29 @@ function ChartBackdrop() {
|
||||
<mask id="chart-mask-x" maskUnits="userSpaceOnUse" x="0" y="0" width="1000" height="950">
|
||||
<rect x="0" y="0" width="1000" height="950" fill="url(#chart-fade-x)" />
|
||||
</mask>
|
||||
<linearGradient
|
||||
id="reveal-feather"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="0"
|
||||
y1="0"
|
||||
x2="1000"
|
||||
y2="0"
|
||||
>
|
||||
<stop offset="0" stopColor="#fff" />
|
||||
<stop ref={solidRef} offset="0" stopColor="#fff" />
|
||||
<stop ref={fadeRef} offset="0" stopColor="#000" />
|
||||
<stop offset="1" stopColor="#000" />
|
||||
</linearGradient>
|
||||
<mask
|
||||
id="reveal-mask"
|
||||
maskUnits="userSpaceOnUse"
|
||||
x="0"
|
||||
y="-100"
|
||||
width="1000"
|
||||
height="1100"
|
||||
>
|
||||
<rect x="0" y="-100" width="1000" height="1100" fill="url(#reveal-feather)" />
|
||||
</mask>
|
||||
<clipPath id="chart-reveal">
|
||||
<rect ref={clipRef} x="0" y="0" width="0" height="950" />
|
||||
</clipPath>
|
||||
@@ -147,7 +177,7 @@ function ChartBackdrop() {
|
||||
<rect ref={clip2Ref} x="0" y="0" width="0" height="950" />
|
||||
</clipPath>
|
||||
</defs>
|
||||
<g clipPath="url(#chart-reveal)">
|
||||
<g mask="url(#reveal-mask)">
|
||||
<path
|
||||
d={`${CHART_PATH} L1000,900 L0,900 Z`}
|
||||
fill="url(#chart-fill)"
|
||||
@@ -155,6 +185,8 @@ function ChartBackdrop() {
|
||||
stroke="none"
|
||||
mask="url(#chart-mask-x)"
|
||||
/>
|
||||
</g>
|
||||
<g clipPath="url(#chart-reveal)">
|
||||
<path
|
||||
d={CHART_PATH}
|
||||
fill="none"
|
||||
@@ -183,7 +215,7 @@ function ChartBackdrop() {
|
||||
<circle cx="640" cy="470" r="4" fill="var(--accent)" opacity="0.9" />
|
||||
<circle cx="810" cy="560" r="4" fill="var(--accent)" opacity="0.9" />
|
||||
</g>
|
||||
<g clipPath="url(#chart-reveal-2)">
|
||||
<g mask="url(#reveal-mask)">
|
||||
<path
|
||||
d={`${CHART_PATH2} L1000,900 L0,900 Z`}
|
||||
fill="url(#chart-fill-2)"
|
||||
@@ -191,6 +223,8 @@ function ChartBackdrop() {
|
||||
stroke="none"
|
||||
mask="url(#chart-mask-x)"
|
||||
/>
|
||||
</g>
|
||||
<g clipPath="url(#chart-reveal-2)">
|
||||
<path
|
||||
d={CHART_PATH2}
|
||||
fill="none"
|
||||
|
||||
Reference in New Issue
Block a user