Skip to content

Commit

Permalink
fix(axis): order of ticks for transposed x axis
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Apr 26, 2023
1 parent e209b6a commit 8736eea
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions __tests__/plots/static/aapl-line-basic-transpose.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { G2Spec } from '../../../src';

export function aaplLineBasicTranspose(): G2Spec {
return {
type: 'line',
height: 640,
width: 480,
paddingLeft: 50,
data: {
type: 'fetch',
value: 'data/aapl.csv',
},
coordinate: { transform: [{ type: 'transpose' }] },
encode: {
x: 'date',
y: 'close',
},
};
}

aaplLineBasicTranspose.maxError = 100;
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,4 @@ export { gaugeCustomShape } from './gauge-custom-shape';
export { scoreByItemAreaRadarSize } from './score-by-item-area-radar-size';
export { mockPointLogTicks } from './mock-point-log-ticks';
export { alphabetIntervalLabelRotate } from './alphabet-interval-label-rotate';
export { aaplLineBasicTranspose } from './aapl-line-basic-transpose';
19 changes: 12 additions & 7 deletions src/component/axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,26 @@ function getData(
defaultTickFormatter || scale.getFormatter?.() || toString;
const applyInset = createInset(position, coordinate);
const applyFisheye = createFisheye(position, coordinate);
const isHorizontal = (position) =>
['top', 'bottom', 'center', 'outer'].includes(position);

// @todo GUI should consider the overlap problem for the first
// and label of arc axis.
if (isPolar(coordinate) || isTranspose(coordinate)) {
const axisTicks = filteredTicks.map((d, i, array) => {
return filteredTicks.map((d, i, array) => {
const offset = scale.getBandWidth?.(d) / 2 || 0;
const tick = applyInset(scale.map(d) + offset);
const shouldReverse =
(isRadial(coordinate) && position === 'center') ||
(isTranspose(coordinate) &&
scale.getTicks?.() &&
isHorizontal(position));
return {
value: isTranspose(coordinate) && scale.getTicks?.() ? 1 - tick : tick,
value: shouldReverse ? 1 - tick : tick,
label: toString(labelFormatter(prettyNumber(d), i, array)),
id: String(i),
};
});
// @todo GUI should consider the overlap problem for the first
// and label of arc axis.
return isRadial(coordinate) && position === 'center'
? reverseTicks(axisTicks)
: axisTicks;
}

return filteredTicks.map((d, i, array) => {
Expand Down

0 comments on commit 8736eea

Please sign in to comment.