Skip to content

Commit

Permalink
refactor: update naming and remove from scales spec
Browse files Browse the repository at this point in the history
  • Loading branch information
rshen91 committed Mar 11, 2020
1 parent 1b76c69 commit 5037110
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 31 deletions.
10 changes: 5 additions & 5 deletions src/chart_types/xy_chart/utils/axis_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
getAxisTickLabelPadding,
isVerticalGrid,
isHorizontalGrid,
getDuplicateTicks,
enableDuplicatedTicks,
} from './axis_utils';
import { CanvasTextBBoxCalculator } from '../../../utils/bbox/canvas_text_bbox_calculator';
import { SvgTextBBoxCalculator } from '../../../utils/bbox/svg_text_bbox_calculator';
Expand Down Expand Up @@ -1448,7 +1448,7 @@ describe('Axis computational utils', () => {
const axisSpec: AxisSpec = {
id: 'bottom',
position: 'bottom',
duplicateTicks: false,
enableDuplicatedTicks: false,
chartType: 'xy_axis',
specType: 'axis',
groupId: '__global__',
Expand All @@ -1470,7 +1470,7 @@ describe('Axis computational utils', () => {
const scale: Scale = computeXScale({ xDomain: xDomainTime, totalBarsInCluster: 0, range: [0, 603.5] });
const offset = 0;
const tickFormatOption = { timeZone: 'utc+1' };
expect(getDuplicateTicks(axisSpec, scale, offset, tickFormatOption)).toEqual([
expect(enableDuplicatedTicks(axisSpec, scale, offset, tickFormatOption)).toEqual([
{ value: 1547208000000, label: '2019-01-11', position: 25.145833333333332 },
{ value: 1547251200000, label: '2019-01-12', position: 85.49583333333334 },
{ value: 1547337600000, label: '2019-01-13', position: 206.19583333333333 },
Expand All @@ -1488,7 +1488,7 @@ describe('Axis computational utils', () => {
const axisSpec: AxisSpec = {
id: 'bottom',
position: 'bottom',
duplicateTicks: true,
enableDuplicatedTicks: true,
chartType: 'xy_axis',
specType: 'axis',
groupId: '__global__',
Expand All @@ -1510,7 +1510,7 @@ describe('Axis computational utils', () => {
const scale: Scale = computeXScale({ xDomain: xDomainTime, totalBarsInCluster: 0, range: [0, 603.5] });
const offset = 0;
const tickFormatOption = { timeZone: 'utc+1' };
expect(getDuplicateTicks(axisSpec, scale, offset, tickFormatOption)).toEqual([
expect(enableDuplicatedTicks(axisSpec, scale, offset, tickFormatOption)).toEqual([
{ value: 1547208000000, label: '2019-01-11', position: 25.145833333333332 },
{ value: 1547251200000, label: '2019-01-12', position: 85.49583333333334 },
{ value: 1547294400000, label: '2019-01-12', position: 145.84583333333333 },
Expand Down
9 changes: 3 additions & 6 deletions src/chart_types/xy_chart/utils/axis_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export function getScaleForAxisSpec(
range,
ticks: axisSpec.ticks,
integersOnly: axisSpec.integersOnly,
duplicateTicks: axisSpec.duplicateTicks,
});
if (yScales.has(axisSpec.groupId)) {
return yScales.get(axisSpec.groupId)!;
Expand All @@ -171,7 +170,6 @@ export function getScaleForAxisSpec(
enableHistogramMode,
ticks: axisSpec.ticks,
integersOnly: axisSpec.integersOnly,
duplicateTicks: axisSpec.duplicateTicks,
});
}
}
Expand Down Expand Up @@ -233,7 +231,6 @@ export function computeTickDimensions(
axisConfig: AxisConfig,
tickLabelPadding: number,
tickLabelRotation = 0,
// duplicateTicks: boolean = false,
tickFormatOptions?: TickFormatterOptions,
) {
const tickValues = scale.ticks();
Expand Down Expand Up @@ -443,10 +440,10 @@ export function getAvailableTicks(

return [firstTick, lastTick];
}
return getDuplicateTicks(axisSpec, scale, offset, tickFormatOptions);
return enableDuplicatedTicks(axisSpec, scale, offset, tickFormatOptions);
}

export function getDuplicateTicks(
export function enableDuplicatedTicks(
axisSpec: AxisSpec,
scale: Scale,
offset: number,
Expand All @@ -462,7 +459,7 @@ export function getDuplicateTicks(
};
});

if (axisSpec.duplicateTicks === false) {
if (axisSpec.enableDuplicatedTicks === false) {
const uniqueTickLabels: { value: any; label: string; position: number }[] = [];
allTicks.filter((value, index) => {
for (let i = 0; i < labels.length; i++) {
Expand Down
18 changes: 3 additions & 15 deletions src/chart_types/xy_chart/utils/scales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ interface XScaleOptions {
enableHistogramMode?: boolean;
ticks?: number;
integersOnly?: boolean;
duplicateTicks?: boolean;
}

/**
Expand All @@ -88,16 +87,7 @@ interface XScaleOptions {
* @param axisLength the length of the x axis
*/
export function computeXScale(options: XScaleOptions): Scale {
const {
xDomain,
totalBarsInCluster,
range,
barsPadding,
enableHistogramMode,
ticks,
integersOnly,
duplicateTicks,
} = options;
const { xDomain, totalBarsInCluster, range, barsPadding, enableHistogramMode, ticks, integersOnly } = options;
const { scaleType, minInterval, domain, isBandScale, timeZone } = xDomain;
const rangeDiff = Math.abs(range[1] - range[0]);
const isInverse = range[1] < range[0];
Expand Down Expand Up @@ -139,7 +129,7 @@ export function computeXScale(options: XScaleOptions): Scale {
} else {
return new ScaleContinuous(
{ type: scaleType, domain, range },
{ bandwidth: 0, minInterval, timeZone, totalBarsInCluster, barsPadding, ticks, integersOnly, duplicateTicks },
{ bandwidth: 0, minInterval, timeZone, totalBarsInCluster, barsPadding, ticks, integersOnly },
);
}
}
Expand All @@ -150,7 +140,6 @@ interface YScaleOptions {
range: [number, number];
ticks?: number;
integersOnly?: boolean;
duplicateTicks?: boolean;
}
/**
* Compute the y scales, one per groupId for the y axis.
Expand All @@ -159,7 +148,7 @@ interface YScaleOptions {
*/
export function computeYScales(options: YScaleOptions): Map<GroupId, Scale> {
const yScales: Map<GroupId, Scale> = new Map();
const { yDomains, range, ticks, integersOnly, duplicateTicks } = options;
const { yDomains, range, ticks, integersOnly } = options;
yDomains.forEach(({ scaleType: type, domain, groupId }) => {
const yScale = new ScaleContinuous(
{
Expand All @@ -170,7 +159,6 @@ export function computeYScales(options: YScaleOptions): Map<GroupId, Scale> {
{
ticks,
integersOnly,
duplicateTicks,
},
);
yScales.set(groupId, yScale);
Expand Down
2 changes: 1 addition & 1 deletion src/chart_types/xy_chart/utils/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ export interface AxisSpec extends Spec {
/** Show only integar values **/
integersOnly?: boolean;
/** Remove duplicate ticks, default is false*/
duplicateTicks?: boolean;
enableDuplicatedTicks?: boolean;
}

export type TickFormatterOptions = {
Expand Down
3 changes: 0 additions & 3 deletions src/scales/scale_continuous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ interface ScaleOptions {
isSingleValueHistogram: boolean;
/** Show only integer values **/
integersOnly?: boolean;
/** Show duplicate tick values default to false */
duplicateTicks?: boolean;
}
const defaultScaleOptions: ScaleOptions = {
bandwidth: 0,
Expand All @@ -151,7 +149,6 @@ const defaultScaleOptions: ScaleOptions = {
ticks: 10,
isSingleValueHistogram: false,
integersOnly: false,
duplicateTicks: false,
};
export class ScaleContinuous implements Scale {
readonly bandwidth: number;
Expand Down
7 changes: 6 additions & 1 deletion stories/line/10_duplicate_ticks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export const example = () => {
const duplicateTicksInAxis = boolean('Show duplicate ticks in x axis', false);
return (
<Chart className="story-chart">
<Axis id="bottom" position={Position.Bottom} tickFormat={formatter} duplicateTicks={duplicateTicksInAxis} />
<Axis
id="bottom"
position={Position.Bottom}
tickFormat={formatter}
enableDuplicatedTicks={duplicateTicksInAxis}
/>
<Axis
id="left"
title={KIBANA_METRICS.metrics.kibana_os_load[0].metric.title}
Expand Down

0 comments on commit 5037110

Please sign in to comment.