Skip to content

Commit

Permalink
🧪 (slope) fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Nov 26, 2024
1 parent 67ece54 commit c9cf350
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function getSeriesName({

// if columns are plotted, use the column name
// and prepend the entity name if multiple entities can be selected
return availableEntityNames.length > 1 && canSelectMultipleEntities
return availableEntityNames.length > 1 || canSelectMultipleEntities
? `${entityName} - ${columnName}`
: columnName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,20 @@ import {
SynthesizeGDPTable,
} from "@ourworldindata/core-table"
import { ChartManager } from "../chart/ChartManager"
import { DEFAULT_SLOPE_CHART_COLOR } from "./SlopeChartConstants"
import { isNumber, OwidTableSlugs } from "@ourworldindata/utils"
import { isNumber } from "@ourworldindata/utils"

const table = SynthesizeGDPTable({ timeRange: [2000, 2010] })
const manager: ChartManager = {
table,
yColumnSlug: SampleColumnSlugs.Population,
selection: table.availableEntityNames,
}

it("can create a new slope chart", () => {
const chart = new SlopeChart({ manager })
expect(chart.series.length).toEqual(2)
})

it("slope charts can have different colors", () => {
const manager: ChartManager = {
table,
yColumnSlug: SampleColumnSlugs.Population,
colorColumnSlug: OwidTableSlugs.entityName,
}
const chart = new SlopeChart({ manager })
expect(chart.series[0].color).not.toEqual(DEFAULT_SLOPE_CHART_COLOR)
})

it("filters non-numeric values", () => {
const table = SynthesizeFruitTableWithStringValues(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ export class SlopeChart
}

@computed private get startTime(): Time {
return this.manager.startTime!
return this.transformedTable.minTime ?? 0
}

@computed private get endTime(): Time {
return this.manager.endTime!
return this.transformedTable.maxTime ?? 0
}

@computed get seriesStrategy(): SeriesStrategy {
Expand Down Expand Up @@ -396,7 +396,7 @@ export class SlopeChart
return map
}

@computed private get series(): SlopeChartSeries[] {
@computed get series(): SlopeChartSeries[] {
return this.rawSeries.filter((series) =>
this.shouldSeriesBePlotted(series)
)
Expand Down

0 comments on commit c9cf350

Please sign in to comment.