-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FOROME-804): implemented logarithmic scale for Y-axis in range s…
…lider histogram (#528) * feat(FOROME-739): implemented histograms for numeric attributes in sidebar * feat(FOROME-739): implemented histogram, bar chart and pie chart with d3.js * feat(FOROME-804): implemented logarithmic scale for Y-axis in range slider histogram
- Loading branch information
Showing
10 changed files
with
103 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as d3 from 'd3' | ||
|
||
import { formatNumber } from '@core/format-number' | ||
|
||
export const getBounds = <T>( | ||
data: T[], | ||
valueGetter: (item: T) => number, | ||
): [number, number] => { | ||
let min = valueGetter(data[0]) | ||
let max = min | ||
|
||
for (const item of data) { | ||
const value = valueGetter(item) | ||
min = Math.min(min, value) | ||
max = Math.max(max, value) | ||
} | ||
|
||
return [min, max] | ||
} | ||
|
||
type TGetYScaleAndAxisParams = { | ||
min: number | ||
max: number | ||
height: number | ||
minTickDistance?: number | ||
} | ||
|
||
export const getYScaleAndAxis = ({ | ||
min, | ||
max, | ||
height, | ||
minTickDistance = 36, | ||
}: TGetYScaleAndAxisParams): [ | ||
d3.ScaleContinuousNumeric<number, number>, | ||
d3.Axis<number>, | ||
] => { | ||
const logMin = Math.max(Math.floor(Math.log10(min)), 0) | ||
const logMax = Math.ceil(Math.log10(max)) | ||
|
||
const isLogScale = logMax - logMin >= 3 | ||
const scale = isLogScale ? d3.scaleLog() : d3.scaleLinear() | ||
scale.range([height, 0]) | ||
|
||
if (isLogScale) { | ||
scale.domain([Math.pow(10, logMin), max]) | ||
} else { | ||
scale.domain([0, max]) | ||
} | ||
|
||
const ticksCount = Math.min( | ||
Math.floor(height / minTickDistance) + 1, | ||
isLogScale ? logMax - logMin - 1 : 4, | ||
) | ||
|
||
const axis = d3 | ||
.axisLeft<number>(scale) | ||
.ticks(ticksCount) | ||
.tickFormat(formatNumber) | ||
|
||
return [scale, axis] | ||
} |
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
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,3 +1,2 @@ | ||
export * from './reduceVariantsData' | ||
export * from './scaling' | ||
export * from './useChartConfig' |
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
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