Skip to content

Commit c2578d0

Browse files
🔨 (slope) clean up
1 parent f15af23 commit c2578d0

File tree

2 files changed

+149
-161
lines changed

2 files changed

+149
-161
lines changed

packages/@ourworldindata/grapher/src/lineLegend/LineLegend.tsx

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const MARKER_MARGIN = 4
4141
// Space between the label and the annotation
4242
const ANNOTATION_PADDING = 1
4343

44-
const DEFAULT_CONNECTOR_LINE_WIDTH = 35
44+
const DEFAULT_CONNECTOR_LINE_WIDTH = 25
4545
const DEFAULT_FONT_WEIGHT = 400
4646

4747
export interface LineLabelSeries extends ChartSeries {
@@ -103,7 +103,6 @@ class LineLabels extends React.Component<{
103103
series: PlacedSeries[]
104104
uniqueKey: string
105105
needsConnectorLines: boolean
106-
connectorLineWidth?: number
107106
outlineColor?: Color
108107
anchor?: "start" | "end"
109108
isFocus?: boolean
@@ -120,10 +119,6 @@ class LineLabels extends React.Component<{
120119
return this.props.anchor ?? "start"
121120
}
122121

123-
@computed private get connectorLineWidth(): number {
124-
return this.props.connectorLineWidth ?? DEFAULT_CONNECTOR_LINE_WIDTH
125-
}
126-
127122
@computed private get outlineColor(): Color {
128123
return this.props.outlineColor ?? GRAPHER_BACKGROUND_DEFAULT
129124
}
@@ -136,7 +131,7 @@ class LineLabels extends React.Component<{
136131
return this.props.series.map((series) => {
137132
const direction = this.anchor === "start" ? 1 : -1
138133
const markerMargin = direction * MARKER_MARGIN
139-
const connectorLineWidth = direction * this.connectorLineWidth
134+
const connectorLineWidth = direction * DEFAULT_CONNECTOR_LINE_WIDTH
140135

141136
const { x } = series.origBounds
142137
const connectorLine = {
@@ -319,7 +314,6 @@ export interface LineLegendProps {
319314
verticalAlign?: VerticalAlign
320315

321316
// presentation
322-
connectorLineWidth?: number
323317
fontSize?: number
324318
fontWeight?: number
325319
outlineColor?: Color // used for halos
@@ -346,7 +340,7 @@ export class LineLegend extends React.Component<LineLegendProps> {
346340
*/
347341
static width(props: LineLegendProps): number {
348342
const test = new LineLegend(props)
349-
return test.maxLabelWidth + test.connectorLineWidth + MARKER_MARGIN
343+
return test.maxLabelWidth + DEFAULT_CONNECTOR_LINE_WIDTH + MARKER_MARGIN
350344
}
351345

352346
static fontSize(props: Partial<LineLegendProps>): number {
@@ -365,10 +359,7 @@ export class LineLegend extends React.Component<LineLegendProps> {
365359
}
366360

367361
@computed private get fontSize(): number {
368-
return Math.max(
369-
GRAPHER_FONT_SCALE_12 * (this.props.fontSize ?? BASE_FONT_SIZE),
370-
11.5
371-
)
362+
return GRAPHER_FONT_SCALE_12 * (this.props.fontSize ?? BASE_FONT_SIZE)
372363
}
373364

374365
@computed private get fontWeight(): number {
@@ -383,17 +374,13 @@ export class LineLegend extends React.Component<LineLegendProps> {
383374
return this.props.yAxis ?? new VerticalAxis(new AxisConfig())
384375
}
385376

386-
@computed private get connectorLineWidth(): number {
387-
return this.props.connectorLineWidth ?? DEFAULT_CONNECTOR_LINE_WIDTH
388-
}
389-
390377
@computed private get verticalAlign(): VerticalAlign {
391378
return this.props.verticalAlign ?? VerticalAlign.middle
392379
}
393380

394381
@computed.struct get sizedLabels(): SizedSeries[] {
395382
const { fontSize, fontWeight, maxWidth } = this
396-
const maxTextWidth = maxWidth - this.connectorLineWidth
383+
const maxTextWidth = maxWidth - DEFAULT_CONNECTOR_LINE_WIDTH
397384
const maxAnnotationWidth = Math.min(maxTextWidth, 150)
398385

399386
return this.props.labelSeries.map((label) => {
@@ -492,7 +479,7 @@ export class LineLegend extends React.Component<LineLegendProps> {
492479

493480
return this.sizedLabels.map((label) => {
494481
const labelHeight = label.height
495-
const labelWidth = label.width + this.connectorLineWidth
482+
const labelWidth = label.width + DEFAULT_CONNECTOR_LINE_WIDTH
496483

497484
const midY = yAxis.place(label.yValue)
498485
const origBounds = new Bounds(
@@ -785,7 +772,6 @@ export class LineLegend extends React.Component<LineLegendProps> {
785772
uniqueKey="background"
786773
series={this.backgroundSeries}
787774
needsConnectorLines={this.needsLines}
788-
connectorLineWidth={this.connectorLineWidth}
789775
outlineColor={this.props.outlineColor}
790776
isFocus={false}
791777
anchor={this.props.xAnchor}
@@ -805,7 +791,6 @@ export class LineLegend extends React.Component<LineLegendProps> {
805791
uniqueKey="focus"
806792
series={this.focusedSeries}
807793
needsConnectorLines={this.needsLines}
808-
connectorLineWidth={this.connectorLineWidth}
809794
outlineColor={this.props.outlineColor}
810795
isFocus={true}
811796
anchor={this.props.xAnchor}

0 commit comments

Comments
 (0)