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

[legend] fix legend threshold. fixes #157 #166

Merged
merged 1 commit into from
Oct 6, 2017
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
9 changes: 5 additions & 4 deletions packages/vx-demo/components/tiles/legends.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ const ordinalShape = scaleOrdinal({
left={50 / 6}
fill="#df905f"
/>,
props =>
props => (
<text fontSize="12" dy="1em" dx=".33em" fill="#e0a346">
$
</text>,
</text>
),
],
});

const threshold = scaleThreshold({
domain: [0.02, 0.04, 0.06, 0.08, 0.1],
domain: [0.01, 0.02, 0.04, 0.06, 0.08, 0.1],
range: [
'#f2f0f7',
'#dadaeb',
Expand Down Expand Up @@ -103,7 +104,7 @@ function LegendDemo({ title, children }) {
{children}
<style jsx>{`
.legend {
line-height: .9em;
line-height: 0.9em;
color: #efefef;
font-size: 10px;
font-family: arial;
Expand Down
17 changes: 12 additions & 5 deletions packages/vx-legend/src/legends/Threshold.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,24 @@ function defaultTransform({
}) {
return ({ scale, labelFormat }) => {
function format(labelFormat, value, i) {
return labelFormat(value, i) || '';
const formattedValue = labelFormat(value, i);
if (formattedValue === 0) return '0';
return formattedValue || '';
}
return (d, i) => {
let [x0, x1] = scale.invertExtent(d);
let delimiter = ` ${labelDelimiter} `;
let value = x1;
if (!x0) {
let value;
if (x0 !== 0 && !x0 && (x1 === 0 || !!x1)) {
// lower threshold
value = x1 - 1;
delimiter = labelLower;
}
if (!x1) {
} else if ((x0 === 0 || !!x0) && (x1 === 0 || !!x1)) {
// threshold step
value = x0;
} else if (!x1 && (x0 === 0 || !!x0)) {
// upper threshold
value = x0 + scale.domain()[1];
x1 = x0;
x0 = undefined;
delimiter = labelUpper;
Expand Down