|
Last change
on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | import { isWellFormedNumberDomain } from '../../../util/isDomainSpecifiedByUser';
|
|---|
| 2 | import { isWellBehavedNumber } from '../../../util/isWellBehavedNumber';
|
|---|
| 3 |
|
|---|
| 4 | /**
|
|---|
| 5 | * This function validates and transforms the axis domain so that it is safe to use in the provided scale.
|
|---|
| 6 | */
|
|---|
| 7 | export var combineCheckedDomain = (realScaleType, axisDomain) => {
|
|---|
| 8 | if (axisDomain == null) {
|
|---|
| 9 | return undefined;
|
|---|
| 10 | }
|
|---|
| 11 | switch (realScaleType) {
|
|---|
| 12 | case 'linear':
|
|---|
| 13 | {
|
|---|
| 14 | /*
|
|---|
| 15 | * linear scale only reads the first two numbers in the domain, and ignores everything else.
|
|---|
| 16 | * So if it happens that someone somehow gave us a bigger domain,
|
|---|
| 17 | * let's pick the min and max from it.
|
|---|
| 18 | */
|
|---|
| 19 | if (!isWellFormedNumberDomain(axisDomain)) {
|
|---|
| 20 | var min, max;
|
|---|
| 21 | for (var i = 0; i < axisDomain.length; i++) {
|
|---|
| 22 | var value = axisDomain[i];
|
|---|
| 23 | if (!isWellBehavedNumber(value)) {
|
|---|
| 24 | continue;
|
|---|
| 25 | }
|
|---|
| 26 | if (min === undefined || value < min) {
|
|---|
| 27 | min = value;
|
|---|
| 28 | }
|
|---|
| 29 | if (max === undefined || value > max) {
|
|---|
| 30 | max = value;
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 | if (min !== undefined && max !== undefined) {
|
|---|
| 34 | return [min, max];
|
|---|
| 35 | }
|
|---|
| 36 | return undefined;
|
|---|
| 37 | }
|
|---|
| 38 | return axisDomain;
|
|---|
| 39 | }
|
|---|
| 40 | default:
|
|---|
| 41 | return axisDomain;
|
|---|
| 42 | }
|
|---|
| 43 | }; |
|---|
Note:
See
TracBrowser
for help on using the repository browser.