-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 基于 annotation shape 实现 regression line (#1803)
* feat: 基于 annotation shape 实现 trendline * fix: conversation * fix: conversation * fix: conversation Co-authored-by: liufu.lf <liufu.lf@antfin.com>
- Loading branch information
Showing
11 changed files
with
564 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { Scatter } from '../../../../src'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
const data = [ | ||
{ x: 1, y: 4.181 }, | ||
{ x: 2, y: 4.665 }, | ||
{ x: 3, y: 5.296 }, | ||
{ x: 4, y: 5.365 }, | ||
{ x: 5, y: 5.448 }, | ||
{ x: 6, y: 5.744 }, | ||
{ x: 7, y: 5.653 }, | ||
{ x: 8, y: 5.844 }, | ||
{ x: 9, y: 6.362 }, | ||
{ x: 10, y: 6.38 }, | ||
{ x: 11, y: 6.311 }, | ||
{ x: 12, y: 6.457 }, | ||
{ x: 13, y: 6.479 }, | ||
{ x: 14, y: 6.59 }, | ||
{ x: 15, y: 6.74 }, | ||
{ x: 16, y: 6.58 }, | ||
{ x: 17, y: 6.852 }, | ||
{ x: 18, y: 6.531 }, | ||
{ x: 19, y: 6.682 }, | ||
{ x: 20, y: 7.013 }, | ||
{ x: 21, y: 6.82 }, | ||
{ x: 22, y: 6.647 }, | ||
{ x: 23, y: 6.951 }, | ||
{ x: 24, y: 7.121 }, | ||
{ x: 25, y: 7.143 }, | ||
{ x: 26, y: 6.914 }, | ||
{ x: 27, y: 6.941 }, | ||
{ x: 28, y: 7.226 }, | ||
{ x: 29, y: 6.898 }, | ||
{ x: 30, y: 7.392 }, | ||
{ x: 31, y: 6.938 }, | ||
]; | ||
|
||
describe('scatter', () => { | ||
it('regressionLine: type', () => { | ||
const scatter = new Scatter(createDiv('regressionLine'), { | ||
data, | ||
width: 400, | ||
height: 300, | ||
appendPadding: 10, | ||
xField: 'x', | ||
yField: 'y', | ||
size: 5, | ||
pointStyle: { | ||
stroke: '#777777', | ||
lineWidth: 1, | ||
fill: '#5B8FF9', | ||
}, | ||
regressionLine: { | ||
type: 'quad', // linear, exp, loess, log, poly, pow, quad | ||
style: { | ||
stroke: 'red', | ||
}, | ||
}, | ||
}); | ||
|
||
scatter.render(); | ||
|
||
const geometry = scatter.chart.geometries[0]; | ||
const annotation = scatter.chart.annotation(); | ||
// @ts-ignore | ||
const options = annotation.option[0]; | ||
expect(options.type).toBe('shape'); | ||
const elements = geometry.elements; | ||
expect(elements.length).toBe(31); | ||
// @ts-ignore | ||
expect(elements[0].getModel().style.fill).toBe('#5B8FF9'); | ||
expect(elements[0].getModel().size).toBe(5); | ||
}); | ||
|
||
it('regressionLine: algorithm', () => { | ||
const scatter = new Scatter(createDiv('regressionLine*algorithm'), { | ||
data, | ||
width: 400, | ||
height: 300, | ||
appendPadding: 10, | ||
xField: 'x', | ||
yField: 'y', | ||
size: 5, | ||
pointStyle: { | ||
stroke: '#777777', | ||
lineWidth: 1, | ||
fill: '#5B8FF9', | ||
}, | ||
regressionLine: { | ||
algorithm: [ | ||
[0, 0], | ||
[200, 200], | ||
], | ||
}, | ||
}); | ||
|
||
scatter.render(); | ||
|
||
const geometry = scatter.chart.geometries[0]; | ||
const annotation = scatter.chart.annotation(); | ||
// @ts-ignore | ||
const options = annotation.option[0]; | ||
expect(options.type).toBe('shape'); | ||
const elements = geometry.elements; | ||
expect(elements.length).toBe(31); | ||
// @ts-ignore | ||
expect(elements[0].getModel().style.fill).toBe('#5B8FF9'); | ||
expect(elements[0].getModel().size).toBe(5); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Scatter } from '@antv/g2plot'; | ||
|
||
const data = [ | ||
{ x: 1, y: 4.181 }, | ||
{ x: 2, y: 4.665 }, | ||
{ x: 3, y: 5.296 }, | ||
{ x: 4, y: 5.365 }, | ||
{ x: 5, y: 5.448 }, | ||
{ x: 6, y: 5.744 }, | ||
{ x: 7, y: 5.653 }, | ||
{ x: 8, y: 5.844 }, | ||
{ x: 9, y: 6.362 }, | ||
{ x: 10, y: 6.38 }, | ||
{ x: 11, y: 6.311 }, | ||
{ x: 12, y: 6.457 }, | ||
{ x: 13, y: 6.479 }, | ||
{ x: 14, y: 6.59 }, | ||
{ x: 15, y: 6.74 }, | ||
{ x: 16, y: 6.58 }, | ||
{ x: 17, y: 6.852 }, | ||
{ x: 18, y: 6.531 }, | ||
{ x: 19, y: 6.682 }, | ||
{ x: 20, y: 7.013 }, | ||
{ x: 21, y: 6.82 }, | ||
{ x: 22, y: 6.647 }, | ||
{ x: 23, y: 6.951 }, | ||
{ x: 24, y: 7.121 }, | ||
{ x: 25, y: 7.143 }, | ||
{ x: 26, y: 6.914 }, | ||
{ x: 27, y: 6.941 }, | ||
{ x: 28, y: 7.226 }, | ||
{ x: 29, y: 6.898 }, | ||
{ x: 30, y: 7.392 }, | ||
{ x: 31, y: 6.938 }, | ||
]; | ||
const scatterPlot = new Scatter('container', { | ||
data, | ||
xField: 'x', | ||
yField: 'y', | ||
size: 5, | ||
pointStyle: { | ||
stroke: '#777777', | ||
lineWidth: 1, | ||
fill: '#5B8FF9', | ||
}, | ||
regressionLine: { | ||
type: 'quad', // linear, exp, loess, log, poly, pow, quad | ||
}, | ||
}); | ||
scatterPlot.render(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.