Skip to content

Commit

Permalink
fix(ava/insight): change the judgement of enable y nice to viewSpecSt…
Browse files Browse the repository at this point in the history
…rategy
  • Loading branch information
chenluli authored and BBSQQ committed Mar 24, 2023
1 parent a3b7c66 commit 715854c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
9 changes: 1 addition & 8 deletions packages/ava/src/insight/chart/generator/insights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ export function generateInsightChartSpec(insight: InsightInfo<PatternInfo>): G2S
correlation: correlationStrategy,
};

// 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%)
const isThetaCoordinate = insight.patterns.map((pattern) => pattern.type).includes('majority');
const viewConfig = isThetaCoordinate
? { scale: { y: { nice: false } } }
: {
scale: { y: { nice: true } },
};
const marks = insightType2Strategy[insightType]?.(insight);
return viewSpecStrategy(marks, viewConfig);
return viewSpecStrategy(marks, insight);
}
18 changes: 11 additions & 7 deletions packages/ava/src/insight/chart/strategy/viewSpec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { G2Spec, Mark } from '@antv/g2';
import type { G2Spec, Mark } from '@antv/g2';
import type { InsightInfo, PatternInfo } from '../../types';

export const viewSpecStrategy = (marks: Mark[], insight?: InsightInfo<PatternInfo>): G2Spec => {
// 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%)
const isMajorityPattern = insight.patterns.map((pattern) => pattern.type).includes('majority');
const viewConfig = isMajorityPattern
? { scale: { y: { nice: false } } }
: {
scale: { y: { nice: true } },
};

export const viewSpecStrategy = (
marks: Mark[],
viewConfig?: {
scale?: Mark['scale'];
}
): G2Spec => {
return {
type: 'view',
theme: 'classic',
Expand Down
14 changes: 10 additions & 4 deletions packages/ava/src/utils/dataFormat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// data format.
// dataFormat(12, 1) = 12
// dataFormat(1234, 1) = 1.2k
// dataFormat(123.456, 2) = 123.46
/**
* data format.
* dataFormat(0.8849) = 0.88
* dataFormat(12, 1) = 12
* dataFormat(1234, 1) = 1.2k
* dataFormat(123.456, 2) = 123.46
* @param value value to be formatted
* @param digits the number of digits to keep after the decimal point, 2 by default
* @returns formatted value string
*/
export default function dataFormat(value: number | string, digits: number = 2) {
if (typeof value === 'string') return value;

Expand Down

0 comments on commit 715854c

Please sign in to comment.