From 70a73b7c6018c3ce3c071a7c5c38d9f57919a778 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 29 Sep 2020 22:13:25 +1000 Subject: [PATCH] "fix" ts failing in CI due to improved upstream type signatures ...by throwing non-null assertions everywhere. --- ts/package.json | 18 +++++++++--------- ts/src/stats/added.ts | 2 +- ts/src/stats/buttons.ts | 10 +++++----- ts/src/stats/calendar.ts | 8 ++++---- ts/src/stats/future-due.ts | 2 +- ts/src/stats/histogram-graph.ts | 22 +++++++++++----------- ts/src/stats/hours.ts | 12 ++++++------ ts/src/stats/intervals.ts | 2 +- ts/src/stats/reviews.ts | 32 ++++++++++++++++---------------- 9 files changed, 54 insertions(+), 54 deletions(-) diff --git a/ts/package.json b/ts/package.json index 02e5ecca2..b7189e015 100644 --- a/ts/package.json +++ b/ts/package.json @@ -9,7 +9,7 @@ "@pyoner/svelte-types": "^3.4.4-2", "@types/d3-array": "^2.0.0", "@types/d3-axis": "^1.0.12", - "@types/d3-scale": "^2.2.0", + "@types/d3-scale": "^2.2.1", "@types/d3-scale-chromatic": "^1.5.0", "@types/d3-selection": "^1.4.1", "@types/d3-shape": "^1.3.2", @@ -27,19 +27,19 @@ "eslint": "^6.7.2", "eslint-loader": "^4.0.2", "eslint-plugin-svelte3": "^2.7.3", - "html-webpack-plugin": "^4.3.0", - "prettier": "^2.1.1", - "prettier-plugin-svelte": "^1.1.1", - "sass": "^1.26.9", + "html-webpack-plugin": "^4.5.0", + "prettier": "^2.1.2", + "prettier-plugin-svelte": "^1.4.0", + "sass": "^1.26.11", "sass-loader": "^8.0.2", "style-loader": "^1.2.1", - "svelte": "^3.23.2", + "svelte": "^3.28.0", "svelte-check": "^0.1.59", "svelte-loader": "^2.13.6", "svelte-preprocess": "^3.9.9", "ts-loader": "^7.0.5", "typescript": "^3.9.7", - "webpack": "^4.44.0", + "webpack": "^4.44.2", "webpack-cli": "^3.3.11", "webpack-dev-server": "^3.11.0" }, @@ -51,10 +51,10 @@ }, "dependencies": { "@fluent/bundle": "^0.15.1", - "d3-array": "^2.6.0", + "d3-array": "^2.8.0", "d3-axis": "^1.0.12", "d3-interpolate": "^1.4.0", - "d3-scale": "^3.2.2", + "d3-scale": "^3.2.3", "d3-scale-chromatic": "^1.5.0", "d3-selection": "^1.4.2", "d3-shape": "^1.3.7", diff --git a/ts/src/stats/added.ts b/ts/src/stats/added.ts index 881abf07f..4e89479a3 100644 --- a/ts/src/stats/added.ts +++ b/ts/src/stats/added.ts @@ -70,7 +70,7 @@ export function buildHistogram( const adjustedRange = scaleLinear().range([0.7, 0.3]); const colourScale = scaleSequential((n) => - interpolateBlues(adjustedRange(n)) + interpolateBlues(adjustedRange(n)!) ).domain([xMax!, xMin!]); const totalInPeriod = sum(bins, (bin) => bin.length); diff --git a/ts/src/stats/buttons.ts b/ts/src/stats/buttons.ts index ea822189e..d982da558 100644 --- a/ts/src/stats/buttons.ts +++ b/ts/src/stats/buttons.ts @@ -204,7 +204,7 @@ export function renderButtons( (d: Datum) => xGroup(d.group)! + xButton(d.buttonNum.toString())! ) .attr("y", (d: Datum) => y(d.count)!) - .attr("height", (d: Datum) => y(0) - y(d.count)) + .attr("height", (d: Datum) => y(0)! - y(d.count)!) .attr("fill", (d: Datum) => colour(d.buttonNum)); }; @@ -221,13 +221,13 @@ export function renderButtons( (d: Datum) => xGroup(d.group)! + xButton(d.buttonNum.toString())! ) - .attr("y", y(0)) + .attr("y", y(0)!) .attr("height", 0) .call(updateBar), (update) => update.call(updateBar), (remove) => remove.call((remove) => - remove.transition(trans).attr("height", 0).attr("y", y(0)) + remove.transition(trans).attr("height", 0).attr("y", y(0)!) ) ); @@ -248,9 +248,9 @@ export function renderButtons( .data(data) .join("rect") .attr("x", (d: Datum) => xGroup(d.group)! + xButton(d.buttonNum.toString())!) - .attr("y", () => y(yMax!)) + .attr("y", () => y(yMax!)!) .attr("width", xButton.bandwidth()) - .attr("height", () => y(0) - y(yMax!)) + .attr("height", () => y(0)! - y(yMax!)!) .on("mousemove", function (this: any, d: Datum) { const [x, y] = mouse(document.body); showTooltip(tooltipText(d), x, y); diff --git a/ts/src/stats/calendar.ts b/ts/src/stats/calendar.ts index 760d5d0a4..a0eb793ae 100644 --- a/ts/src/stats/calendar.ts +++ b/ts/src/stats/calendar.ts @@ -118,7 +118,7 @@ export function renderCalendar( } const data = Array.from(dayMap.values()); const cappedRange = scaleLinear().range([0.2, nightMode ? 0.8 : 1]); - const blues = scaleSequential((n) => interpolateBlues(cappedRange(n))).domain([ + const blues = scaleSequential((n) => interpolateBlues(cappedRange(n)!)).domain([ 0, maxCount, ]); @@ -145,10 +145,10 @@ export function renderCalendar( .join("rect") .attr("fill", emptyColour) .attr("width", (d) => { - return x(d.weekNumber + 1) - x(d.weekNumber) - 2; + return x(d.weekNumber + 1)! - x(d.weekNumber)! - 2; }) .attr("height", height - 2) - .attr("x", (d) => x(d.weekNumber)) + .attr("x", (d) => x(d.weekNumber)!) .attr("y", (d) => bounds.marginTop + d.weekDay * height) .on("mousemove", function (this: any, d: any) { const [x, y] = mouse(document.body); @@ -161,7 +161,7 @@ export function renderCalendar( if (d.count === 0) { return emptyColour; } else { - return blues(d.count); + return blues(d.count)!; } }); } diff --git a/ts/src/stats/future-due.ts b/ts/src/stats/future-due.ts index 615e58573..f7017f91c 100644 --- a/ts/src/stats/future-due.ts +++ b/ts/src/stats/future-due.ts @@ -118,7 +118,7 @@ export function buildHistogram( const adjustedRange = scaleLinear().range([0.7, 0.3]); const colourScale = scaleSequential((n) => - interpolateGreens(adjustedRange(n)) + interpolateGreens(adjustedRange(n)!) ).domain([xMin!, xMax!]); const total = sum(bins as any, binValue); diff --git a/ts/src/stats/histogram-graph.ts b/ts/src/stats/histogram-graph.ts index 2e590ad7f..8f01d5fa5 100644 --- a/ts/src/stats/histogram-graph.ts +++ b/ts/src/stats/histogram-graph.ts @@ -76,7 +76,7 @@ export function histogramGraph( // x bars function barWidth(d: any): number { - const width = Math.max(0, x(d.x1) - x(d.x0) - 1); + const width = Math.max(0, x(d.x1)! - x(d.x0)! - 1); return width ? width : 0; } @@ -86,7 +86,7 @@ export function histogramGraph( .transition(trans) .attr("x", (d: any) => x(d.x0)) .attr("y", (d: any) => y(binValue(d))!) - .attr("height", (d: any) => y(0) - y(binValue(d))) + .attr("height", (d: any) => y(0)! - y(binValue(d))!) .attr("fill", (d) => data.colourScale(d.x1)); }; @@ -98,14 +98,14 @@ export function histogramGraph( enter .append("rect") .attr("rx", 1) - .attr("x", (d: any) => x(d.x0)) - .attr("y", y(0)) + .attr("x", (d: any) => x(d.x0)!) + .attr("y", y(0)!) .attr("height", 0) .call(updateBar), (update) => update.call(updateBar), (remove) => remove.call((remove) => - remove.transition(trans).attr("height", 0).attr("y", y(0)) + remove.transition(trans).attr("height", 0).attr("y", y(0)!) ) ); @@ -133,13 +133,13 @@ export function histogramGraph( .curve(curveBasis) .x((d, idx) => { if (idx === 0) { - return x(data.bins[0].x0!); + return x(data.bins[0].x0!)!; } else { - return x(data.bins[idx - 1].x1!); + return x(data.bins[idx - 1].x1!)!; } }) .y0(bounds.height - bounds.marginBottom) - .y1((d: any) => yAreaScale(d)) as any + .y1((d: any) => yAreaScale(d)!) as any ); } @@ -148,10 +148,10 @@ export function histogramGraph( .selectAll("rect") .data(data.bins) .join("rect") - .attr("x", (d: any) => x(d.x0)) - .attr("y", () => y(yMax!)) + .attr("x", (d: any) => x(d.x0)!) + .attr("y", () => y(yMax!)!) .attr("width", barWidth) - .attr("height", () => y(0) - y(yMax!)) + .attr("height", () => y(0)! - y(yMax!)!) .on("mousemove", function (this: any, d: any, idx) { const [x, y] = mouse(document.body); const pct = data.showArea ? (areaData[idx + 1] / data.total) * 100 : 0; diff --git a/ts/src/stats/hours.ts b/ts/src/stats/hours.ts index ffee50329..cb592d8fd 100644 --- a/ts/src/stats/hours.ts +++ b/ts/src/stats/hours.ts @@ -96,7 +96,7 @@ export function renderHours( }); const cappedRange = scaleLinear().range([0.1, 0.8]); - const colour = scaleSequential((n) => interpolateBlues(cappedRange(n))).domain([ + const colour = scaleSequential((n) => interpolateBlues(cappedRange(n)!)).domain([ 0, yMax, ]); @@ -125,7 +125,7 @@ export function renderHours( .transition(trans) .attr("x", (d: Hour) => x(d.hour.toString())!) .attr("y", (d: Hour) => y(d.totalCount)!) - .attr("height", (d: Hour) => y(0) - y(d.totalCount)) + .attr("height", (d: Hour) => y(0)! - y(d.totalCount)!) .attr("fill", (d: Hour) => colour(d.totalCount!)); }; @@ -138,14 +138,14 @@ export function renderHours( .append("rect") .attr("rx", 1) .attr("x", (d: Hour) => x(d.hour.toString())!) - .attr("y", y(0)) + .attr("y", y(0)!) .attr("height", 0) // .attr("opacity", 0.7) .call(updateBar), (update) => update.call(updateBar), (remove) => remove.call((remove) => - remove.transition(trans).attr("height", 0).attr("y", y(0)) + remove.transition(trans).attr("height", 0).attr("y", y(0)!) ) ); @@ -171,7 +171,7 @@ export function renderHours( .y0(bounds.height - bounds.marginBottom) .y1((d: Hour) => { const correctRatio = d.correctCount! / d.totalCount!; - return yArea(isNaN(correctRatio) ? 0 : correctRatio); + return yArea(isNaN(correctRatio) ? 0 : correctRatio)!; }) ); @@ -196,7 +196,7 @@ export function renderHours( .attr("x", (d: Hour) => x(d.hour.toString())!) .attr("y", () => y(yMax)!) .attr("width", x.bandwidth()) - .attr("height", () => y(0) - y(yMax!)) + .attr("height", () => y(0)! - y(yMax!)!) .on("mousemove", function (this: any, d: Hour) { const [x, y] = mouse(document.body); showTooltip(tooltipText(d), x, y); diff --git a/ts/src/stats/intervals.ts b/ts/src/stats/intervals.ts index 18275c03d..da6e7f11c 100644 --- a/ts/src/stats/intervals.ts +++ b/ts/src/stats/intervals.ts @@ -103,7 +103,7 @@ export function prepareIntervalData( const adjustedRange = scaleLinear().range([0.7, 0.3]); const colourScale = scaleSequential((n) => - interpolateBlues(adjustedRange(n)) + interpolateBlues(adjustedRange(n)!) ).domain([xMax!, xMin!]); function hoverText( diff --git a/ts/src/stats/reviews.ts b/ts/src/stats/reviews.ts index a33b878a8..cb77c535e 100644 --- a/ts/src/stats/reviews.ts +++ b/ts/src/stats/reviews.ts @@ -191,25 +191,25 @@ export function renderReviews( // x bars function barWidth(d: any): number { - const width = Math.max(0, x(d.x1) - x(d.x0) - 1); + const width = Math.max(0, x(d.x1)! - x(d.x0)! - 1); return width ? width : 0; } const cappedRange = scaleLinear().range([0.3, 0.5]); const shiftedRange = scaleLinear().range([0.4, 0.7]); const darkerGreens = scaleSequential((n) => - interpolateGreens(shiftedRange(n)) + interpolateGreens(shiftedRange(n)!) ).domain(x.domain() as any); const lighterGreens = scaleSequential((n) => - interpolateGreens(cappedRange(n)) + interpolateGreens(cappedRange(n)!) ).domain(x.domain() as any); - const blues = scaleSequential((n) => interpolateBlues(cappedRange(n))).domain( + const blues = scaleSequential((n) => interpolateBlues(cappedRange(n)!)).domain( x.domain() as any ); - const reds = scaleSequential((n) => interpolateReds(cappedRange(n))).domain( + const reds = scaleSequential((n) => interpolateReds(cappedRange(n)!)).domain( x.domain() as any ); - const oranges = scaleSequential((n) => interpolateOranges(cappedRange(n))).domain( + const oranges = scaleSequential((n) => interpolateOranges(cappedRange(n)!)).domain( x.domain() as any ); @@ -269,7 +269,7 @@ export function renderReviews( .transition(trans) .attr("x", (d: any) => x(d.x0)) .attr("y", (d: any) => y(cumulativeBinValue(d, idx))!) - .attr("height", (d: any) => y(0) - y(cumulativeBinValue(d, idx))) + .attr("height", (d: any) => y(0)! - y(cumulativeBinValue(d, idx))!) .attr("fill", (d: any) => { switch (idx) { case 0: @@ -295,14 +295,14 @@ export function renderReviews( enter .append("rect") .attr("rx", 1) - .attr("x", (d: any) => x(d.x0)) - .attr("y", y(0)) + .attr("x", (d: any) => x(d.x0)!) + .attr("y", y(0)!) .attr("height", 0) .call((d) => updateBar(d, barNum)), (update) => update.call((d) => updateBar(d, barNum)), (remove) => remove.call((remove) => - remove.transition(trans).attr("height", 0).attr("y", y(0)) + remove.transition(trans).attr("height", 0).attr("y", y(0)!) ) ); } @@ -333,13 +333,13 @@ export function renderReviews( .curve(curveBasis) .x((d, idx) => { if (idx === 0) { - return x(bins[0].x0!); + return x(bins[0].x0!)!; } else { - return x(bins[idx - 1].x1!); + return x(bins[idx - 1].x1!)!; } }) .y0(bounds.height - bounds.marginBottom) - .y1((d: any) => yAreaScale(d)) as any + .y1((d: any) => yAreaScale(d)!) as any ); } @@ -348,10 +348,10 @@ export function renderReviews( .selectAll("rect") .data(bins) .join("rect") - .attr("x", (d: any) => x(d.x0)) - .attr("y", () => y(yMax!)) + .attr("x", (d: any) => x(d.x0)!) + .attr("y", () => y(yMax!)!) .attr("width", barWidth) - .attr("height", () => y(0) - y(yMax!)) + .attr("height", () => y(0)! - y(yMax!)!) .on("mousemove", function (this: any, d: any, idx) { const [x, y] = mouse(document.body); showTooltip(tooltipText(d, areaData[idx + 1]), x, y);