UNPKG

@formant/ava

Version:

A framework for automated visual analytics.

76 lines (75 loc) 2.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateHomogeneousInsightChartSpec = exports.generateHomogeneousInsightAugmentedMarks = void 0; var tslib_1 = require("tslib"); var constants_1 = require("../constants"); function generateHomogeneousInsightAugmentedMarks(pattern) { var annotations = []; var insightType = pattern.insightType, childPatterns = pattern.childPatterns; if (['change_point', 'time_series_outlier'].includes(insightType)) { var x_1 = childPatterns[0].x; var text = insightType === 'change_point' ? 'Abrupt Change' : 'Outlier'; var color_1 = insightType === 'change_point' ? constants_1.INSIGHT_COLOR_PLATTE.highlight : constants_1.INSIGHT_COLOR_PLATTE.outlier; // draw line var line = { type: 'line', start: [x_1, 'min'], end: [x_1, 'max'], text: { content: text, position: 'left', offsetY: 15, offsetX: 5, rotate: 0, autoRotate: false, style: { textAlign: 'left', }, }, }; annotations.push(line); // draw circle var circles = childPatterns.map(function (pattern) { var y = pattern.y; return { type: 'dataMarker', position: [x_1, y], point: { style: { fill: '#fff', stroke: color_1, }, }, line: { length: 20, }, autoAdjust: false, }; }); annotations.push.apply(annotations, tslib_1.__spreadArray([], tslib_1.__read(circles), false)); } return annotations; } exports.generateHomogeneousInsightAugmentedMarks = generateHomogeneousInsightAugmentedMarks; function generateHomogeneousInsightChartSpec(insight, pattern) { var dimensions = insight.dimensions, measures = insight.measures; var plotSchema; if (measures.length > 1) { plotSchema = { xField: dimensions[0], yField: 'value', seriesField: 'measureName', }; } else { plotSchema = { xField: dimensions[1], yField: measures[0].fieldName, seriesField: dimensions[0], }; } var annotationConfig = generateHomogeneousInsightAugmentedMarks(pattern); var chartSchema = tslib_1.__assign(tslib_1.__assign({}, plotSchema), { annotations: annotationConfig }); return chartSchema; } exports.generateHomogeneousInsightChartSpec = generateHomogeneousInsightChartSpec;