Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/chart/line/LineSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export interface LineSeriesOption extends SeriesOption<LineStateOption<CallbackD
data?: (LineDataValue | LineDataItemOption)[]

triggerLineEvent?: boolean

closed?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think loop (inspired by gl.LINE_LOOP of WebGL) may be a better name than closed because it may not always be closed due to the existance of null data.

}

class LineSeriesModel extends SeriesModel<LineSeriesOption> {
Expand Down Expand Up @@ -152,6 +154,8 @@ class LineSeriesModel extends SeriesModel<LineSeriesOption> {

clip: true,

closed: false,

label: {
position: 'top'
},
Expand Down
16 changes: 10 additions & 6 deletions src/chart/line/LineView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ class LineView extends ChartView {

const connectNulls = seriesModel.get('connectNulls');

const closed = isCoordSysPolar && seriesModel.get('closed');

const isIgnoreFunc = showSymbol && !isCoordSysPolar
&& getIsIgnoreFunc(seriesModel, data, coordSys as Cartesian2D);

Expand Down Expand Up @@ -725,10 +727,10 @@ class LineView extends ChartView {
}
}

polyline = this._newPolyline(points);
polyline = this._newPolyline(points, closed);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a better idea to define const closed = isCoordSysPolar && seriesModel.get('closed'); here. It will make the code more readable and postpone the execution until necessary.

if (isAreaChart) {
polygon = this._newPolygon(
points, stackedOnPoints
points, stackedOnPoints, closed
);
}// If areaStyle is removed
else if (polygon) {
Expand All @@ -749,7 +751,7 @@ class LineView extends ChartView {
if (isAreaChart && !polygon) {
// If areaStyle is added
polygon = this._newPolygon(
points, stackedOnPoints
points, stackedOnPoints, closed
);
}
else if (polygon && !isAreaChart) {
Expand Down Expand Up @@ -1019,7 +1021,7 @@ class LineView extends ChartView {
polygon && setStatesFlag(polygon, toState);
}

_newPolyline(points: ArrayLike<number>) {
_newPolyline(points: ArrayLike<number>, closed: boolean) {
let polyline = this._polyline;
// Remove previous created polyline
if (polyline) {
Expand All @@ -1028,7 +1030,8 @@ class LineView extends ChartView {

polyline = new ECPolyline({
shape: {
points
points,
closed
},
segmentIgnoreThreshold: 2,
z2: 10
Expand All @@ -1041,7 +1044,7 @@ class LineView extends ChartView {
return polyline;
}

_newPolygon(points: ArrayLike<number>, stackedOnPoints: ArrayLike<number>) {
_newPolygon(points: ArrayLike<number>, stackedOnPoints: ArrayLike<number>, closed: boolean) {
let polygon = this._polygon;
// Remove previous created polygon
if (polygon) {
Expand All @@ -1051,6 +1054,7 @@ class LineView extends ChartView {
polygon = new ECPolygon({
shape: {
points,
closed,
stackedOnPoints: stackedOnPoints
},
segmentIgnoreThreshold: 2
Expand Down
28 changes: 23 additions & 5 deletions src/chart/line/poly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class ECPolylineShape {
smoothConstraint = true;
smoothMonotone: 'x' | 'y' | 'none';
connectNulls: boolean;
closed = false;
}

interface ECPolylineProps extends PathProps {
Expand Down Expand Up @@ -245,7 +246,15 @@ export class ECPolyline extends Path<ECPolylineProps> {
}

buildPath(ctx: PathProxy, shape: ECPolylineShape) {
const points = shape.points;
const points = shape.closed
? [
shape.points[shape.points.length - 2],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if shape.points.length is less than 2?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to consider the situation when some of the data is null and when connectNulls is set to either true or false. Please add test cases.

shape.points[shape.points.length - 1],
...shape.points as number[],
shape.points[0],
shape.points[1]
]
: shape.points;

let i = 0;
let len = points.length / 2;
Expand All @@ -267,7 +276,7 @@ export class ECPolyline extends Path<ECPolylineProps> {
}
while (i < len) {
i += drawSegment(
ctx, points, i, len, len,
ctx, points, shape.closed ? i - 1 : i, len, shape.closed ? len - 1 : len,
1,
shape.smooth,
shape.smoothMonotone, shape.connectNulls
Expand Down Expand Up @@ -369,7 +378,15 @@ export class ECPolygon extends Path {
}

buildPath(ctx: PathProxy, shape: ECPolygonShape) {
const points = shape.points;
const points = shape.closed
? [
shape.points[shape.points.length - 2],
shape.points[shape.points.length - 1],
...shape.points as number[],
shape.points[0],
shape.points[1]
]
: shape.points;
const stackedOnPoints = shape.stackedOnPoints;

let i = 0;
Expand All @@ -391,13 +408,14 @@ export class ECPolygon extends Path {
}
while (i < len) {
const k = drawSegment(
ctx, points, i, len, len,
ctx, points,
shape.closed ? i - 1 : i, len, shape.closed ? len - 1 : len,
1,
shape.smooth,
smoothMonotone, shape.connectNulls
);
drawSegment(
ctx, stackedOnPoints, i + k - 1, k, len,
ctx, stackedOnPoints, i + k - 1 - (shape.closed ? 1 : 0), k, shape.closed ? len - 1 : len,
-1,
shape.stackedOnSmooth,
smoothMonotone, shape.connectNulls
Expand Down