Skip to content

Commit

Permalink
feat: update gui and adapt to crossSize config (#4949)
Browse files Browse the repository at this point in the history
* feat: update gui and adapt to crossSize config

* test: update test snapshots

* test: fix issues cause test failed
  • Loading branch information
Aarebecca authored and hustcc committed May 9, 2023
1 parent f85e72f commit d1d9b8d
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 52 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ export async function populationIntervalRoseKeyframe(): Promise<G2Spec> {
}

populationIntervalRoseKeyframe.intervals = [false, false, [333, 666]];
populationIntervalRoseKeyframe.maxError = 100;
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export function aaplLineSliderFilterTranspose(): G2Spec {

aaplLineSliderFilterTranspose.maxError = 500;

aaplLineSliderFilterTranspose.skip = true;

aaplLineSliderFilterTranspose.steps = ({ canvas }) => {
const { document } = canvas;
const sliders = document.getElementsByClassName(SLIDER_CLASS_NAME);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@antv/g": "^5.7.4",
"@antv/g-canvas": "^1.7.4",
"@antv/g-plugin-dragndrop": "^1.6.1",
"@antv/gui": "0.5.0-alpha.17",
"@antv/gui": "^0.5.0-alpha.18",
"@antv/path-util": "^3.0.1",
"@antv/scale": "^0.4.7",
"@antv/util": "^3.3.2",
Expand Down
73 changes: 41 additions & 32 deletions site/docs/spec/component/axis.zh.md

Large diffs are not rendered by default.

31 changes: 14 additions & 17 deletions src/component/axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,34 +193,31 @@ function inferGridLength(position: GCP, coordinate: Coordinate) {
}

function inferLabelOverlap(transform = [], style: Record<string, any>) {
const {
labelAutoRotate = true,
labelAutoHide = false,
labelAutoEllipsis = false,
} = style;
if (transform.length > 0) return transform;
const { labelAutoRotate, labelAutoHide, labelAutoEllipsis, labelAutoWrap } =
style;

const finalTransforms = [...transform];
const finalTransforms = [];

const mutateLabelOverlap = (overlap, state) => {
const addToTransfroms = (overlap, state) => {
if (state) {
const index = finalTransforms.findIndex((t) => t.type === overlap.type);
if (index !== -1) finalTransforms[index] = overlap;
else finalTransforms.push(overlap);
} else {
const index = finalTransforms.findIndex((t) => t.type === overlap.type);
if (index !== -1) finalTransforms.splice(index, 1);
finalTransforms.push(overlap);
}
};

mutateLabelOverlap(
addToTransfroms(
{
type: 'rotate',
optionalAngles: [0, 15, 30, 45, 60, 90],
},
labelAutoRotate,
);
mutateLabelOverlap({ type: 'ellipsis', minLength: 20 }, labelAutoEllipsis);
mutateLabelOverlap({ type: 'hide' }, labelAutoHide);
addToTransfroms({ type: 'ellipsis', minLength: 20 }, labelAutoEllipsis);
addToTransfroms({ type: 'hide' }, labelAutoHide);
addToTransfroms(
{ type: 'wrap', wordWrapWidth: 100, maxLines: 3, recoveryWhenFail: true },
labelAutoWrap,
);
return finalTransforms;
}

Expand Down Expand Up @@ -503,7 +500,6 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
};

const gridLength = inferGridLength(position, coordinate);

const overrideStyle = inferAxisLinearOverrideStyle(
position,
orientation,
Expand All @@ -523,6 +519,7 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
position,
coordinate,
),
crossSize: size,
titleText: titleContent(title),
labelOverlap: inferLabelOverlap(transform, internalAxisStyle),
grid: inferGrid(internalAxisStyle.grid, coordinate, scale),
Expand Down
4 changes: 3 additions & 1 deletion src/component/axisX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export type AxisXOptions = AxisOptions;
* LinearAxis component bind to x scale.
*/
export const AxisX: GCC<AxisXOptions> = (options) => {
return LinearAxis(options);
return (...args) =>
// empirical value for crossPadding
LinearAxis(Object.assign({}, { crossPadding: 50 }, options))(...args);
};

AxisX.props = {
Expand Down
3 changes: 2 additions & 1 deletion src/component/axisY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export type AxisYOptions = AxisOptions;
* LinearAxis component bind to y scale.
*/
export const AxisY: GCC<AxisYOptions> = (options) => {
return LinearAxis(options);
return (...args) =>
LinearAxis(Object.assign({}, { crossPadding: 10 }, options))(...args);
};

AxisY.props = {
Expand Down
2 changes: 2 additions & 0 deletions src/theme/classic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export const Classic: TC<ClassicOptions> = (options) => {
gridDirection: 'negative',
labelDirection: 'positive',
labelSpacing: 12,
labelAutoRotate: true,
tickDirection: 'positive',
titlePosition: 'bottom',
titleSpacing: 10,
Expand All @@ -280,6 +281,7 @@ export const Classic: TC<ClassicOptions> = (options) => {
gridDirection: 'positive',
labelDirection: 'negative',
labelSpacing: 4,
labelAutoRotate: false,
tickDirection: 'negative',
titlePosition: 'right',
titleSpacing: 0,
Expand Down

0 comments on commit d1d9b8d

Please sign in to comment.