@formant/ava 3.4.21-formant → 3.5.0-formant

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/ava.min.js +1 -1
  2. package/esm/insight/chart/constants.js +2 -23
  3. package/esm/insight/chart/generator/index.js +0 -1
  4. package/esm/insight/chart/generator/insights.js +2 -2
  5. package/esm/insight/chart/index.js +0 -1
  6. package/esm/insight/chart/strategy/augmentedMarks/categoryOutlier.js +5 -11
  7. package/esm/insight/chart/strategy/augmentedMarks/changePoint.js +11 -27
  8. package/esm/insight/chart/strategy/augmentedMarks/correlation.js +1 -2
  9. package/esm/insight/chart/strategy/augmentedMarks/index.js +0 -1
  10. package/esm/insight/chart/strategy/augmentedMarks/lowVariance.js +6 -11
  11. package/esm/insight/chart/strategy/augmentedMarks/majority.js +1 -2
  12. package/esm/insight/chart/strategy/augmentedMarks/timeSeriesOutlier.js +10 -67
  13. package/esm/insight/chart/strategy/augmentedMarks/trend.js +9 -9
  14. package/esm/insight/chart/strategy/chart.js +16 -27
  15. package/esm/insight/chart/strategy/commonMarks/areaMark.js +1 -11
  16. package/esm/insight/chart/strategy/commonMarks/barMark.js +6 -0
  17. package/esm/insight/chart/strategy/commonMarks/index.js +2 -2
  18. package/esm/insight/chart/strategy/commonMarks/lineMark.js +1 -33
  19. package/esm/insight/chart/strategy/commonMarks/pointMark.js +8 -12
  20. package/esm/insight/chart/strategy/commonMarks/ruleMark.js +2 -0
  21. package/esm/insight/chart/strategy/viewSpec.js +19 -13
  22. package/esm/insight/chart/types.js +7 -0
  23. package/esm/insight/narrative/strategy/categoryOutlier.js +2 -2
  24. package/esm/insight/narrative/strategy/trend.js +1 -1
  25. package/esm/insight/pipeline/specificInsight.js +2 -6
  26. package/esm/insight/pipeline/visualize.js +0 -2
  27. package/lib/index.d.ts +1 -1
  28. package/lib/insight/chart/constants.d.ts +2 -11
  29. package/lib/insight/chart/constants.js +3 -24
  30. package/lib/insight/chart/generator/index.d.ts +0 -1
  31. package/lib/insight/chart/generator/index.js +0 -1
  32. package/lib/insight/chart/generator/insights.d.ts +2 -2
  33. package/lib/insight/chart/generator/insights.js +2 -2
  34. package/lib/insight/chart/index.d.ts +0 -1
  35. package/lib/insight/chart/index.js +0 -1
  36. package/lib/insight/chart/strategy/augmentedMarks/categoryOutlier.d.ts +2 -3
  37. package/lib/insight/chart/strategy/augmentedMarks/categoryOutlier.js +4 -10
  38. package/lib/insight/chart/strategy/augmentedMarks/changePoint.d.ts +2 -3
  39. package/lib/insight/chart/strategy/augmentedMarks/changePoint.js +11 -27
  40. package/lib/insight/chart/strategy/augmentedMarks/correlation.d.ts +2 -2
  41. package/lib/insight/chart/strategy/augmentedMarks/correlation.js +1 -2
  42. package/lib/insight/chart/strategy/augmentedMarks/index.d.ts +0 -1
  43. package/lib/insight/chart/strategy/augmentedMarks/index.js +1 -3
  44. package/lib/insight/chart/strategy/augmentedMarks/lowVariance.d.ts +2 -3
  45. package/lib/insight/chart/strategy/augmentedMarks/lowVariance.js +5 -10
  46. package/lib/insight/chart/strategy/augmentedMarks/majority.d.ts +2 -2
  47. package/lib/insight/chart/strategy/augmentedMarks/majority.js +1 -2
  48. package/lib/insight/chart/strategy/augmentedMarks/timeSeriesOutlier.d.ts +2 -3
  49. package/lib/insight/chart/strategy/augmentedMarks/timeSeriesOutlier.js +10 -67
  50. package/lib/insight/chart/strategy/augmentedMarks/trend.d.ts +2 -3
  51. package/lib/insight/chart/strategy/augmentedMarks/trend.js +9 -9
  52. package/lib/insight/chart/strategy/chart.d.ts +6 -3
  53. package/lib/insight/chart/strategy/chart.js +15 -26
  54. package/lib/insight/chart/strategy/commonMarks/areaMark.d.ts +2 -3
  55. package/lib/insight/chart/strategy/commonMarks/areaMark.js +1 -11
  56. package/lib/insight/chart/strategy/commonMarks/barMark.d.ts +4 -0
  57. package/lib/insight/chart/strategy/commonMarks/barMark.js +10 -0
  58. package/lib/insight/chart/strategy/commonMarks/index.d.ts +2 -2
  59. package/lib/insight/chart/strategy/commonMarks/index.js +5 -5
  60. package/lib/insight/chart/strategy/commonMarks/lineMark.d.ts +2 -3
  61. package/lib/insight/chart/strategy/commonMarks/lineMark.js +1 -33
  62. package/lib/insight/chart/strategy/commonMarks/pointMark.d.ts +5 -4
  63. package/lib/insight/chart/strategy/commonMarks/pointMark.js +7 -11
  64. package/lib/insight/chart/strategy/commonMarks/ruleMark.d.ts +2 -0
  65. package/lib/insight/chart/strategy/commonMarks/ruleMark.js +6 -0
  66. package/lib/insight/chart/strategy/viewSpec.d.ts +9 -3
  67. package/lib/insight/chart/strategy/viewSpec.js +19 -13
  68. package/lib/insight/chart/types.d.ts +99 -42
  69. package/lib/insight/chart/types.js +7 -0
  70. package/lib/insight/chart/utils.d.ts +2 -3
  71. package/lib/insight/index.d.ts +1 -1
  72. package/lib/insight/narrative/strategy/categoryOutlier.js +2 -2
  73. package/lib/insight/narrative/strategy/trend.js +1 -1
  74. package/lib/insight/pipeline/specificInsight.d.ts +2 -3
  75. package/lib/insight/pipeline/specificInsight.js +2 -6
  76. package/lib/insight/pipeline/visualize.js +0 -2
  77. package/lib/insight/types.d.ts +3 -3
  78. package/package.json +1 -1
  79. package/esm/insight/chart/generator/homogeneous.js +0 -70
  80. package/esm/insight/chart/strategy/augmentedMarks/homogeneous.js +0 -5
  81. package/esm/insight/chart/strategy/commonMarks/intervalMark.js +0 -14
  82. package/esm/insight/chart/strategy/commonMarks/textMark.js +0 -28
  83. package/lib/insight/chart/generator/homogeneous.d.ts +0 -3
  84. package/lib/insight/chart/generator/homogeneous.js +0 -75
  85. package/lib/insight/chart/strategy/augmentedMarks/homogeneous.d.ts +0 -3
  86. package/lib/insight/chart/strategy/augmentedMarks/homogeneous.js +0 -9
  87. package/lib/insight/chart/strategy/commonMarks/intervalMark.d.ts +0 -5
  88. package/lib/insight/chart/strategy/commonMarks/intervalMark.js +0 -18
  89. package/lib/insight/chart/strategy/commonMarks/textMark.d.ts +0 -5
  90. package/lib/insight/chart/strategy/commonMarks/textMark.js +0 -32
@@ -2,37 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.lineMarkStrategy = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var constants_1 = require("../../constants");
6
- var lineMarkStrategy = function (_a, _b) {
7
- var points = _a.points, x = _a.x, y = _a.y;
8
- var encode = _b.encode, style = _b.style, label = _b.label, tooltip = _b.tooltip;
9
- var common = {
10
- style: tslib_1.__assign({ lineDash: [2, 2], stroke: constants_1.INSIGHT_COLOR_PLATTE.highlight }, style),
11
- labels: label
12
- ? [
13
- {
14
- text: label,
15
- selector: 'last',
16
- position: 'right',
17
- style: {
18
- textBaseline: 'bottom',
19
- textAlign: 'end',
20
- dy: -24,
21
- },
22
- },
23
- ]
24
- : undefined,
25
- tooltip: tooltip,
26
- };
27
- if (points) {
28
- return tslib_1.__assign(tslib_1.__assign({}, common), { type: 'line', data: points, encode: tslib_1.__assign({ x: 'x', y: 'y' }, encode) });
29
- }
30
- if (x) {
31
- return tslib_1.__assign(tslib_1.__assign({}, common), { type: 'lineX', data: [x] });
32
- }
33
- if (y) {
34
- return tslib_1.__assign(tslib_1.__assign({}, common), { type: 'lineY', data: [y] });
35
- }
36
- return null;
37
- };
5
+ var lineMarkStrategy = function (data, config) { return (tslib_1.__assign({ type: 'line', data: data }, config)); };
38
6
  exports.lineMarkStrategy = lineMarkStrategy;
@@ -1,5 +1,6 @@
1
- import { PointMark } from '@antv/g2';
2
- import { PointPatternInfo } from '../../../types';
3
- import { PointMarkConfig } from '../../types';
1
+ import type { PointPatternInfo } from '../../../types';
2
+ import type { InsightPointMark } from '../../types';
4
3
  /** get mark for point patterns, the patterns should have same dimension and measure */
5
- export declare const pointMarkStrategy: (patterns: PointPatternInfo[], config: PointMarkConfig) => PointMark;
4
+ export declare const pointMarkStrategy: (patterns: PointPatternInfo[], config: Omit<InsightPointMark, "type" | "data"> & {
5
+ label?: (pattern: PointPatternInfo) => string;
6
+ }) => InsightPointMark;
@@ -5,17 +5,13 @@ var tslib_1 = require("tslib");
5
5
  var lodash_1 = require("lodash");
6
6
  /** get mark for point patterns, the patterns should have same dimension and measure */
7
7
  var pointMarkStrategy = function (patterns, config) {
8
- var data = [];
9
- patterns.forEach(function (_a) {
8
+ var label = config.label, markConfig = tslib_1.__rest(config, ["label"]);
9
+ var data = patterns
10
+ .filter(function (_a) {
10
11
  var x = _a.x, y = _a.y;
11
- if ((0, lodash_1.isNil)(x) || (0, lodash_1.isNil)(y))
12
- return;
13
- data.push({ x: x, y: y });
14
- });
15
- var pointMark = tslib_1.__assign({ type: 'point', data: data, encode: {
16
- x: 'x',
17
- y: 'y',
18
- } }, config);
19
- return pointMark;
12
+ return !(0, lodash_1.isNil)(x) && !(0, lodash_1.isNil)(y);
13
+ })
14
+ .map(function (pattern) { return (tslib_1.__assign({ x: pattern.x, y: pattern.y }, (label ? { label: label(pattern) } : {}))); });
15
+ return tslib_1.__assign({ type: 'point', data: data }, markConfig);
20
16
  };
21
17
  exports.pointMarkStrategy = pointMarkStrategy;
@@ -0,0 +1,2 @@
1
+ import type { InsightRuleYMark } from '../../types';
2
+ export declare const ruleYMarkStrategy: (y: number, config: Omit<InsightRuleYMark, 'type' | 'y'>) => InsightRuleYMark;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ruleYMarkStrategy = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var ruleYMarkStrategy = function (y, config) { return (tslib_1.__assign({ type: 'ruleY', y: y }, config)); };
6
+ exports.ruleYMarkStrategy = ruleYMarkStrategy;
@@ -1,3 +1,9 @@
1
- import type { G2Spec, Mark } from '@antv/g2';
2
- import type { InsightInfo, PatternInfo } from '../../types';
3
- export declare const viewSpecStrategy: (marks: Mark[], insight?: InsightInfo<PatternInfo>) => G2Spec;
1
+ import type { InsightInfo, InsightType, PatternInfo } from '../../types';
2
+ import type { InsightChartMark, InsightChartSpec } from '../types';
3
+ type ViewInsight = Pick<InsightInfo<PatternInfo>, 'dimensions' | 'measures'> & {
4
+ patterns: {
5
+ type: InsightType;
6
+ }[];
7
+ };
8
+ export declare const viewSpecStrategy: (marks: InsightChartMark[], insight: ViewInsight) => InsightChartSpec;
9
+ export {};
@@ -1,20 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.viewSpecStrategy = void 0;
4
- var tslib_1 = require("tslib");
5
4
  var viewSpecStrategy = function (marks, insight) {
6
- // majority insight pattern visualizes as 'pie', should not use y nice (G2 handle it as rescale y, the pie chart will be less than 100%)
7
- var isMajorityPattern = insight.patterns.map(function (pattern) { return pattern.type; }).includes('majority');
8
- var viewConfig = isMajorityPattern
9
- ? { scale: { y: { nice: false } } }
10
- : {
11
- scale: { y: { nice: true } },
5
+ var _a, _b, _c, _d, _e;
6
+ var validMarks = marks.filter(Boolean);
7
+ var insightType = ((_a = insight.patterns[0]) !== null && _a !== void 0 ? _a : {}).type;
8
+ if (insightType === 'majority') {
9
+ return { coordinate: 'polar', marks: validMarks };
10
+ }
11
+ if (insightType === 'correlation') {
12
+ return {
13
+ coordinate: 'cartesian',
14
+ x: { field: (_b = insight.measures[0]) === null || _b === void 0 ? void 0 : _b.fieldName, type: 'value' },
15
+ y: { field: (_c = insight.measures[1]) === null || _c === void 0 ? void 0 : _c.fieldName, type: 'value' },
16
+ marks: validMarks,
12
17
  };
13
- return tslib_1.__assign({ type: 'view', theme: 'dark', axis: {
14
- x: { labelAutoHide: true, labelAutoRotate: false, title: false },
15
- y: { title: false },
16
- }, interaction: {
17
- tooltip: { groupName: false },
18
- }, legend: false, children: marks }, viewConfig);
18
+ }
19
+ return {
20
+ coordinate: 'cartesian',
21
+ x: { field: (_d = insight.dimensions[0]) === null || _d === void 0 ? void 0 : _d.fieldName, type: 'category' },
22
+ y: { field: (_e = insight.measures[0]) === null || _e === void 0 ? void 0 : _e.fieldName, type: 'value' },
23
+ marks: validMarks,
24
+ };
19
25
  };
20
26
  exports.viewSpecStrategy = viewSpecStrategy;
@@ -1,60 +1,117 @@
1
- import type { AreaMark, IntervalMark, LineMark, Mark, PointMark, TextMark } from '@antv/g2';
2
- import type { Datum } from '../types';
3
- type LabelType = string | ((d: Datum) => string);
4
- export type TextMarkConfig = {
5
- label?: LabelType;
6
- style?: Mark['style'];
7
- formatter?: (value: number) => string;
8
- };
9
- export type PointMarkConfig = {
10
- style?: Mark['style'];
11
- tooltip?: Mark['tooltip'];
12
- };
13
- export type LineMarkData = {
14
- /** draw a vertical line at x value */
15
- x?: number;
16
- /** draw a horizontal line at y value */
17
- y?: number;
18
- /** draw a line using specific points */
19
- points?: {
20
- x: number;
21
- y: number;
1
+ /**
2
+ * Renderer-agnostic chart spec for insights.
3
+ *
4
+ * Strategies describe *what* to draw as a list of marks with semantic `role`s; renderers
5
+ * (e.g. `@formant/ava-react`, which compiles to ECharts) decide *how* it looks via a theme.
6
+ * No colors or renderer options live here, so a chart is restyled entirely by its theme.
7
+ */
8
+ export type InsightChartValue = string | number;
9
+ /** semantic role of a mark; themes map each role to colors/styles */
10
+ export type InsightMarkRole =
11
+ /** the data itself */
12
+ 'primary'
13
+ /** emphasized data points, e.g. change points */
14
+ | 'highlight'
15
+ /** anomalous data, e.g. category / time series outliers */
16
+ | 'outlier'
17
+ /** expected value of a time series */
18
+ | 'baseline'
19
+ /** expected range of a time series */
20
+ | 'band'
21
+ /** fitted regression line */
22
+ | 'trend'
23
+ /** reference line at the mean */
24
+ | 'mean';
25
+ export type InsightChartPoint = {
26
+ x: InsightChartValue;
27
+ y: number;
28
+ /** text shown next to the point */
29
+ label?: string;
30
+ };
31
+ type BaseMark = {
32
+ role: InsightMarkRole;
33
+ /** series name, shown in tooltips */
34
+ name?: string;
35
+ };
36
+ export type InsightLineMark = BaseMark & {
37
+ type: 'line';
38
+ data: InsightChartPoint[];
39
+ smooth?: boolean;
40
+ /** text shown at the end of the line */
41
+ label?: string;
42
+ };
43
+ export type InsightBarMark = BaseMark & {
44
+ type: 'bar';
45
+ data: InsightChartPoint[];
46
+ };
47
+ export type InsightPointMark = BaseMark & {
48
+ type: 'point';
49
+ data: InsightChartPoint[];
50
+ };
51
+ /** filled range between y0 and y1 */
52
+ export type InsightAreaMark = BaseMark & {
53
+ type: 'area';
54
+ data: {
55
+ x: InsightChartValue;
56
+ y0: number;
57
+ y1: number;
22
58
  }[];
59
+ smooth?: boolean;
60
+ };
61
+ /** full-span horizontal reference line */
62
+ export type InsightRuleYMark = BaseMark & {
63
+ type: 'ruleY';
64
+ y: number;
65
+ label?: string;
23
66
  };
24
- export type LineMarkConfig = {
25
- encode?: Mark['encode'];
67
+ /** full-span vertical reference line */
68
+ export type InsightRuleXMark = BaseMark & {
69
+ type: 'ruleX';
70
+ x: InsightChartValue;
26
71
  label?: string;
27
- style?: Mark['style'];
28
- tooltip?: Mark['tooltip'];
29
72
  };
30
- export type AreaMarkData = {
31
- x: number;
32
- y: [number, number];
33
- }[];
34
- export type AreaMarkConfig = {
35
- encode?: Mark['encode'];
36
- style?: Mark['style'];
37
- tooltip?: Mark['tooltip'];
73
+ /** pie / donut slices; only valid with `coordinate: 'polar'` */
74
+ export type InsightArcMark = BaseMark & {
75
+ type: 'arc';
76
+ data: {
77
+ name: string;
78
+ value: number;
79
+ }[];
80
+ /** radii as fractions of the available radius */
81
+ innerRadius?: number;
82
+ outerRadius?: number;
83
+ };
84
+ export type InsightChartMark = InsightLineMark | InsightBarMark | InsightPointMark | InsightAreaMark | InsightRuleYMark | InsightRuleXMark | InsightArcMark;
85
+ export type InsightChartAxis = {
86
+ /** source field name, used as axis name in tooltips */
87
+ field?: string;
88
+ /** `category` for dimensions, `value` for measures */
89
+ type: 'category' | 'value';
38
90
  };
39
- export type IntervalMarkConfig = {
40
- style?: Mark['style'];
91
+ export type InsightChartSpec = {
92
+ /** `cartesian`: x/y axes; `polar`: pie (arc marks only) */
93
+ coordinate: 'cartesian' | 'polar';
94
+ x?: InsightChartAxis;
95
+ y?: InsightChartAxis;
96
+ /** drawn in order: later marks paint on top */
97
+ marks: InsightChartMark[];
41
98
  };
42
99
  export type ChangePointMark = {
43
- changePoint: (PointMark | TextMark)[];
100
+ changePoint: InsightPointMark[];
44
101
  };
45
102
  export type TrendMark = {
46
- trendLine: LineMark[];
103
+ trendLine: InsightLineMark[];
47
104
  };
48
105
  export type TimeSeriesOutlierMark = {
49
- trendLine: LineMark[];
50
- anomalyArea: AreaMark[];
51
- outliers?: PointMark[];
106
+ trendLine: InsightLineMark[];
107
+ anomalyArea: InsightAreaMark[];
108
+ outliers?: InsightPointMark[];
52
109
  };
53
110
  export type CategoryOutlierMark = {
54
- categoryOutlier: (IntervalMark | TextMark)[];
111
+ categoryOutlier: InsightBarMark[];
55
112
  };
56
113
  export type LowVarianceMark = {
57
- meanLine: LineMark[];
114
+ meanLine: InsightRuleYMark[];
58
115
  };
59
116
  export type AugmentedMarks = ChangePointMark[] | TrendMark[] | TimeSeriesOutlierMark[] | CategoryOutlierMark[] | LowVarianceMark[];
60
117
  export {};
@@ -1,2 +1,9 @@
1
1
  "use strict";
2
+ /**
3
+ * Renderer-agnostic chart spec for insights.
4
+ *
5
+ * Strategies describe *what* to draw as a list of marks with semantic `role`s; renderers
6
+ * (e.g. `@formant/ava-react`, which compiles to ECharts) decide *how* it looks via a theme.
7
+ * No colors or renderer options live here, so a chart is restyled entirely by its theme.
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,2 @@
1
- import { Mark } from '@antv/g2';
2
- import { AugmentedMarks } from './types';
3
- export declare const augmentedMarks2Marks: (augmentedMarks: AugmentedMarks) => Mark[];
1
+ import { AugmentedMarks, InsightChartMark } from './types';
2
+ export declare const augmentedMarks2Marks: (augmentedMarks: AugmentedMarks) => InsightChartMark[];
@@ -3,4 +3,4 @@ export { insightPatternsExtractor } from './insights';
3
3
  export { generateInsightVisualizationSpec } from './pipeline/visualize';
4
4
  export * from './types';
5
5
  export { getSpecificInsight } from './pipeline/specificInsight';
6
- export type { AugmentedMarks } from './chart';
6
+ export type { AugmentedMarks, InsightChartSpec, InsightChartMark, InsightChartAxis, InsightChartPoint, InsightChartValue, InsightMarkRole, InsightLineMark, InsightBarMark, InsightPointMark, InsightAreaMark, InsightRuleXMark, InsightRuleYMark, InsightArcMark, } from './chart';
@@ -59,7 +59,7 @@ var CategoryOutlierNarrativeStrategy = /** @class */ (function (_super) {
59
59
  template: '${.x}',
60
60
  separator: (0, helpers_1.getDefaultSeparator)('zh-CN'),
61
61
  variableMetaMap: variableMetaMap,
62
- useVariable: 'paragraph',
62
+ useVariable: 'patterns',
63
63
  },
64
64
  ],
65
65
  'en-US': [
@@ -68,7 +68,7 @@ var CategoryOutlierNarrativeStrategy = /** @class */ (function (_super) {
68
68
  template: '${.x}',
69
69
  separator: (0, helpers_1.getDefaultSeparator)('en-US'),
70
70
  variableMetaMap: variableMetaMap,
71
- useVariable: 'paragraph',
71
+ useVariable: 'patterns',
72
72
  },
73
73
  ],
74
74
  };
@@ -52,7 +52,7 @@ var TrendNarrativeStrategy = /** @class */ (function (_super) {
52
52
  ],
53
53
  'en-US': [
54
54
  {
55
- template: 'There is a signifcant ${trend} trend for ${measure} during ${dateRange} with a slope of ${slope}X.',
55
+ template: 'There is a significant ${trend} trend for ${measure} during ${dateRange} with a slope of ${slope}X.',
56
56
  variableMetaMap: variableMetaMap,
57
57
  },
58
58
  ],
@@ -1,9 +1,8 @@
1
- import { G2Spec } from '@antv/g2';
2
- import { AugmentedMarks } from '../chart';
1
+ import { AugmentedMarks, InsightChartSpec } from '../chart';
3
2
  import { InsightInfo, InsightType, PatternInfo, PatternInfo2InsightInfoProps, SpecificInsightProps, SpecificInsightResult } from '../types';
4
3
  export declare const patternInfo2InsightInfo: (props: PatternInfo2InsightInfoProps) => InsightInfo<PatternInfo>;
5
4
  export declare const getAnnotationSpec: (insightInfo: InsightInfo<PatternInfo>) => AugmentedMarks;
6
- export declare const getChartSpecWithoutAugmentedMarks: (insightInfo: InsightInfo<PatternInfo>, insightType: InsightType) => G2Spec;
5
+ export declare const getChartSpecWithoutAugmentedMarks: (insightInfo: InsightInfo<PatternInfo>, insightType: InsightType) => InsightChartSpec;
7
6
  export declare const filterValidInsightInfoForAnnotationSpec: ({ patternInfos, insightType, }: {
8
7
  patternInfos: PatternInfo[];
9
8
  insightType: InsightType;
@@ -33,12 +33,8 @@ var getAnnotationSpec = function (insightInfo) {
33
33
  };
34
34
  exports.getAnnotationSpec = getAnnotationSpec;
35
35
  var getChartSpecWithoutAugmentedMarks = function (insightInfo, insightType) {
36
- var chartMark = (0, strategy_1.insight2ChartStrategy)(tslib_1.__assign(tslib_1.__assign({}, insightInfo), ((0, lodash_1.size)(insightInfo.patterns) === 0
37
- ? {
38
- patterns: [{ type: insightType }],
39
- }
40
- : {})));
41
- return (0, strategy_1.viewSpecStrategy)([chartMark], insightInfo);
36
+ var chartInsight = tslib_1.__assign(tslib_1.__assign({}, insightInfo), ((0, lodash_1.size)(insightInfo.patterns) === 0 ? { patterns: [{ type: insightType }] } : {}));
37
+ return (0, strategy_1.viewSpecStrategy)([(0, strategy_1.insight2ChartStrategy)(chartInsight)], chartInsight);
42
38
  };
43
39
  exports.getChartSpecWithoutAugmentedMarks = getChartSpecWithoutAugmentedMarks;
44
40
  var filterValidInsightInfoForAnnotationSpec = function (_a) {
@@ -34,10 +34,8 @@ var generateHomogeneousInsightVisualizationSpec = function (insight, visualizati
34
34
  var schemas = [];
35
35
  patterns.forEach(function (pattern) {
36
36
  var insightType = pattern.insightType;
37
- var chartSpec = {};
38
37
  schemas.push({
39
38
  patternType: insightType,
40
- chartSpec: chartSpec,
41
39
  narrativeSpec: (0, narrative_1.default)(tslib_1.__assign(tslib_1.__assign({}, (0, lodash_1.omit)(insight, ['patterns'])), pattern), visualizationOptions),
42
40
  });
43
41
  });
@@ -1,7 +1,6 @@
1
1
  import { PCorrTestParameter } from '../data/statistics/types';
2
2
  import { PATTERN_TYPES, HOMOGENEOUS_PATTERN_TYPES } from './constant';
3
- import { AugmentedMarks } from './chart/types';
4
- import type { G2Spec } from '@antv/g2';
3
+ import { AugmentedMarks, InsightChartSpec } from './chart/types';
5
4
  import type { ParagraphSpec } from '../ntv/types';
6
5
  import type { NumberFieldInfo, DateFieldInfo, StringFieldInfo, Extra } from '../data/types';
7
6
  export type Datum = Record<string, string | number>;
@@ -50,7 +49,8 @@ export type PatternInfo = CategoryOutlierInfo | TimeSeriesOutlierInfo | LowVaria
50
49
  /** explanation and visualization for insight */
51
50
  export interface InsightVisualizationSpec {
52
51
  patternType: InsightType;
53
- chartSpec: G2Spec;
52
+ /** absent for homogeneous insights, which have no chart */
53
+ chartSpec?: InsightChartSpec;
54
54
  /** augmented marks */
55
55
  annotationSpec?: AugmentedMarks;
56
56
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formant/ava",
3
- "version": "3.4.21-formant",
3
+ "version": "3.5.0-formant",
4
4
  "description": "A framework for automated visual analytics.",
5
5
  "author": {
6
6
  "name": "formant",
@@ -1,70 +0,0 @@
1
- import { __assign, __read, __spreadArray } from "tslib";
2
- import { INSIGHT_COLOR_PLATTE } from '../constants';
3
- export function generateHomogeneousInsightAugmentedMarks(pattern) {
4
- var annotations = [];
5
- var insightType = pattern.insightType, childPatterns = pattern.childPatterns;
6
- if (['change_point', 'time_series_outlier'].includes(insightType)) {
7
- var x_1 = childPatterns[0].x;
8
- var text = insightType === 'change_point' ? 'Abrupt Change' : 'Outlier';
9
- var color_1 = insightType === 'change_point' ? INSIGHT_COLOR_PLATTE.highlight : INSIGHT_COLOR_PLATTE.outlier;
10
- // draw line
11
- var line = {
12
- type: 'line',
13
- start: [x_1, 'min'],
14
- end: [x_1, 'max'],
15
- text: {
16
- content: text,
17
- position: 'left',
18
- offsetY: 15,
19
- offsetX: 5,
20
- rotate: 0,
21
- autoRotate: false,
22
- style: {
23
- textAlign: 'left',
24
- },
25
- },
26
- };
27
- annotations.push(line);
28
- // draw circle
29
- var circles = childPatterns.map(function (pattern) {
30
- var y = pattern.y;
31
- return {
32
- type: 'dataMarker',
33
- position: [x_1, y],
34
- point: {
35
- style: {
36
- fill: '#fff',
37
- stroke: color_1,
38
- },
39
- },
40
- line: {
41
- length: 20,
42
- },
43
- autoAdjust: false,
44
- };
45
- });
46
- annotations.push.apply(annotations, __spreadArray([], __read(circles), false));
47
- }
48
- return annotations;
49
- }
50
- export function generateHomogeneousInsightChartSpec(insight, pattern) {
51
- var dimensions = insight.dimensions, measures = insight.measures;
52
- var plotSchema;
53
- if (measures.length > 1) {
54
- plotSchema = {
55
- xField: dimensions[0],
56
- yField: 'value',
57
- seriesField: 'measureName',
58
- };
59
- }
60
- else {
61
- plotSchema = {
62
- xField: dimensions[1],
63
- yField: measures[0].fieldName,
64
- seriesField: dimensions[0],
65
- };
66
- }
67
- var annotationConfig = generateHomogeneousInsightAugmentedMarks(pattern);
68
- var chartSchema = __assign(__assign({}, plotSchema), { annotations: annotationConfig });
69
- return chartSchema;
70
- }
@@ -1,5 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- export var homogeneousStrategy = function (_insight) {
3
- // colorField: string
4
- return {};
5
- };
@@ -1,14 +0,0 @@
1
- import { __assign } from "tslib";
2
- import { INSIGHT_COLOR_PLATTE } from '../../constants';
3
- /** get mark for point patterns, the patterns should have same dimension and measure */
4
- export var intervalMarkStrategy = function (patterns, config) {
5
- var data = patterns.map(function (_a) {
6
- var x = _a.x, y = _a.y;
7
- return ({ x: x, y: y });
8
- });
9
- var intervalMark = __assign(__assign({ type: 'interval', data: data, encode: {
10
- x: 'x',
11
- y: 'y',
12
- } }, config), { style: __assign(__assign({}, config === null || config === void 0 ? void 0 : config.style), { fill: INSIGHT_COLOR_PLATTE.outlier }) });
13
- return intervalMark;
14
- };
@@ -1,28 +0,0 @@
1
- import { __assign } from "tslib";
2
- import { isFunction } from 'lodash';
3
- import { TEXT_STYLE } from '../../constants';
4
- /** get mark for point patterns, the patterns should have same dimension and measure */
5
- export var textMarkStrategy = function (patterns, textConfig) {
6
- var _a = textConfig || {}, style = _a.style, label = _a.label, formatter = _a.formatter;
7
- var _b = patterns[0], measure = _b.measure, dimension = _b.dimension;
8
- var data = patterns.map(function (pattern) {
9
- var _a;
10
- var customLabel = isFunction(label) ? label(pattern) : label;
11
- var value = isFunction(formatter) ? formatter(pattern.y) : pattern.y;
12
- return _a = {},
13
- _a[dimension] = pattern.x,
14
- _a[measure] = pattern.y,
15
- _a.label = customLabel !== null && customLabel !== void 0 ? customLabel : "".concat(pattern.x, "\n").concat(value),
16
- _a;
17
- });
18
- return {
19
- type: 'text',
20
- data: data,
21
- encode: {
22
- x: dimension,
23
- y: measure,
24
- text: 'label',
25
- },
26
- style: __assign(__assign({}, TEXT_STYLE), style),
27
- };
28
- };
@@ -1,3 +0,0 @@
1
- import { HomogeneousPatternInfo, InsightInfo, InsightVisualizationSpec } from '../../types';
2
- export declare function generateHomogeneousInsightAugmentedMarks(pattern: HomogeneousPatternInfo): any[];
3
- export declare function generateHomogeneousInsightChartSpec(insight: InsightInfo<HomogeneousPatternInfo>, pattern: HomogeneousPatternInfo): InsightVisualizationSpec[];
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateHomogeneousInsightChartSpec = exports.generateHomogeneousInsightAugmentedMarks = void 0;
4
- var tslib_1 = require("tslib");
5
- var constants_1 = require("../constants");
6
- function generateHomogeneousInsightAugmentedMarks(pattern) {
7
- var annotations = [];
8
- var insightType = pattern.insightType, childPatterns = pattern.childPatterns;
9
- if (['change_point', 'time_series_outlier'].includes(insightType)) {
10
- var x_1 = childPatterns[0].x;
11
- var text = insightType === 'change_point' ? 'Abrupt Change' : 'Outlier';
12
- var color_1 = insightType === 'change_point' ? constants_1.INSIGHT_COLOR_PLATTE.highlight : constants_1.INSIGHT_COLOR_PLATTE.outlier;
13
- // draw line
14
- var line = {
15
- type: 'line',
16
- start: [x_1, 'min'],
17
- end: [x_1, 'max'],
18
- text: {
19
- content: text,
20
- position: 'left',
21
- offsetY: 15,
22
- offsetX: 5,
23
- rotate: 0,
24
- autoRotate: false,
25
- style: {
26
- textAlign: 'left',
27
- },
28
- },
29
- };
30
- annotations.push(line);
31
- // draw circle
32
- var circles = childPatterns.map(function (pattern) {
33
- var y = pattern.y;
34
- return {
35
- type: 'dataMarker',
36
- position: [x_1, y],
37
- point: {
38
- style: {
39
- fill: '#fff',
40
- stroke: color_1,
41
- },
42
- },
43
- line: {
44
- length: 20,
45
- },
46
- autoAdjust: false,
47
- };
48
- });
49
- annotations.push.apply(annotations, tslib_1.__spreadArray([], tslib_1.__read(circles), false));
50
- }
51
- return annotations;
52
- }
53
- exports.generateHomogeneousInsightAugmentedMarks = generateHomogeneousInsightAugmentedMarks;
54
- function generateHomogeneousInsightChartSpec(insight, pattern) {
55
- var dimensions = insight.dimensions, measures = insight.measures;
56
- var plotSchema;
57
- if (measures.length > 1) {
58
- plotSchema = {
59
- xField: dimensions[0],
60
- yField: 'value',
61
- seriesField: 'measureName',
62
- };
63
- }
64
- else {
65
- plotSchema = {
66
- xField: dimensions[1],
67
- yField: measures[0].fieldName,
68
- seriesField: dimensions[0],
69
- };
70
- }
71
- var annotationConfig = generateHomogeneousInsightAugmentedMarks(pattern);
72
- var chartSchema = tslib_1.__assign(tslib_1.__assign({}, plotSchema), { annotations: annotationConfig });
73
- return chartSchema;
74
- }
75
- exports.generateHomogeneousInsightChartSpec = generateHomogeneousInsightChartSpec;
@@ -1,3 +0,0 @@
1
- import { G2Spec } from '@antv/g2';
2
- import { HomogeneousPatternInfo, InsightInfo } from '../../../types';
3
- export declare const homogeneousStrategy: (_insight: InsightInfo<HomogeneousPatternInfo>) => G2Spec;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.homogeneousStrategy = void 0;
4
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
- var homogeneousStrategy = function (_insight) {
6
- // colorField: string
7
- return {};
8
- };
9
- exports.homogeneousStrategy = homogeneousStrategy;