Skip to content

Commit

Permalink
fix(bullet): full circle overlapping tick labels (#2350)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickofthyme authored Mar 12, 2024
1 parent cf9ce81 commit edbff68
Show file tree
Hide file tree
Showing 25 changed files with 24 additions and 11 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.
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.
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.
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.
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.
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/charts/api/charts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ export interface BulletDatum {
targetFormatter?: ValueFormatter;
// (undocumented)
tickFormatter: ValueFormatter;
ticks?: number | ((domain: GenericDomain) => number[]);
ticks?: number | number[] | ((domain: GenericDomain) => number[]);
// (undocumented)
title: string;
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { drawPolarLine } from '../../../../xy_chart/renderer/canvas/lines';
import { renderDebugPoint } from '../../../../xy_chart/renderer/canvas/utils/debug';
import { ActiveValue } from '../../../selectors/get_active_values';
import { BulletPanelDimensions } from '../../../selectors/get_panel_dimensions';
import { BulletSpec } from '../../../spec';
import { BulletSpec, BulletSubtype } from '../../../spec';
import { BulletStyle, GRAPH_PADDING, TICK_FONT, TICK_FONT_SIZE } from '../../../theme';
import { getAngledChartSizing } from '../../../utils/angular';
import { TARGET_SIZE, BULLET_SIZE, TICK_WIDTH, BAR_SIZE, TARGET_STROKE_WIDTH } from '../constants';
Expand Down Expand Up @@ -44,7 +44,15 @@ export function angularBullet(
// const counterClockwise = true;
const counterClockwise = startAngle < endAngle && start > end;
const [min, max] = sortNumbers([start, end]) as ContinuousDomain;
const formatterColorTicks = ticks.map((v) => ({ value: v, formattedValue: datum.tickFormatter(v) }));
const filteredTicks =
spec.subtype !== BulletSubtype.circle
? ticks
: min === ticks.at(0) && max === ticks.at(-1)
? ticks.slice(0, -1)
: max === ticks.at(0) && min === ticks.at(-1)
? ticks.slice(1)
: ticks;
const formatterColorTicks = filteredTicks.map((v) => ({ value: v, formattedValue: datum.tickFormatter(v) }));

// Color bands
colorBands.forEach((band) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ function getScaleWithTicks(domain: GenericDomain, range: Range, tickOptions: Tic

return {
scale,
ticks: customRange ? ticks(updatedDomain).filter(isWithinRange(updatedDomain)) : scale.ticks(ticks),
ticks: customRange
? (Array.isArray(ticks) ? ticks : ticks(updatedDomain)).filter(isWithinRange(updatedDomain))
: scale.ticks(ticks),
};
}
2 changes: 1 addition & 1 deletion packages/charts/src/chart_types/bullet_graph/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface BulletDatum {
*
* See https://d3js.org/d3-scale/linear#linear_ticks
*/
ticks?: number | ((domain: GenericDomain) => number[]);
ticks?: number | number[] | ((domain: GenericDomain) => number[]);
syncCursor?: boolean;
valueFormatter: ValueFormatter;
targetFormatter?: ValueFormatter;
Expand Down
9 changes: 8 additions & 1 deletion packages/charts/src/chart_types/bullet_graph/utils/ticks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ export interface TickOptions {

/** @internal */
export function getTicks(length: number, { desiredTicks, interval }: Omit<TickOptions, 'nice'>) {
if ((isFiniteNumber(desiredTicks) && desiredTicks > 0) || typeof desiredTicks === 'function') return desiredTicks;
if (
(isFiniteNumber(desiredTicks) && desiredTicks >= 0) ||
typeof desiredTicks === 'function' ||
Array.isArray(desiredTicks)
) {
return desiredTicks;
}

const target = Math.floor(length / interval);
return clamp(target, MIN_TICK_COUNT, MAX_TICK_COUNT);
}
6 changes: 1 addition & 5 deletions storybook/stories/bullet_graph/1_single.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ export const Example: ChartsStory = (_, { title, description }) => {
domain: [start, end],
niceDomain,
ticks:
tickStrategy[0] === 'count'
? ticks
: tickStrategy[0] === 'placements'
? () => tickPlacements
: undefined,
tickStrategy[0] === 'count' ? ticks : tickStrategy[0] === 'placements' ? tickPlacements : undefined,
valueFormatter: formatter,
tickFormatter: formatter,
},
Expand Down

0 comments on commit edbff68

Please sign in to comment.