Skip to content

Commit

Permalink
fix(scales): fix casing of symlog
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze committed Jun 22, 2021
1 parent 9977858 commit c2a656e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/scales/src/compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createPointScale } from './pointScale'
import { createBandScale } from './bandScale'
import { createTimeScale } from './timeScale'
import { createLogScale } from './logScale'
import { createSymLogScale } from './symLogScale'
import { createSymlogScale } from './symlogScale'

type XY = ReturnType<typeof generateSeriesXY>

Expand Down Expand Up @@ -72,7 +72,7 @@ export function computeScale<Input extends ScaleValue>(
case 'log':
return createLogScale(spec, data, size, axis)
case 'symlog':
return createSymLogScale(spec, data, size, axis)
return createSymlogScale(spec, data, size, axis)
default:
throw new Error('invalid scale spec')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/scales/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './compute'
export * from './linearScale'
export * from './logScale'
export * from './symLogScale'
export * from './symlogScale'
export * from './pointScale'
export * from './timeScale'
export * from './timeHelpers'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { scaleSymlog } from 'd3-scale'
import { ComputedSerieAxis, ScaleAxis, ScaleSymLog, ScaleSymLogSpec } from './types'
import { ComputedSerieAxis, ScaleAxis, ScaleSymlog, ScaleSymlogSpec } from './types'

export const createSymLogScale = (
{ constant = 1, min = 'auto', max = 'auto', reverse = false }: ScaleSymLogSpec,
export const createSymlogScale = (
{ constant = 1, min = 'auto', max = 'auto', reverse = false }: ScaleSymlogSpec,
data: ComputedSerieAxis<number>,
size: number,
axis: ScaleAxis
Expand All @@ -29,7 +29,7 @@ export const createSymLogScale = (
if (reverse === true) scale.domain([maxValue, minValue])
else scale.domain([minValue, maxValue])

const typedScale = scale as ScaleSymLog
const typedScale = scale as ScaleSymlog
typedScale.type = 'symlog'

return typedScale
Expand Down
8 changes: 4 additions & 4 deletions packages/scales/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type ScaleValue = NumericValue | StringValue | Date
export interface ScaleTypeToSpec {
linear: ScaleLinearSpec
log: ScaleLogSpec
symlog: ScaleSymLogSpec
symlog: ScaleSymlogSpec
point: ScalePointSpec
band: ScaleBandSpec
time: ScaleTimeSpec
Expand All @@ -30,7 +30,7 @@ export type ScaleSpec = ScaleTypeToSpec[keyof ScaleTypeToSpec]
export interface ScaleTypeToScale<Input, Output> {
linear: ScaleLinear<Output>
log: ScaleLog
symlog: ScaleSymLog
symlog: ScaleSymlog
point: ScalePoint<Input>
band: ScaleBand<Input>
time: ScaleTime<Input>
Expand Down Expand Up @@ -71,7 +71,7 @@ export interface ScaleLog extends D3ScaleLogarithmic<number, number> {
type: 'log'
}

export interface ScaleSymLogSpec {
export interface ScaleSymlogSpec {
type: 'symlog'
// default to `1`
constant?: number
Expand All @@ -81,7 +81,7 @@ export interface ScaleSymLogSpec {
max?: 'auto' | number
reverse?: boolean
}
export interface ScaleSymLog extends D3ScaleSymLog<number, number> {
export interface ScaleSymlog extends D3ScaleSymLog<number, number> {
type: 'symlog'
}

Expand Down
18 changes: 9 additions & 9 deletions packages/scales/tests/symlogScale.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { createSymLogScale } from '../src/symlogScale'
import { createSymlogScale } from '../src/symlogScale'

it(`should be able to build a symlog scale for x axis`, () => {
const scale = createSymLogScale({ type: 'symlog' }, { all: [], min: 0, max: 1 }, 100, 'x')
const scale = createSymlogScale({ type: 'symlog' }, { all: [], min: 0, max: 1 }, 100, 'x')

expect(scale(0)).toBe(0)
expect(scale(0.5)).toBe(58)
expect(scale(1)).toBe(100)
})

it(`should be able to build a symlog scale for y axis`, () => {
const scale = createSymLogScale({ type: 'symlog' }, { all: [], min: 0, max: 1 }, 100, 'y')
const scale = createSymlogScale({ type: 'symlog' }, { all: [], min: 0, max: 1 }, 100, 'y')

expect(scale(0)).toBe(100)
expect(scale(0.5)).toBe(42)
expect(scale(1)).toBe(0)
})

it(`should allow to define min value for x axis`, () => {
const scale = createSymLogScale(
const scale = createSymlogScale(
{ type: 'symlog', min: 0.5 },
{ all: [], min: 0, max: 1 },
100,
Expand All @@ -31,7 +31,7 @@ it(`should allow to define min value for x axis`, () => {
})

it(`should allow to define min value for y axis`, () => {
const scale = createSymLogScale(
const scale = createSymlogScale(
{ type: 'symlog', min: 0.5 },
{ all: [], min: 0, max: 1 },
100,
Expand All @@ -45,7 +45,7 @@ it(`should allow to define min value for y axis`, () => {
})

it(`should allow to define max value for x axis`, () => {
const scale = createSymLogScale(
const scale = createSymlogScale(
{ type: 'symlog', max: 2 },
{ all: [], min: 0, max: 1 },
100,
Expand All @@ -59,7 +59,7 @@ it(`should allow to define max value for x axis`, () => {
})

it(`should allow to define max value for y axis`, () => {
const scale = createSymLogScale(
const scale = createSymlogScale(
{ type: 'symlog', max: 2 },
{ all: [], min: 0, max: 1 },
100,
Expand All @@ -73,7 +73,7 @@ it(`should allow to define max value for y axis`, () => {
})

it(`should allow to reverse domain`, () => {
const scale = createSymLogScale(
const scale = createSymlogScale(
{ type: 'symlog', reverse: true },
{ all: [], min: 0, max: 1 },
100,
Expand All @@ -86,7 +86,7 @@ it(`should allow to reverse domain`, () => {
})

it(`should allow to adjust the constant`, () => {
const scale = createSymLogScale(
const scale = createSymlogScale(
{ type: 'symlog', constant: 0.1 },
{ all: [], min: 0, max: 1 },
100,
Expand Down

0 comments on commit c2a656e

Please sign in to comment.