@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
@@ -1,26 +1,5 @@
1
- export var INSIGHT_COLOR_PLATTE = {
2
- highlight: '#f89973',
3
- outlier: '#ea719d',
4
- font: '#bac4e2',
5
- defaultPointColor: '#fff',
6
- };
7
- export var BOLD_FONT_WEIGHT = 500;
8
- export var TEXT_STYLE = {
9
- textAlign: 'center',
10
- fill: INSIGHT_COLOR_PLATTE.font,
11
- fontFamily: 'Moderat',
12
- opacity: 0.85,
13
- };
14
- export var ChartTypeMap = {
15
- category_outlier: 'column_chart',
16
- trend: 'line_chart',
17
- change_point: 'line_chart',
18
- time_series_outlier: 'line_chart',
19
- majority: 'pie_chart',
20
- low_variance: 'column_chart',
21
- correlation: 'scatter_plot',
22
- };
23
- export var PIE_RADIUS_STYLE = {
1
+ /** pie radii as fractions of the available radius */
2
+ export var PIE_RADIUS = {
24
3
  innerRadius: 0.25,
25
4
  outerRadius: 0.8,
26
5
  };
@@ -1,2 +1 @@
1
- export * from './homogeneous';
2
1
  export * from './insights';
@@ -1,6 +1,6 @@
1
1
  import { categoryOutlierStrategy, changePointStrategy, lowVarianceStrategy, majorityStrategy, correlationStrategy, timeSeriesOutlierStrategy, trendStrategy, viewSpecStrategy, } from '../strategy';
2
2
  export function generateInsightChartSpec(insight) {
3
- var _a;
3
+ var _a, _b;
4
4
  var insightType = insight.patterns[0].type;
5
5
  var insightType2Strategy = {
6
6
  trend: trendStrategy,
@@ -11,6 +11,6 @@ export function generateInsightChartSpec(insight) {
11
11
  majority: majorityStrategy,
12
12
  correlation: correlationStrategy,
13
13
  };
14
- var marks = (_a = insightType2Strategy[insightType]) === null || _a === void 0 ? void 0 : _a.call(insightType2Strategy, insight);
14
+ var marks = (_b = (_a = insightType2Strategy[insightType]) === null || _a === void 0 ? void 0 : _a.call(insightType2Strategy, insight)) !== null && _b !== void 0 ? _b : [];
15
15
  return viewSpecStrategy(marks, insight);
16
16
  }
@@ -1,4 +1,3 @@
1
- export * from './generator/homogeneous';
2
1
  export * from './generator/insights';
3
2
  export * from './strategy/augmentedMarks';
4
3
  export * from './types';
@@ -1,24 +1,18 @@
1
1
  import { __read, __spreadArray } from "tslib";
2
2
  import { size } from 'lodash';
3
3
  import { insight2ChartStrategy } from '../chart';
4
- import { intervalMarkStrategy } from '../commonMarks';
4
+ import { barMarkStrategy } from '../commonMarks';
5
5
  import { augmentedMarks2Marks } from '../../utils';
6
6
  export var categoryOutlierAugmentedMarksStrategy = function (insight) {
7
7
  var patterns = insight.patterns;
8
8
  if (!size(patterns))
9
9
  return [];
10
- var categoryOutlierMarks = [];
11
- patterns.forEach(function (pattern) {
12
- var rectMark = intervalMarkStrategy([pattern]);
13
- categoryOutlierMarks.push({
14
- categoryOutlier: [rectMark],
15
- });
16
- });
17
- return categoryOutlierMarks;
10
+ return patterns.map(function (pattern) { return ({
11
+ categoryOutlier: [barMarkStrategy([pattern], { role: 'outlier', name: 'outlier' })],
12
+ }); });
18
13
  };
19
14
  export var categoryOutlierStrategy = function (insight) {
20
15
  var chart = insight2ChartStrategy(insight);
21
- var categoryOutlierMarks = categoryOutlierAugmentedMarksStrategy(insight);
22
- var marks = augmentedMarks2Marks(categoryOutlierMarks);
16
+ var marks = augmentedMarks2Marks(categoryOutlierAugmentedMarksStrategy(insight));
23
17
  return __spreadArray([chart], __read(marks), false);
24
18
  };
@@ -1,42 +1,26 @@
1
1
  import { __read, __spreadArray } from "tslib";
2
2
  import { size } from 'lodash';
3
- import { INSIGHT_COLOR_PLATTE } from '../../constants';
4
3
  import { dataFormat } from '../../../../utils';
5
- import { pointMarkStrategy } from '../commonMarks/pointMark';
6
- import { textMarkStrategy } from '../commonMarks/textMark';
4
+ import { pointMarkStrategy } from '../commonMarks';
7
5
  import { insight2ChartStrategy } from '../chart';
8
6
  import { augmentedMarks2Marks } from '../../utils';
9
7
  export var changePointAugmentedMarksStrategy = function (insight) {
10
8
  var patterns = insight.patterns;
11
- var color = INSIGHT_COLOR_PLATTE.highlight;
12
9
  if (!size(patterns))
13
10
  return [];
14
11
  var measure = patterns[0].measure;
15
- var changePointMarks = [];
16
- patterns.forEach(function (pattern) {
17
- var pointMark = pointMarkStrategy([pattern], { style: { fill: color } });
18
- var textMark = textMarkStrategy([pattern], {
19
- formatter: dataFormat,
20
- label: function (pt) { return "".concat(pt.x, ", ").concat(measure, ": ").concat(pt.y); },
21
- style: {
22
- dy: -20,
23
- background: true,
24
- backgroundRadius: 2,
25
- connector: true,
26
- startMarker: true,
27
- startMarkerFill: '#1c1e2d',
28
- startMarkerFillOpacity: 0.65,
29
- },
30
- });
31
- changePointMarks.push({
32
- changePoint: [pointMark, textMark],
33
- });
34
- });
35
- return changePointMarks;
12
+ return patterns.map(function (pattern) { return ({
13
+ changePoint: [
14
+ pointMarkStrategy([pattern], {
15
+ role: 'highlight',
16
+ name: 'change point',
17
+ label: function (pt) { return "".concat(pt.x, ", ").concat(measure, ": ").concat(dataFormat(pt.y)); },
18
+ }),
19
+ ],
20
+ }); });
36
21
  };
37
22
  export var changePointStrategy = function (insight) {
38
23
  var chart = insight2ChartStrategy(insight);
39
- var changePointMarks = changePointAugmentedMarksStrategy(insight);
40
- var marks = augmentedMarks2Marks(changePointMarks);
24
+ var marks = augmentedMarks2Marks(changePointAugmentedMarksStrategy(insight));
41
25
  return __spreadArray([chart], __read(marks), false);
42
26
  };
@@ -1,6 +1,5 @@
1
1
  import { insight2ChartStrategy } from '../chart';
2
2
  export var correlationStrategy = function (insight) {
3
3
  // todo add correlation regression line and value
4
- var chartMark = insight2ChartStrategy(insight);
5
- return [chartMark];
4
+ return [insight2ChartStrategy(insight)];
6
5
  };
@@ -4,5 +4,4 @@ export { categoryOutlierStrategy, categoryOutlierAugmentedMarksStrategy } from '
4
4
  export { changePointStrategy, changePointAugmentedMarksStrategy } from './changePoint';
5
5
  export { majorityStrategy } from './majority';
6
6
  export { correlationStrategy } from './correlation';
7
- export { homogeneousStrategy } from './homogeneous';
8
7
  export { timeSeriesOutlierStrategy, timeSeriesOutlierStrategyAugmentedMarksStrategy } from './timeSeriesOutlier';
@@ -1,23 +1,18 @@
1
1
  import { __read, __spreadArray } from "tslib";
2
- import { lineMarkStrategy } from '../commonMarks';
2
+ import { ruleYMarkStrategy } from '../commonMarks';
3
3
  import { insight2ChartStrategy } from '../chart';
4
4
  import { augmentedMarks2Marks } from '../../utils';
5
5
  import { dataFormat } from '../../../../utils';
6
6
  export var lowVarianceAugmentedMarkStrategy = function (insight) {
7
- var patterns = insight.patterns;
8
- var marks = [];
9
- patterns.forEach(function (pattern) {
10
- var mean = pattern.mean;
11
- var meanLineMark = lineMarkStrategy({ y: mean }, { label: "mean: ".concat(dataFormat(mean)) });
12
- marks.push({
13
- meanLine: [meanLineMark],
7
+ return insight.patterns.map(function (_a) {
8
+ var mean = _a.mean;
9
+ return ({
10
+ meanLine: [ruleYMarkStrategy(mean, { role: 'mean', name: 'mean', label: "mean: ".concat(dataFormat(mean)) })],
14
11
  });
15
12
  });
16
- return marks;
17
13
  };
18
14
  export var lowVarianceStrategy = function (insight) {
19
15
  var chartMark = insight2ChartStrategy(insight);
20
- var lowVarianceMarks = lowVarianceAugmentedMarkStrategy(insight);
21
- var marks = augmentedMarks2Marks(lowVarianceMarks);
16
+ var marks = augmentedMarks2Marks(lowVarianceAugmentedMarkStrategy(insight));
22
17
  return __spreadArray([chartMark], __read(marks), false);
23
18
  };
@@ -1,5 +1,4 @@
1
1
  import { insight2ChartStrategy } from '../chart';
2
2
  export var majorityStrategy = function (insight) {
3
- var chartMark = insight2ChartStrategy(insight);
4
- return [chartMark];
3
+ return [insight2ChartStrategy(insight)];
5
4
  };
@@ -1,82 +1,25 @@
1
1
  import { __read, __spreadArray } from "tslib";
2
2
  import { insight2ChartStrategy } from '../chart';
3
3
  import { areaMarkStrategy, lineMarkStrategy, pointMarkStrategy } from '../commonMarks';
4
- var BASELINE = 'baseline';
5
- var INTERVAL = 'interval';
6
- var OUTLIER = 'outlier';
7
4
  export var timeSeriesOutlierStrategyAugmentedMarksStrategy = function (insight) {
8
5
  var chartData = insight.data, _a = __read(insight.dimensions, 1), dimensionName = _a[0].fieldName, patterns = insight.patterns;
9
6
  var _b = patterns[0], baselines = _b.baselines, thresholds = _b.thresholds;
10
- var data = chartData.map(function (datum, index) {
11
- var baseline = baselines[index];
12
- var interval = [baseline - Math.abs(thresholds[0]), baseline + thresholds[1]];
13
- return {
14
- baseline: {
15
- x: datum[dimensionName],
16
- y: baseline,
17
- },
18
- interval: {
19
- x: datum[dimensionName],
20
- y: interval,
21
- },
22
- };
23
- });
24
- var intervalData = data.map(function (datum) { return datum[INTERVAL]; });
25
- var intervalMark = areaMarkStrategy(intervalData, {
26
- encode: {
27
- shape: 'smooth',
28
- },
29
- style: {
30
- fillOpacity: 0.3,
31
- fill: '#ffd8b8',
32
- },
33
- tooltip: {
34
- title: '',
35
- items: [
36
- function (_d, i, _data, column) { return ({
37
- name: INTERVAL,
38
- value: "".concat(column.y.value[i], "-").concat(column.y1.value[i]),
39
- color: '#ffd8b8',
40
- }); },
41
- ],
42
- },
43
- });
44
- var baselineData = data.map(function (datum) { return datum[BASELINE]; });
45
- var baselineMark = lineMarkStrategy({ points: baselineData }, {
46
- encode: {
47
- shape: 'smooth',
48
- },
49
- style: {
50
- lineWidth: 1,
51
- stroke: '#ffa45c',
52
- lineDash: undefined,
53
- },
54
- tooltip: {
55
- title: '',
56
- items: [{ name: BASELINE, channel: 'y' }],
57
- },
58
- });
59
- var outlierMark = pointMarkStrategy(patterns, {
60
- style: {
61
- fill: '#f4664a',
62
- stroke: '#f4664a',
63
- },
64
- tooltip: {
65
- title: '',
66
- items: [{ name: OUTLIER, channel: 'y' }],
67
- },
68
- });
7
+ var intervalData = chartData.map(function (datum, index) { return ({
8
+ x: datum[dimensionName],
9
+ y0: baselines[index] - Math.abs(thresholds[0]),
10
+ y1: baselines[index] + thresholds[1],
11
+ }); });
12
+ var baselineData = chartData.map(function (datum, index) { return ({ x: datum[dimensionName], y: baselines[index] }); });
69
13
  return [
70
14
  {
71
- trendLine: [baselineMark],
72
- anomalyArea: [intervalMark],
73
- outliers: [outlierMark],
15
+ trendLine: [lineMarkStrategy(baselineData, { role: 'baseline', name: 'baseline', smooth: true })],
16
+ anomalyArea: [areaMarkStrategy(intervalData, { role: 'band', name: 'interval', smooth: true })],
17
+ outliers: [pointMarkStrategy(patterns, { role: 'outlier', name: 'outlier' })],
74
18
  },
75
19
  ];
76
20
  };
77
21
  export var timeSeriesOutlierStrategy = function (insight) {
78
- // Should to support marks free combination
79
22
  var chartMark = insight2ChartStrategy(insight);
80
- var _a = timeSeriesOutlierStrategyAugmentedMarksStrategy(insight)[0] || {}, _b = _a.trendLine, trendLine = _b === void 0 ? [] : _b, _c = _a.anomalyArea, anomalyArea = _c === void 0 ? [] : _c, _e = _a.outliers, outliers = _e === void 0 ? [] : _e;
23
+ var _a = timeSeriesOutlierStrategyAugmentedMarksStrategy(insight)[0] || {}, _b = _a.trendLine, trendLine = _b === void 0 ? [] : _b, _c = _a.anomalyArea, anomalyArea = _c === void 0 ? [] : _c, _d = _a.outliers, outliers = _d === void 0 ? [] : _d;
81
24
  return __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(anomalyArea), false), __read(trendLine), false), [chartMark], false), __read(outliers), false);
82
25
  };
@@ -4,17 +4,17 @@ import { insight2ChartStrategy } from '../chart';
4
4
  import { dataFormat } from '../../../../utils';
5
5
  export var trendAugmentedMarksStrategy = function (insight) {
6
6
  var chartData = insight.data, _a = __read(insight.dimensions, 1), dimensionName = _a[0].fieldName, patterns = insight.patterns;
7
- var points = chartData.map(function (datum, index) {
8
- var points = patterns[0].regression.points;
9
- var point = points[index];
10
- return [datum[dimensionName], point];
11
- });
12
- var _b = __read(patterns[0].regression.equation, 2), m = _b[0], c = _b[1];
13
- var lineData = points.map(function (point) { return ({ x: point[0], y: point[1] }); });
14
- var regressionLineMark = lineMarkStrategy({ points: lineData }, { label: "y=".concat(dataFormat(m), "x").concat(c < 0 ? '' : '+').concat(dataFormat(c)) });
7
+ var _b = patterns[0].regression, points = _b.points, _c = __read(_b.equation, 2), m = _c[0], c = _c[1];
8
+ var lineData = chartData.map(function (datum, index) { return ({ x: datum[dimensionName], y: points[index] }); });
15
9
  return [
16
10
  {
17
- trendLine: [regressionLineMark],
11
+ trendLine: [
12
+ lineMarkStrategy(lineData, {
13
+ role: 'trend',
14
+ name: 'trend',
15
+ label: "y=".concat(dataFormat(m), "x").concat(c < 0 ? '' : '+').concat(dataFormat(c)),
16
+ }),
17
+ ],
18
18
  },
19
19
  ];
20
20
  };
@@ -1,45 +1,34 @@
1
1
  import { __assign } from "tslib";
2
- import { PIE_RADIUS_STYLE } from '../constants';
2
+ import { PIE_RADIUS } from '../constants';
3
+ /** the mark that draws the insight data itself */
3
4
  export var insight2ChartStrategy = function (insight) {
4
- var _a, _b;
5
+ var _a, _b, _c;
5
6
  var data = insight.data, patterns = insight.patterns, dimensions = insight.dimensions, measures = insight.measures;
6
7
  var insightType = patterns[0].type;
7
- var commonSpec = {
8
- data: data,
9
- encode: {
10
- x: dimensions[0].fieldName,
11
- y: measures[0].fieldName,
12
- },
13
- };
8
+ var dimension = (_a = dimensions[0]) === null || _a === void 0 ? void 0 : _a.fieldName;
9
+ var measure = (_b = measures[0]) === null || _b === void 0 ? void 0 : _b.fieldName;
10
+ var points = function () { return data.map(function (datum) { return ({ x: datum[dimension], y: Number(datum[measure]) }); }); };
14
11
  // pie
15
12
  if (insightType === 'majority') {
16
- return __assign(__assign({}, commonSpec), { type: 'interval', encode: {
17
- color: dimensions[0].fieldName,
18
- y: measures[0].fieldName,
19
- }, transform: [{ type: 'stackY' }], coordinate: {
20
- type: 'theta',
21
- innerRadius: PIE_RADIUS_STYLE.innerRadius,
22
- outerRadius: PIE_RADIUS_STYLE.outerRadius,
23
- }, tooltip: {
24
- items: [{ field: dimensions[0].fieldName }, { field: measures[0].fieldName }],
25
- } });
13
+ return __assign({ type: 'arc', role: 'primary', name: measure, data: data.map(function (datum) { return ({ name: String(datum[dimension]), value: Number(datum[measure]) }); }) }, PIE_RADIUS);
26
14
  }
27
15
  // line
28
16
  if (insightType === 'trend' || insightType === 'time_series_outlier' || insightType === 'change_point') {
29
- return __assign(__assign({}, commonSpec), { type: 'line', style: {
30
- lineWidth: 2,
31
- } });
17
+ return { type: 'line', role: 'primary', name: measure, data: points() };
32
18
  }
33
19
  // bar
34
20
  if (insightType === 'category_outlier' || insightType === 'low_variance') {
35
- return __assign(__assign({}, commonSpec), { type: 'interval' });
21
+ return { type: 'bar', role: 'primary', name: measure, data: points() };
36
22
  }
37
23
  // scatter
38
24
  if (insightType === 'correlation') {
39
- return __assign(__assign({}, commonSpec), { type: 'point', encode: {
40
- x: (_a = measures[0]) === null || _a === void 0 ? void 0 : _a.fieldName,
41
- y: (_b = measures[1]) === null || _b === void 0 ? void 0 : _b.fieldName,
42
- } });
25
+ var yMeasure_1 = (_c = measures[1]) === null || _c === void 0 ? void 0 : _c.fieldName;
26
+ return {
27
+ type: 'point',
28
+ role: 'primary',
29
+ name: "".concat(measure, " / ").concat(yMeasure_1),
30
+ data: data.map(function (datum) { return ({ x: Number(datum[measure]), y: Number(datum[yMeasure_1]) }); }),
31
+ };
43
32
  }
44
33
  return null;
45
34
  };
@@ -1,12 +1,2 @@
1
1
  import { __assign } from "tslib";
2
- export var areaMarkStrategy = function (data, _a) {
3
- var encode = _a.encode, style = _a.style, tooltip = _a.tooltip;
4
- var common = {
5
- style: style,
6
- tooltip: tooltip,
7
- };
8
- if (data) {
9
- return __assign(__assign({}, common), { type: 'area', data: data, encode: __assign({ x: 'x', y: 'y' }, encode) });
10
- }
11
- return null;
12
- };
2
+ export var areaMarkStrategy = function (data, config) { return (__assign({ type: 'area', data: data }, config)); };
@@ -0,0 +1,6 @@
1
+ import { __assign } from "tslib";
2
+ /** get mark for point patterns, the patterns should have same dimension and measure */
3
+ export var barMarkStrategy = function (patterns, config) { return (__assign({ type: 'bar', data: patterns.map(function (_a) {
4
+ var x = _a.x, y = _a.y;
5
+ return ({ x: x, y: y });
6
+ }) }, config)); };
@@ -1,5 +1,5 @@
1
1
  export { lineMarkStrategy } from './lineMark';
2
2
  export { pointMarkStrategy } from './pointMark';
3
- export { textMarkStrategy } from './textMark';
4
3
  export { areaMarkStrategy } from './areaMark';
5
- export { intervalMarkStrategy } from './intervalMark';
4
+ export { barMarkStrategy } from './barMark';
5
+ export { ruleYMarkStrategy } from './ruleMark';
@@ -1,34 +1,2 @@
1
1
  import { __assign } from "tslib";
2
- import { INSIGHT_COLOR_PLATTE } from '../../constants';
3
- export var lineMarkStrategy = function (_a, _b) {
4
- var points = _a.points, x = _a.x, y = _a.y;
5
- var encode = _b.encode, style = _b.style, label = _b.label, tooltip = _b.tooltip;
6
- var common = {
7
- style: __assign({ lineDash: [2, 2], stroke: INSIGHT_COLOR_PLATTE.highlight }, style),
8
- labels: label
9
- ? [
10
- {
11
- text: label,
12
- selector: 'last',
13
- position: 'right',
14
- style: {
15
- textBaseline: 'bottom',
16
- textAlign: 'end',
17
- dy: -24,
18
- },
19
- },
20
- ]
21
- : undefined,
22
- tooltip: tooltip,
23
- };
24
- if (points) {
25
- return __assign(__assign({}, common), { type: 'line', data: points, encode: __assign({ x: 'x', y: 'y' }, encode) });
26
- }
27
- if (x) {
28
- return __assign(__assign({}, common), { type: 'lineX', data: [x] });
29
- }
30
- if (y) {
31
- return __assign(__assign({}, common), { type: 'lineY', data: [y] });
32
- }
33
- return null;
34
- };
2
+ export var lineMarkStrategy = function (data, config) { return (__assign({ type: 'line', data: data }, config)); };
@@ -1,17 +1,13 @@
1
- import { __assign } from "tslib";
1
+ import { __assign, __rest } from "tslib";
2
2
  import { isNil } from 'lodash';
3
3
  /** get mark for point patterns, the patterns should have same dimension and measure */
4
4
  export var pointMarkStrategy = function (patterns, config) {
5
- var data = [];
6
- patterns.forEach(function (_a) {
5
+ var label = config.label, markConfig = __rest(config, ["label"]);
6
+ var data = patterns
7
+ .filter(function (_a) {
7
8
  var x = _a.x, y = _a.y;
8
- if (isNil(x) || isNil(y))
9
- return;
10
- data.push({ x: x, y: y });
11
- });
12
- var pointMark = __assign({ type: 'point', data: data, encode: {
13
- x: 'x',
14
- y: 'y',
15
- } }, config);
16
- return pointMark;
9
+ return !isNil(x) && !isNil(y);
10
+ })
11
+ .map(function (pattern) { return (__assign({ x: pattern.x, y: pattern.y }, (label ? { label: label(pattern) } : {}))); });
12
+ return __assign({ type: 'point', data: data }, markConfig);
17
13
  };
@@ -0,0 +1,2 @@
1
+ import { __assign } from "tslib";
2
+ export var ruleYMarkStrategy = function (y, config) { return (__assign({ type: 'ruleY', y: y }, config)); };
@@ -1,16 +1,22 @@
1
- import { __assign } from "tslib";
2
1
  export var viewSpecStrategy = function (marks, insight) {
3
- // 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%)
4
- var isMajorityPattern = insight.patterns.map(function (pattern) { return pattern.type; }).includes('majority');
5
- var viewConfig = isMajorityPattern
6
- ? { scale: { y: { nice: false } } }
7
- : {
8
- scale: { y: { nice: true } },
2
+ var _a, _b, _c, _d, _e;
3
+ var validMarks = marks.filter(Boolean);
4
+ var insightType = ((_a = insight.patterns[0]) !== null && _a !== void 0 ? _a : {}).type;
5
+ if (insightType === 'majority') {
6
+ return { coordinate: 'polar', marks: validMarks };
7
+ }
8
+ if (insightType === 'correlation') {
9
+ return {
10
+ coordinate: 'cartesian',
11
+ x: { field: (_b = insight.measures[0]) === null || _b === void 0 ? void 0 : _b.fieldName, type: 'value' },
12
+ y: { field: (_c = insight.measures[1]) === null || _c === void 0 ? void 0 : _c.fieldName, type: 'value' },
13
+ marks: validMarks,
9
14
  };
10
- return __assign({ type: 'view', theme: 'dark', axis: {
11
- x: { labelAutoHide: true, labelAutoRotate: false, title: false },
12
- y: { title: false },
13
- }, interaction: {
14
- tooltip: { groupName: false },
15
- }, legend: false, children: marks }, viewConfig);
15
+ }
16
+ return {
17
+ coordinate: 'cartesian',
18
+ x: { field: (_d = insight.dimensions[0]) === null || _d === void 0 ? void 0 : _d.fieldName, type: 'category' },
19
+ y: { field: (_e = insight.measures[0]) === null || _e === void 0 ? void 0 : _e.fieldName, type: 'value' },
20
+ marks: validMarks,
21
+ };
16
22
  };
@@ -1 +1,8 @@
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
+ */
1
8
  export {};
@@ -57,7 +57,7 @@ var CategoryOutlierNarrativeStrategy = /** @class */ (function (_super) {
57
57
  template: '${.x}',
58
58
  separator: getDefaultSeparator('zh-CN'),
59
59
  variableMetaMap: variableMetaMap,
60
- useVariable: 'paragraph',
60
+ useVariable: 'patterns',
61
61
  },
62
62
  ],
63
63
  'en-US': [
@@ -66,7 +66,7 @@ var CategoryOutlierNarrativeStrategy = /** @class */ (function (_super) {
66
66
  template: '${.x}',
67
67
  separator: getDefaultSeparator('en-US'),
68
68
  variableMetaMap: variableMetaMap,
69
- useVariable: 'paragraph',
69
+ useVariable: 'patterns',
70
70
  },
71
71
  ],
72
72
  };
@@ -50,7 +50,7 @@ var TrendNarrativeStrategy = /** @class */ (function (_super) {
50
50
  ],
51
51
  'en-US': [
52
52
  {
53
- template: 'There is a signifcant ${trend} trend for ${measure} during ${dateRange} with a slope of ${slope}X.',
53
+ template: 'There is a significant ${trend} trend for ${measure} during ${dateRange} with a slope of ${slope}X.',
54
54
  variableMetaMap: variableMetaMap,
55
55
  },
56
56
  ],
@@ -28,12 +28,8 @@ export var getAnnotationSpec = function (insightInfo) {
28
28
  return (_b = insightType2AugmentedMarks[insightType]) === null || _b === void 0 ? void 0 : _b.call(insightType2AugmentedMarks, insightInfo);
29
29
  };
30
30
  export var getChartSpecWithoutAugmentedMarks = function (insightInfo, insightType) {
31
- var chartMark = insight2ChartStrategy(__assign(__assign({}, insightInfo), (size(insightInfo.patterns) === 0
32
- ? {
33
- patterns: [{ type: insightType }],
34
- }
35
- : {})));
36
- return viewSpecStrategy([chartMark], insightInfo);
31
+ var chartInsight = __assign(__assign({}, insightInfo), (size(insightInfo.patterns) === 0 ? { patterns: [{ type: insightType }] } : {}));
32
+ return viewSpecStrategy([insight2ChartStrategy(chartInsight)], chartInsight);
37
33
  };
38
34
  export var filterValidInsightInfoForAnnotationSpec = function (_a) {
39
35
  var _b = _a.patternInfos, patternInfos = _b === void 0 ? [] : _b, insightType = _a.insightType;
@@ -30,10 +30,8 @@ export var generateHomogeneousInsightVisualizationSpec = function (insight, visu
30
30
  var schemas = [];
31
31
  patterns.forEach(function (pattern) {
32
32
  var insightType = pattern.insightType;
33
- var chartSpec = {};
34
33
  schemas.push({
35
34
  patternType: insightType,
36
- chartSpec: chartSpec,
37
35
  narrativeSpec: generateInsightNarrative(__assign(__assign({}, omit(insight, ['patterns'])), pattern), visualizationOptions),
38
36
  });
39
37
  });
package/lib/index.d.ts CHANGED
@@ -5,6 +5,6 @@ export type { ChartId, Family, Purpose, CoordinateSystem, GraphicCategory, Shape
5
5
  export { analyzeField, Series, DataFrame, min, max, sum, mean, normalDistributionQuantile, tDistributionQuantile, distinct, valueMap, missing, valid, pearson, covariance, coefficientOfVariance, standardDeviation, variance, quantile, quartile, median, harmonicMean, geometricMean, pcorrtest, cdf, maxabs, } from './data';
6
6
  export type { FieldType, FieldInfo, StringFieldInfo, NumberFieldInfo, DateFieldInfo, NDArray, SeriesData, FrameData, Axis, Extra, FieldsInfo, } from './data';
7
7
  export { getInsights, generateInsightVisualizationSpec, insightPatternsExtractor, getSpecificInsight } from './insight';
8
- export type { Datum, DomainType, MeasureMethod, ImpactMeasureMethod, Aggregator, DataProperty, Measure, Dimension, Subspace, ImpactMeasure, SubjectInfo, InsightType, HomogeneousInsightType, PatternInfo, InsightVisualizationSpec, InsightInfo, InsightVisualizationOptions, InsightOptions, BasePatternInfo, HomogeneousPatternInfo, PointPatternInfo, CategoryOutlierInfo, TimeSeriesOutlierInfo, ChangePointInfo, MajorityInfo, LinearRegressionResult, LowVarianceInfo, CorrelationInfo, InsightsResult, InsightExtractorProps, SpecificInsightProps, AugmentedMarks, } from './insight';
8
+ export type { Datum, DomainType, MeasureMethod, ImpactMeasureMethod, Aggregator, DataProperty, Measure, Dimension, Subspace, ImpactMeasure, SubjectInfo, InsightType, HomogeneousInsightType, PatternInfo, InsightVisualizationSpec, InsightInfo, InsightVisualizationOptions, InsightOptions, BasePatternInfo, HomogeneousPatternInfo, PointPatternInfo, CategoryOutlierInfo, TimeSeriesOutlierInfo, ChangePointInfo, MajorityInfo, LinearRegressionResult, LowVarianceInfo, CorrelationInfo, InsightsResult, InsightExtractorProps, SpecificInsightProps, AugmentedMarks, InsightChartSpec, InsightChartMark, InsightChartAxis, InsightChartPoint, InsightChartValue, InsightMarkRole, InsightLineMark, InsightBarMark, InsightPointMark, InsightAreaMark, InsightRuleXMark, InsightRuleYMark, InsightArcMark, } from './insight';
9
9
  export { generateTextSpec, isCustomSection, isStandardSection, isCustomParagraph, isTextParagraph, isBulletParagraph, getHeadingWeight, isHeadingParagraph, isDividerParagraph, isEntityPhrase, isImagePhrase, isCustomPhrase, isTextPhrase, isEntityType, isEscapePhrase, isFormulaPhrase, ENTITY_TYPES, } from './ntv';
10
10
  export * from './ntv/types';
@@ -1,14 +1,5 @@
1
- import { ChartType, InsightType } from '../types';
2
- export declare const INSIGHT_COLOR_PLATTE: Record<string, string>;
3
- export declare const BOLD_FONT_WEIGHT = 500;
4
- export declare const TEXT_STYLE: {
5
- textAlign: string;
6
- fill: string;
7
- fontFamily: string;
8
- opacity: number;
9
- };
10
- export declare const ChartTypeMap: Record<InsightType, ChartType>;
11
- export declare const PIE_RADIUS_STYLE: {
1
+ /** pie radii as fractions of the available radius */
2
+ export declare const PIE_RADIUS: {
12
3
  innerRadius: number;
13
4
  outerRadius: number;
14
5
  };