-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import mitt from 'mitt' | ||
|
||
type Events = { | ||
scaleXUpdated: void, | ||
scaleYUpdated: void, | ||
} | ||
|
||
export const emitter = mitt<Events>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,88 @@ | ||
import { ScaleLinear, scaleLinear } from 'd3' | ||
import { application } from '@/objects/application' | ||
import { emitter } from '@/objects/events' | ||
|
||
export let scaleX: ScaleLinear<number, number> | ||
export let scaleY: ScaleLinear<number, number> | ||
|
||
// these are the same for now but ScaleXDomain will eventually be [Date, Date] | ||
type ScaleRange = [start: number, end: number] | ||
type ScaleXDomain = [start: number, end: number] | ||
type ScaleYDomain = [start: number, end: number] | ||
|
||
export function createScales(): void { | ||
createScaleX() | ||
createScaleY() | ||
} | ||
|
||
export function createScaleX(): void { | ||
scaleX = scaleLinear().range([0, application.view.width]).domain([0, 100]) | ||
const range: ScaleRange = [0, application.view.width] | ||
const domain: ScaleXDomain = [0, 100] | ||
|
||
scaleX = scaleLinear() | ||
|
||
setScaleX({ range, domain, silent: true }) | ||
} | ||
|
||
type XScale = { | ||
domain?: ScaleXDomain, | ||
range?: ScaleRange, | ||
silent?: boolean, | ||
} | ||
|
||
// this needs to be clamped to some minimum range | ||
export function setScaleX({ domain, range, silent }: XScale): void { | ||
if (range) { | ||
scaleX.range(range) | ||
} | ||
|
||
if (domain) { | ||
scaleX.domain(domain) | ||
} | ||
|
||
if (!silent && (range || domain)) { | ||
emitter.emit('scaleXUpdated') | ||
} | ||
} | ||
|
||
export function createScaleY(): void { | ||
scaleY = scaleLinear().range([0, application.view.height]).domain([0, 100]) | ||
const range: ScaleRange = [0, application.view.height] | ||
const domain: ScaleYDomain = [0, 100] | ||
|
||
scaleY = scaleLinear() | ||
|
||
setScaleY({ range, domain, silent: true }) | ||
} | ||
|
||
export function setScaleXZoom(zoom: number): void { | ||
type YScale = { | ||
domain?: ScaleYDomain, | ||
range?: ScaleRange, | ||
silent?: boolean, | ||
} | ||
|
||
// this needs to be clamped to some minimum range | ||
export function setScaleY({ domain, range, silent }: YScale): void { | ||
if (range) { | ||
scaleY.range(range) | ||
} | ||
|
||
const start = 0 | ||
const interval = application.view.width * 0.2 | ||
if (domain) { | ||
scaleY.domain(domain) | ||
} | ||
|
||
if (!silent && (range || domain)) { | ||
emitter.emit('scaleYUpdated') | ||
} | ||
} | ||
|
||
// proof of concept based on a static number | ||
// my guess is rather than accepting a static zoom | ||
// the multiplier would be accepted so a scroll event could pass a positive or negative value | ||
export function setScaleXZoom(zoom: number): void { | ||
const multiplier = 0.2 | ||
const interval = application.view.width * multiplier | ||
const rangeEnd = application.view.width + zoom * interval | ||
console.log(zoom, rangeEnd) | ||
const range: ScaleRange = [0, rangeEnd] | ||
|
||
scaleX.range([start, rangeEnd]) | ||
setScaleX({ range }) | ||
} |