Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix the transpose color gradient render #5809

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/shape/area/curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ export const Curve: SC<CurveOptions> = (options, context) => {
seriesX: sx,
seriesY: sy,
} = value;
const tpShape = isTranspose(coordinate);
const transform = getTransform(coordinate, value);
const fill = gradient && sc ? computeGradient(sc, sx, sy, gradient) : color;
const fill =
gradient && sc
? computeGradient(sc, sx, sy, gradient, undefined, tpShape)
: color;

const finalStyle = {
...defaults,
Expand Down Expand Up @@ -119,7 +123,7 @@ export const Curve: SC<CurveOptions> = (options, context) => {
const areaPath = (points) => {
const Y1 = points.slice(0, points.length / 2);
const Y0 = points.slice(points.length / 2);
return isTranspose(coordinate)
return tpShape
? area()
.y((_, idx) => Y1[idx][1])
.x1((_, idx) => Y1[idx][0])
Expand Down
9 changes: 6 additions & 3 deletions src/shape/line/curve.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { line, lineRadial, CurveFactory, CurveFactoryLineOnly } from 'd3-shape';
import { Vector2 } from '@antv/coord';
import { isPolar } from '../../utils/coordinate';
import { isPolar, isTranspose } from '../../utils/coordinate';
import { select } from '../../utils/selection';
import { ShapeComponent as SC } from '../../runtime';
import { applyStyle, computeGradient, getTransform } from '../utils';
Expand Down Expand Up @@ -89,11 +89,14 @@ export const Curve: SC<CurveOptions> = (options, context) => {
seriesX: sx,
seriesY: sy,
} = value;

const transform = getTransform(coordinate, value);
const tpShape = isTranspose(coordinate);
const stroke =
gradient && sc
? computeGradient(sc, sx, sy, gradient, gradientColor)
? computeGradient(sc, sx, sy, gradient, gradientColor, tpShape)
: color;
const transform = getTransform(coordinate, value);

const finalStyle = {
...rest,
...(stroke && { stroke }),
Expand Down
21 changes: 20 additions & 1 deletion src/shape/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,29 @@ export function computeGradient(
Y: number[],
from: string | boolean = 'y',
mode: 'between' | 'start' | 'end' = 'between',
tpShape = false,
): string {
// The angles of gradients rendering are varies when 'from' and 'tpShape' are different.
const getTheta = (from: string | boolean, tpShape: boolean) => {
if (from === 'y' || from === true) {
if (tpShape) {
return 180;
} else {
return 90;
}
} else {
if (tpShape) {
return 90;
} else {
return 0;
}
}
};
pearmini marked this conversation as resolved.
Show resolved Hide resolved

const P = from === 'y' || from === true ? Y : X;
const theta = from === 'y' || from === true ? 90 : 0;
const theta = getTheta(from, tpShape);
const I = indexOf(P);

const [min, max] = extent(I, (i) => P[i]);
// This need to improve for non-uniform distributed colors.
const p = new Linear({
Expand Down
Loading