UNPKG

@formant/ava

Version:

A framework for automated visual analytics.

50 lines (49 loc) 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.insight2ChartStrategy = void 0; var tslib_1 = require("tslib"); var constants_1 = require("../constants"); var insight2ChartStrategy = function (insight) { var _a, _b; var data = insight.data, patterns = insight.patterns, dimensions = insight.dimensions, measures = insight.measures; var insightType = patterns[0].type; var commonSpec = { data: data, encode: { x: dimensions[0].fieldName, y: measures[0].fieldName, }, }; // pie if (insightType === 'majority') { return tslib_1.__assign(tslib_1.__assign({}, commonSpec), { type: 'interval', encode: { color: dimensions[0].fieldName, y: measures[0].fieldName, }, transform: [{ type: 'stackY' }], coordinate: { type: 'theta', innerRadius: constants_1.PIE_RADIUS_STYLE.innerRadius, outerRadius: constants_1.PIE_RADIUS_STYLE.outerRadius, }, tooltip: { items: [{ field: dimensions[0].fieldName }, { field: measures[0].fieldName }], } }); } // line if (insightType === 'trend' || insightType === 'time_series_outlier' || insightType === 'change_point') { return tslib_1.__assign(tslib_1.__assign({}, commonSpec), { type: 'line', style: { lineWidth: 2, } }); } // bar if (insightType === 'category_outlier' || insightType === 'low_variance') { return tslib_1.__assign(tslib_1.__assign({}, commonSpec), { type: 'interval' }); } // scatter if (insightType === 'correlation') { return tslib_1.__assign(tslib_1.__assign({}, commonSpec), { type: 'point', encode: { x: (_a = measures[0]) === null || _a === void 0 ? void 0 : _a.fieldName, y: (_b = measures[1]) === null || _b === void 0 ? void 0 : _b.fieldName, } }); } return null; }; exports.insight2ChartStrategy = insight2ChartStrategy;