Skip to content

Commit

Permalink
fix(ava/insight): correct sign of regression line & format the mean i…
Browse files Browse the repository at this point in the history
…n lowVarianceMark
  • Loading branch information
LAI-X authored and BBSQQ committed Nov 17, 2023
1 parent 8257cb3 commit b1eeeb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Mark } from '@antv/g2';
import { LineMark, Mark } from '@antv/g2';

import { LowVarianceInfo, InsightInfo } from '../../../types';
import { lineMarkStrategy } from '../commonMarks';
import { insight2ChartStrategy } from '../chart';
import { LowVarianceMark } from '../../types';
import { augmentedMarks2Marks } from '../../utils';
import { dataFormat } from '../../../../utils';

export const lowVarianceAugmentedMarkStrategy = (insight: InsightInfo<LowVarianceInfo>): LowVarianceMark[] => {
const { patterns } = insight;
const marks: LowVarianceMark[] = [];
patterns.forEach((pattern) => {
const { mean } = pattern;
const meanLineMark = lineMarkStrategy({ y: mean }, { label: `mean: ${mean}` });
const meanLineMark = lineMarkStrategy({ y: mean }, { label: `mean: ${dataFormat(mean)}` }) as LineMark;
marks.push({
meanLine: [meanLineMark],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { lineMarkStrategy } from '../commonMarks';
import { insight2ChartStrategy } from '../chart';
import { InsightInfo, TrendInfo } from '../../../types';
import { TrendMark } from '../../types';
import { dataFormat } from '../../../../utils';

export const trendAugmentedMarksStrategy = (insight: InsightInfo<TrendInfo>): TrendMark[] => {
const {
Expand All @@ -28,7 +29,10 @@ export const trendAugmentedMarksStrategy = (insight: InsightInfo<TrendInfo>): Tr

const lineData = points.map((point) => ({ x: point[0], y: point[1] }));

const regressionLineMark = lineMarkStrategy({ points: lineData }, { label: `y=${m.toFixed(2)}x+${c.toFixed(2)}` });
const regressionLineMark = lineMarkStrategy(
{ points: lineData },
{ label: `y=${dataFormat(m)}x${c < 0 ? '' : '+'}${dataFormat(c)}` }
);

return [
{
Expand Down

0 comments on commit b1eeeb6

Please sign in to comment.