Skip to content

Commit

Permalink
fix(line-xy): support bandOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Jul 27, 2023
1 parent 5403279 commit d5fbc3d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,4 @@ export { cars2PointOrdinalSize } from './cars2-point-ordinal-size';
export { cars2PointConstantColorSize } from './cars2-point-constant-color-size';
export { alphabetIntervalTitleAuto } from './alphabet-interval-title-auto';
export { alphabetIntervalAutoPaddingLabelHide } from './alphabet-interval-auto-padding-label-hide';
export { settleWeatherCellLineXY } from './seattle-weather-cell-lineXY';
34 changes: 34 additions & 0 deletions __tests__/plots/static/seattle-weather-cell-lineXY.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { G2Spec } from '../../../src';

export function settleWeatherCellLineXY(): G2Spec {
return {
type: 'view',
height: 325,
children: [
{
type: 'cell',
data: {
type: 'fetch',
value: 'data/seattle-weather.csv',
},
encode: {
x: (d) => new Date(d.date).getUTCDate(),
y: (d) => new Date(d.date).getUTCMonth(),
color: 'temp_max',
},
transform: [{ type: 'group', color: 'max' }],
style: { inset: 0.5 },
},
{
type: 'lineY',
data: [4],
style: { stroke: 'red', strokeWidth: 4, bandOffset: 0.5 },
},
{
type: 'lineX',
data: [4],
style: { stroke: 'red', strokeWidth: 4, bandOffset: 0.5 },
},
],
};
}
16 changes: 11 additions & 5 deletions src/mark/lineX.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { Vector } from '@antv/coord';
import { deepMix } from '@antv/util';
import { MarkComponent as MC, Vector2 } from '../runtime';
import { LineXMark } from '../spec';
import {
basePostInference,
baseAnnotationChannels,
basePreInference,
createBandOffset,
} from './utils';

export type LineXOptions = Omit<LineXMark, 'type'>;

export const LineX: MC<LineXOptions> = () => {
export const LineX: MC<LineXOptions> = (options) => {
return (index, scale, value, coordinate) => {
const { x: X } = value;
const offset = createBandOffset(
scale,
value,
deepMix({ style: { bandOffset: 0 } }, options),
);
const P = Array.from(index, (i) => {
const p1 = [X[i], 1] as Vector;
const p2 = [X[i], 0] as Vector;
return [p1, p2].map((d) => coordinate.map(d)) as Vector2[];
const p1 = [X[i], 1] as Vector2;
const p2 = [X[i], 0] as Vector2;
return [p1, p2].map((d) => coordinate.map(offset(d, i))) as Vector2[];
});
return [index, P];
};
Expand Down
16 changes: 11 additions & 5 deletions src/mark/lineY.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { Vector } from '@antv/coord';
import { deepMix } from '@antv/util';
import { MarkComponent as MC, Vector2 } from '../runtime';
import { LineYMark } from '../spec';
import {
baseAnnotationChannels,
basePreInference,
basePostInference,
createBandOffset,
} from './utils';

export type LineYOptions = Omit<LineYMark, 'type'>;

export const LineY: MC<LineYOptions> = () => {
export const LineY: MC<LineYOptions> = (options) => {
return (index, scale, value, coordinate) => {
const { y: Y } = value;
const offset = createBandOffset(
scale,
value,
deepMix({ style: { bandOffset: 0 } }, options),
);
const P = Array.from(index, (i) => {
const p1 = [0, Y[i]] as Vector;
const p2 = [1, Y[i]] as Vector;
return [p1, p2].map((d) => coordinate.map(d)) as Vector2[];
const p1 = [0, Y[i]] as Vector2;
const p2 = [1, Y[i]] as Vector2;
return [p1, p2].map((d) => coordinate.map(offset(d, i))) as Vector2[];
});
return [index, P];
};
Expand Down

0 comments on commit d5fbc3d

Please sign in to comment.