Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const monthPathAndBBox = ({
date,
cellSize,
yearIndex,
yearSpacing,
daySpacing,
direction,
originX,
originY,
}) => {
// first day of next month
const t1 = new Date(date.getFullYear(), date.getMonth() + 1, 0)
// ranges
const firstWeek = timeWeek.count(timeYear(date), date)
const lastWeek = timeWeek.count(timeYear(t1), t1)
const firstDay = date.getDay()
const lastDay = t1.getDay()
// offset according to year index
let xO = originX
let yO = originY
const yearOffset = yearIndex * (7 * (cellSize + daySpacing) + yearSpacing)
if (direction === 'horizontal') {
yO += yearOffset
} else {
xO += yearOffset
}
let path
let bbox = { x: xO, y: yO, width: 0, height: 0 }
if (direction === 'horizontal') {
const monthPathAndBBox = ({
date,
cellSize,
yearIndex,
yearSpacing,
daySpacing,
direction,
originX,
originY,
}) => {
// first day of next month
const t1 = new Date(date.getFullYear(), date.getMonth() + 1, 0)
// ranges
const firstWeek = timeWeek.count(timeYear(date), date)
const lastWeek = timeWeek.count(timeYear(t1), t1)
const firstDay = date.getDay()
const lastDay = t1.getDay()
// offset according to year index
let xO = originX
let yO = originY
const yearOffset = yearIndex * (7 * (cellSize + daySpacing) + yearSpacing)
if (direction === 'horizontal') {
yO += yearOffset
} else {
xO += yearOffset
}
let path
let bbox = { x: xO, y: yO, width: 0, height: 0 }
function calcMonthPath(t0) {
const t1 = new Date(t0.getFullYear(), t0.getMonth() + 1, 0);
const d0 = t0.getDay();
const w0 = d3TimeWeek.count(d3TimeYear(t0), t0);
const d1 = t1.getDay();
const w1 = d3TimeWeek.count(d3TimeYear(t1), t1);
return "M" + (w0 + 1) * cellSize + "," + d0 * cellSize +
"H" + w0 * cellSize + "V" + 7 * cellSize +
"H" + w1 * cellSize + "V" + (d1 + 1) * cellSize +
"H" + (w1 + 1) * cellSize + "V" + 0 +
"H" + (w0 + 1) * cellSize + "Z";
}
}
function calcMonthPath(t0) {
const t1 = new Date(t0.getFullYear(), t0.getMonth() + 1, 0);
const d0 = t0.getDay();
const w0 = d3TimeWeek.count(d3TimeYear(t0), t0);
const d1 = t1.getDay();
const w1 = d3TimeWeek.count(d3TimeYear(t1), t1);
return "M" + (w0 + 1) * cellSize + "," + d0 * cellSize +
"H" + w0 * cellSize + "V" + 7 * cellSize +
"H" + w1 * cellSize + "V" + (d1 + 1) * cellSize +
"H" + (w1 + 1) * cellSize + "V" + 0 +
"H" + (w0 + 1) * cellSize + "Z";
}
}
return (originX, originY, d, yearIndex) => {
const weekOfYear = timeWeek.count(timeYear(d), d)
return {
x:
originX +
d.getDay() * (cellSize + daySpacing) +
daySpacing / 2 +
yearIndex * (yearSpacing + 7 * (cellSize + daySpacing)),
y: originY + weekOfYear * (cellSize + daySpacing) + daySpacing / 2,
}
}
}
.attr("x", function (d) { return d3TimeWeek.count(d3TimeYear(d), d) * cellSize; })
.attr("y", function (d) { return d.getDay() * cellSize; })