diff --git a/packages/vx-demo/components/gallery.js b/packages/vx-demo/components/gallery.js
index b91fb09dd..a72c49662 100644
--- a/packages/vx-demo/components/gallery.js
+++ b/packages/vx-demo/components/gallery.js
@@ -676,7 +676,8 @@ export default class Gallery extends React.Component {
>
diff --git a/packages/vx-demo/components/tiles/barstackhorizontal.js b/packages/vx-demo/components/tiles/barstackhorizontal.js
index b97a94ba8..d53ad42e7 100644
--- a/packages/vx-demo/components/tiles/barstackhorizontal.js
+++ b/packages/vx-demo/components/tiles/barstackhorizontal.js
@@ -9,6 +9,21 @@ import { withTooltip, Tooltip } from '@vx/tooltip';
import { LegendOrdinal } from '@vx/legend';
import { extent, max } from 'd3-array';
+const data = cityTemperature.slice(0, 12);
+const keys = Object.keys(data[0]).filter(d => d !== 'date');
+const parseDate = timeParse('%Y%m%d');
+const format = timeFormat('%b %d');
+const formatDate = date => format(parseDate(date));
+
+const totals = data.reduce((ret, cur) => {
+ const t = keys.reduce((dailyTotal, k) => {
+ dailyTotal += +cur[k];
+ return dailyTotal;
+ }, 0);
+ ret.push(t);
+ return ret;
+}, []);
+
export default withTooltip(
({
width,
@@ -16,55 +31,42 @@ export default withTooltip(
events = false,
margin = {
top: 40,
- left: 0,
+ left: 50,
+ right: 40,
+ bottom: 100,
},
tooltipOpen,
tooltipLeft,
tooltipTop,
tooltipData,
hideTooltip,
- showTooltip
+ showTooltip,
}) => {
if (width < 10) return null;
- const data = cityTemperature.slice(0, 12);
- const keys = Object.keys(data[0]).filter(d => d !== 'date');
- const parseDate = timeParse('%Y%m%d');
- const format = timeFormat('%b %d');
- const formatDate = date => format(parseDate(date));
-
// accessors
const y = d => d.date;
const x = d => d.value;
-
- const totals = data.reduce((ret, cur) => {
- const t = keys.reduce((dailyTotal, k) => {
- dailyTotal += +cur[k];
- return dailyTotal;
- }, 0);
- ret.push(t);
- return ret;
- }, []);
// bounds
- const xMax = width;
- const yMax = height - margin.top - 100;
+ const xMax = width - margin.left - margin.right;
+ const yMax = height - margin.top - margin.bottom;
// // scales
const xScale = scaleLinear({
rangeRound: [0, xMax],
- domain: [0, max(totals)],
- nice: true,
+ domain: [0, max(totals)],
+ nice: true,
});
const yScale = scaleBand({
rangeRound: [yMax, 0],
- domain: data.map(y),
+ domain: data.map(y),
padding: 0.2,
- tickFormat: () => val => formatDate(val)
+ tickFormat: () => val => formatDate(val),
});
const zScale = scaleOrdinal({
domain: keys,
- range: ['#6c5efb', '#c998ff', '#a44afe']
+ range: ['#6c5efb', '#c998ff', '#a44afe'],
});
let tooltipTimeout;
@@ -77,63 +79,61 @@ export default withTooltip(
y={0}
width={width}
height={height}
- fill='#eaedff'
+ fill="#eaedff"
rx={14}
/>
-
event => {
- if (!events) return;
- alert(`clicked: ${JSON.stringify(data)}`);
- }}
- onMouseLeave={data => event => {
- tooltipTimeout = setTimeout(() => {
- hideTooltip();
- }, 300);
- }}
- onMouseMove={data => event => {
- if (tooltipTimeout) clearTimeout(tooltipTimeout);
- showTooltip({
- tooltipData: data,
- tooltipTop: margin.top + yScale(y(data.data)),
- tooltipLeft: margin.left + data.width + 75,
- });
- }}
- />
- ({
- fill: '#a44afe',
- fontSize: 11,
- textAnchor: 'middle',
- })}
- />
- ({
- fill: '#a44afe',
- fontSize: 11,
- textAnchor: 'middle',
- })}
- />
+
+ event => {
+ if (!events) return;
+ alert(`clicked: ${JSON.stringify(data)}`);
+ }}
+ onMouseLeave={data => event => {
+ tooltipTimeout = setTimeout(() => {
+ hideTooltip();
+ }, 300);
+ }}
+ onMouseMove={data => event => {
+ if (tooltipTimeout) clearTimeout(tooltipTimeout);
+ showTooltip({
+ tooltipData: data,
+ tooltipTop: margin.top + yScale(y(data.data)),
+ tooltipLeft: margin.left + data.width + 75,
+ });
+ }}
+ />
+ ({
+ fill: '#a44afe',
+ fontSize: 11,
+ textAnchor: 'end',
+ dy: '0.33em',
+ })}
+ />
+ ({
+ fill: '#a44afe',
+ fontSize: 11,
+ textAnchor: 'middle',
+ })}
+ />
+
- {tooltipOpen &&
+ {tooltipOpen && (
-
- {tooltipData.key}
-
-
-
- {tooltipData.data[tooltipData.key]}℉
+ {tooltipData.key}
+ {tooltipData.data[tooltipData.key]}℉
-
- {tooltipData.xFormatted}
-
+ {tooltipData.xFormatted}
- }
+
+ )}
);
- }
-);
\ No newline at end of file
+ },
+);
diff --git a/packages/vx-demo/components/tiles/radar.js b/packages/vx-demo/components/tiles/radar.js
index 5222d5083..b5873fb79 100644
--- a/packages/vx-demo/components/tiles/radar.js
+++ b/packages/vx-demo/components/tiles/radar.js
@@ -6,38 +6,39 @@ import { Point } from '@vx/point';
import { Line, LineRadial } from '@vx/shape';
import { max, min } from 'd3-array';
-
const ANG = 360;
-const _data = letterFrequency.slice(2, 12);
-const calcAxis = (length) => {
+const data = letterFrequency.slice(2, 12);
+const calcAxis = length => {
if (!length) return [];
- else return new Array(length + 1)
- .fill(0).map((v, i) => ({ angle: i * (ANG / length)}));
-}
+ else
+ return new Array(length + 1)
+ .fill(0)
+ .map((v, i) => ({ angle: i * (ANG / length) }));
+};
-function calcPoints (length, radius) {
+function calcPoints(length, radius) {
const step = Math.PI * 2 / length;
- return new Array(length)
- .fill(0).map((v, i) => {
- return {
- x: radius * Math.sin(i * step),
- y: radius * Math.cos(i * step),
- }
- });
+ return new Array(length).fill(0).map((v, i) => {
+ return {
+ x: radius * Math.sin(i * step),
+ y: radius * Math.cos(i * step),
+ };
+ });
}
-function calcCoordinates (data, scale, access) {
+function calcCoordinates(data, scale, access) {
const step = Math.PI * 2 / data.length;
const points = new Array(data.length).fill({});
const pointStr = new Array(data.length + 1)
- .fill('').reduce((res, v, i) => {
- if (i > data.length) return res;
- const x = scale(access(data[i - 1])) * Math.sin(i * step);
- const y = scale(access(data[i - 1])) * Math.cos(i * step);
- points[i - 1] = { x, y };
- return res += `${x},${y} `;
- });
+ .fill('')
+ .reduce((res, v, i) => {
+ if (i > data.length) return res;
+ const x = scale(access(data[i - 1])) * Math.sin(i * step);
+ const y = scale(access(data[i - 1])) * Math.cos(i * step);
+ points[i - 1] = { x, y };
+ return (res += `${x},${y} `);
+ });
points.str = pointStr;
return points;
@@ -47,14 +48,17 @@ export default ({
width,
height,
events = false,
- margin = { top: 80, left: 80, right: 80, bottom: 80 },
+ margin = { top: 40, left: 80, right: 80, bottom: 80 },
levels = 5,
}) => {
if (width < 10) return null;
- const webs = calcAxis(_data.length);
- const radius = min([width, height]) / 2 - max(Object.values(margin));
- const points = calcPoints(_data.length, radius);
+ const xMax = width - margin.left - margin.right;
+ const yMax = height - margin.top - margin.bottom;
+
+ const webs = calcAxis(data.length);
+ const radius = min([xMax, yMax]) / 2;
+ const points = calcPoints(data.length, radius);
const labelMargin = max(Object.values(margin)) - 20;
const x = d => d.letter;
@@ -67,38 +71,36 @@ export default ({
const yScale = scaleLinear({
range: [0, radius],
- domain: [0, max(_data, y)],
+ domain: [0, max(data, y)],
});
- const polyPoints = calcCoordinates(_data, yScale, y);
+ const polyPoints = calcCoordinates(data, yScale, y);
return (