Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-ui): Fix LegendProportion radius scale #877

Merged
merged 5 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import LegendProportion from '../../../src/widgets/legend/legend-types/LegendPro
import { IntlProvider } from 'react-intl';

const DEFAULT_LEGEND = {
labels: ['0', '200']
labels: ['0', '150']
};

describe('LegendProportion', () => {
Expand All @@ -14,8 +14,8 @@ describe('LegendProportion', () => {
<LegendProportion legend={DEFAULT_LEGEND} />
</IntlProvider>
);
expect(screen.queryByText('Max: 200')).toBeInTheDocument();
expect(screen.queryByText('150')).toBeInTheDocument();
expect(screen.queryByText('Max: 150')).toBeInTheDocument();
expect(screen.queryByText('100')).toBeInTheDocument();
expect(screen.queryByText('50')).toBeInTheDocument();
expect(screen.queryByText('Min: 0')).toBeInTheDocument();
});
Expand All @@ -27,8 +27,8 @@ describe('LegendProportion', () => {
);
expect(screen.queryByText('Max')).not.toBeInTheDocument();
expect(screen.queryByText('Min')).not.toBeInTheDocument();
expect(screen.queryByText('200')).toBeInTheDocument();
expect(screen.queryByText('150')).toBeInTheDocument();
expect(screen.queryByText('100')).toBeInTheDocument();
expect(screen.queryByText('50')).toBeInTheDocument();
expect(screen.queryByText('0')).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const OpacityTextField = styled(TextField)(({ theme }) => ({
flexShrink: 0,
'input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button':
{
'-webkit-appearance': 'none',
WebkitAppearance: 'none',
margin: 0
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Typography from '../../../components/atoms/Typography';
import { useIntl } from 'react-intl';
import useImperativeIntl from '../../../hooks/useImperativeIntl';

const MAX_SIG_DIGITS = 6;

const sizes = {
0: 12,
1: 9,
Expand Down Expand Up @@ -86,20 +88,20 @@ function LegendProportion({ legend }) {
) : (
<>
<Typography variant='overline' color='textSecondary'>
{showMinMax
? `${intlConfig.formatMessage({ id: 'c4r.widgets.legend.max' })}: ${max}`
: max}
{showMinMax &&
intlConfig.formatMessage({ id: 'c4r.widgets.legend.max' }) + ': '}
{intl.formatNumber(max, { maximumSignificantDigits: MAX_SIG_DIGITS })}
</Typography>
<Typography variant='overline' color='textSecondary'>
{step2}
{intl.formatNumber(step2, { maximumSignificantDigits: MAX_SIG_DIGITS })}
</Typography>
<Typography variant='overline' color='textSecondary'>
{step1}
{intl.formatNumber(step1, { maximumSignificantDigits: MAX_SIG_DIGITS })}
</Typography>
<Typography variant='overline' color='textSecondary'>
{showMinMax
? `${intlConfig.formatMessage({ id: 'c4r.widgets.legend.min' })}: ${min}`
: min}
{showMinMax &&
intlConfig.formatMessage({ id: 'c4r.widgets.legend.min' }) + ': '}
{intl.formatNumber(min, { maximumSignificantDigits: MAX_SIG_DIGITS })}
</Typography>
</>
)}
Expand Down Expand Up @@ -149,10 +151,11 @@ function calculateRange(legend) {
return { min, max, error };
}

/**
* Calculates two evenly-spaced steps, linearly interpolated between a given
* min and max. For example, `calculateSteps(3, 12)` gives `[6, 9]`.
*/
function calculateSteps(min, max) {
const gap = (max + min) / 4;
const step1 = min + gap;
const step2 = max - gap;

return [step1, step2];
const step = (max - min) / 3;
return [min + step, max - step];
}
Loading