Skip to content

Commit

Permalink
fix(ava): 修改计算insight mark的方法&补充示例 (#13)
Browse files Browse the repository at this point in the history
* fix(ava): 修改获取insight mark的方法&补充示例 (#9)

* fix(ava): 修改获取insight mark的方法

* fix(ava): 补充insight mark示例

* fix(ava): 删除demo中的styles配置

---------

Co-authored-by: laixingui.lxg <[email protected]>

* chore(ava): 更新ava版本 (#12)

* fix(ava): 解决格式问题 (#14)

---------

Co-authored-by: laixingui.lxg <[email protected]>
  • Loading branch information
LAI-X and laixingui.lxg authored Nov 17, 2023
1 parent eaf7b8c commit 2038f2a
Show file tree
Hide file tree
Showing 20 changed files with 259 additions and 113 deletions.
10 changes: 10 additions & 0 deletions ava/__tests__/data/category-outlier.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
year,value
1991,6
1992,1.6
1993,5
1994,5
1995,6
1996,4
1997,0.5
1998,5
1999,5
10 changes: 10 additions & 0 deletions ava/__tests__/data/change-point.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
year,value
1991,0.3
1992,-0.5
1993,0.05
1994,-0.2
1995,0.4
1996,6
1997,5
1998,8
1999,5
31 changes: 31 additions & 0 deletions ava/__tests__/plots/category-outlier-basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { register } from "@antv/g2";
import { CategoryOutlier } from "../../src/insights";

/** @ts-ignore */
register("mark.categoryOutlier", CategoryOutlier);

export function CategoryOutlierBasic() {
return {
type: "view",
children: [
// 原始图表
{
data: { type: "fetch", value: "data/category-outlier.csv" },
encode: {
x: "year",
y: "value",
},
type: "interval",
},
// 异常点 mark
{
type: "categoryOutlier",
data: { type: "fetch", value: "data/category-outlier.csv" },
encode: {
x: "year",
y: "value",
},
},
],
};
}
31 changes: 31 additions & 0 deletions ava/__tests__/plots/change-point-basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { register } from "@antv/g2";
import { ChangePoint } from "../../src/insights";

/** @ts-ignore */
register("mark.changePoint", ChangePoint);

export function ChangePointBasic() {
return {
type: "view",
children: [
// 原始图表
{
data: { type: "fetch", value: "data/change-point.csv" },
encode: {
x: "year",
y: "value",
},
type: "line",
},
// 突变点 mark
{
type: "changePoint",
data: { type: "fetch", value: "data/change-point.csv" },
encode: {
x: "year",
y: "value",
},
},
],
};
}
8 changes: 6 additions & 2 deletions ava/__tests__/plots/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export { AlphabetAutoBasic } from "./alphabet-auto-basic";
export { InsightBasic } from './insight-basic';
export { TimeSeriesOutlierBasic } from './time-series-outlier-basic'
export { InsightBasic } from "./insight-basic";
export { TimeSeriesOutlierBasic } from "./time-series-outlier-basic";
export { TrendBasic } from "./trend-basic";
export { ChangePointBasic } from "./change-point-basic";
export { CategoryOutlierBasic } from "./category-outlier-basic";
export { LowVarianceBasic } from "./low-variance-basic";
16 changes: 7 additions & 9 deletions ava/__tests__/plots/insight-basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ register("mark.insight", Insight);

export function InsightBasic() {
return {
type: 'view',
type: "view",
children: [
// 原始图表
{
data: { type: "fetch", value: "data/basic-time-series.csv" },
encode: {
"x": "year",
"y": "life_expect"
x: "year",
y: "life_expect",
},
type: "line",
},
Expand All @@ -22,12 +22,10 @@ export function InsightBasic() {
type: "insight",
data: { type: "fetch", value: "data/basic-time-series.csv" },
// 指定分析的维度、指标和分析类型
measures: [
{ fieldName: 'life_expect', method: 'SUM' },
],
dimensions: [{fieldName: 'year'}],
insightType: 'trend',
measures: [{ fieldName: "life_expect", method: "SUM" }],
dimensions: [{ fieldName: "year" }],
insightType: "trend",
},
]
],
};
}
31 changes: 31 additions & 0 deletions ava/__tests__/plots/low-variance-basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { register } from "@antv/g2";
import { LowVariance } from "../../src/insights";

/** @ts-ignore */
register("mark.lowVariance", LowVariance);

export function LowVarianceBasic() {
return {
type: "view",
children: [
// 原始图表
{
data: { type: "fetch", value: "data/basic-time-series.csv" },
encode: {
x: "year",
y: "life_expect",
},
type: "interval",
},
// 低方差 mark
{
type: "lowVariance",
data: { type: "fetch", value: "data/basic-time-series.csv" },
encode: {
x: "year",
y: "life_expect",
},
},
],
};
}
15 changes: 6 additions & 9 deletions ava/__tests__/plots/time-series-outlier-basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,26 @@ register("mark.timeSeriesOutlier", TimeSeriesOutlier);

export function TimeSeriesOutlierBasic() {
return {
type: 'view',
type: "view",
children: [
// 原始图表
{
data: { type: "fetch", value: "data/basic-time-series.csv" },
encode: {
"x": "year",
"y": "life_expect"
x: "year",
y: "life_expect",
},
type: "line",
style: {
"lineWidth": 2
}
},
// 异常点 mark
{
type: "timeSeriesOutlier",
data: { type: "fetch", value: "data/basic-time-series.csv" },
encode: {
"x": "year",
"y": "life_expect"
x: "year",
y: "life_expect",
},
},
]
],
};
}
30 changes: 30 additions & 0 deletions ava/__tests__/plots/trend-basic.ts
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
import { register } from "@antv/g2";
import { Trend } from "../../src/insights";

/** @ts-ignore */
register("mark.trend", Trend);

export function TrendBasic() {
return {
type: "view",
children: [
// 原始图表
{
data: { type: "fetch", value: "data/change-point.csv" },
encode: {
x: "year",
y: "value",
},
type: "line",
},
// 趋势线 mark
{
type: "trend",
data: { type: "fetch", value: "data/change-point.csv" },
encode: {
x: "year",
y: "value",
},
},
],
};
}
4 changes: 2 additions & 2 deletions ava/__tests__/unit/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "vitest";
import { Auto, Insight, autolib } from "../../src";
import { CategoryOutlier, ChangePoint, Correlation, LowVariance, TimeSeriesOutlier, Trend } from "../../src/insights";
import { CategoryOutlier, ChangePoint, LowVariance, TimeSeriesOutlier, Trend } from "../../src/insights";

test("g2-extension-ava should export expected marks", () => {
expect(Auto).toBeDefined();
Expand All @@ -15,6 +15,6 @@ test("autolib should export expected marks", () => {
// "mark.correlation": Correlation,
"mark.changePoint": ChangePoint,
"mark.lowVariance": LowVariance,
"mark.categoryOutlier": CategoryOutlier
"mark.categoryOutlier": CategoryOutlier,
});
});
2 changes: 1 addition & 1 deletion ava/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build": "run-p build:*"
},
"dependencies": {
"@antv/ava": "^3.2.0",
"@antv/ava": "^3.3.0",
"@antv/util": "^3.3.5"
},
"peerDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions ava/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Auto } from "./auto";
import { CategoryOutlier, ChangePoint, Correlation, Insight, LowVariance, TimeSeriesOutlier, Trend } from "./insights";
import { CategoryOutlier, ChangePoint, Insight, LowVariance, TimeSeriesOutlier, Trend } from "./insights";

export function autolib() {
return {
Expand All @@ -11,9 +11,9 @@ export function autolib() {
// "mark.correlation": Correlation,
"mark.changePoint": ChangePoint,
"mark.lowVariance": LowVariance,
"mark.categoryOutlier": CategoryOutlier
"mark.categoryOutlier": CategoryOutlier,
};
}

export * from './auto';
export * from './insights'
export * from "./auto";
export * from "./insights";
20 changes: 10 additions & 10 deletions ava/src/insights/categoryOutlier.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { InsightExtractorProps } from "@antv/ava";
import { Insight, type InsightMarkOptions } from "./insight";

export type CategoryOutlierMarkOptions = Omit<InsightMarkOptions, 'insightType' | 'options'> & {
algorithmParameter?: Pick<InsightExtractorProps['options']['algorithmParameter'], 'outlier'>
};;
export type CategoryOutlierMarkOptions = Omit<InsightMarkOptions, "insightType" | "options"> & {
algorithmParameter?: Pick<InsightExtractorProps["options"]["algorithmParameter"], "outlier">;
};

/** 类别型数据异常检测高阶 Mark
/** 类别型数据异常检测高阶 Mark
* category outlier detection augmented mark
*/
*/
export const CategoryOutlier = (options: CategoryOutlierMarkOptions) => {
const {algorithmParameter, ...restOptions} = options
const { algorithmParameter, ...restOptions } = options;
return Insight({
...restOptions,
options: {
algorithmParameter
algorithmParameter,
},
insightType: 'category_outlier'
})
}
insightType: "category_outlier",
});
};
18 changes: 9 additions & 9 deletions ava/src/insights/changePoint.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { InsightExtractorProps } from "@antv/ava";
import { Insight, type InsightMarkOptions } from "./insight";

export type ChangePointMarkOptions = Omit<InsightMarkOptions, 'insightType' | 'options'> & {
algorithmParameter?: Pick<InsightExtractorProps['options']['algorithmParameter'], 'changePoint'>
export type ChangePointMarkOptions = Omit<InsightMarkOptions, "insightType" | "options"> & {
algorithmParameter?: Pick<InsightExtractorProps["options"]["algorithmParameter"], "changePoint">;
};

/** 突变点检测高阶 Mark
/** 突变点检测高阶 Mark
* change point detection augmented mark
*/
*/
export const ChangePoint = (options: ChangePointMarkOptions) => {
const {algorithmParameter, ...restOptions} = options
const { algorithmParameter, ...restOptions } = options;
return Insight({
...restOptions,
options: {
algorithmParameter
algorithmParameter,
},
insightType: 'change_point'
})
}
insightType: "change_point",
});
};
18 changes: 9 additions & 9 deletions ava/src/insights/correlation.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { InsightExtractorProps } from "@antv/ava";
import { Insight, type InsightMarkOptions } from "./insight";

export type CorrelationMarkOptions = Omit<InsightMarkOptions, 'insightType' | 'options'> & {
algorithmParameter?: Pick<InsightExtractorProps['options']['algorithmParameter'], 'correlation'>
export type CorrelationMarkOptions = Omit<InsightMarkOptions, "insightType" | "options"> & {
algorithmParameter?: Pick<InsightExtractorProps["options"]["algorithmParameter"], "correlation">;
};

/** 相关性拟合线高阶 Mark
/** 相关性拟合线高阶 Mark
* correlation regression line
*/
*/
export const Correlation = (options: CorrelationMarkOptions) => {
const {algorithmParameter, ...restOptions} = options
const { algorithmParameter, ...restOptions } = options;
return Insight({
...restOptions,
options: {
algorithmParameter
algorithmParameter,
},
insightType: 'correlation'
})
}
insightType: "correlation",
});
};
14 changes: 7 additions & 7 deletions ava/src/insights/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './insight'
export * from './lowVariance'
export * from './categoryOutlier'
export * from './changePoint'
export * from './correlation'
export * from './trend'
export * from './timeSeriesOutlier'
export * from "./insight";
export * from "./lowVariance";
export * from "./categoryOutlier";
export * from "./changePoint";
export * from "./correlation";
export * from "./trend";
export * from "./timeSeriesOutlier";
Loading

0 comments on commit 2038f2a

Please sign in to comment.