Skip to content

Commit

Permalink
Apply styling for empty color
Browse files Browse the repository at this point in the history
  • Loading branch information
adorack committed Jan 10, 2025
1 parent 74fc7fd commit 5bbcfac
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ const positionToClass = (position: `${ChartLegendPosition}`) => {
margin-top: 0;
.label {
line-height: $kui-line-height-40;
padding-right: $kui-space-10; // Ensure italics text doesn't get cut off.
white-space: nowrap;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ ul.tooltip {
}
li {
align-items: center;
display: flex;
font-size: var(--kui-font-size-30, $kui-font-size-30);
line-height: 1;
margin: var(--kui-space-40, $kui-space-40);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('useVitalsExploreDatasets', () => {
{ label: 'ThenBy1', backgroundColor: '#a86cd5', data: [null, 100], isSegmentEmpty: false },
{ label: 'ThenBy3', backgroundColor: '#6a86d2', data: [200, null], isSegmentEmpty: false },
{ label: 'ThenBy4', backgroundColor: '#00bbf9', data: [250, null], isSegmentEmpty: false },
{ label: 'ThenBy2', backgroundColor: '#00c4b0', data: [null, 150], isSegmentEmpty: true },
{ label: 'ThenBy2', backgroundColor: '#afb7c5', data: [null, 150], isSegmentEmpty: true },
],
isLabelEmpty: [false, true],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AnalyticsExploreRecord, ExploreResultV4 } from '@kong-ui-public/analytics-utilities'
import { lookupDatavisColor, datavisPalette } from '../utils'
import { lookupDatavisColor, datavisPalette, determineBaseColor } from '../utils'
import type { Ref } from 'vue'
import { computed } from 'vue'
import type { Dataset, ExploreToDatasetDeps, KChartData, BarChartDatasetGenerationParams, DatasetLabel } from '../types'
Expand Down Expand Up @@ -35,9 +35,7 @@ function generateDatasets(dataSetGenerationParams: BarChartDatasetGenerationPara
return []
}

const baseColor = Array.isArray(colorPalette)
? lookupDatavisColor(i, colorPalette)
: colorPalette[dimension.name] || lookupDatavisColor(i) // fallback to default datavis palette if no color found
const baseColor = determineBaseColor(i, dimension.name, dimension.id === 'empty', colorPalette)

// The label here matters for the title in the tooltip and legend. It doesn't impact axes.
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { ExploreAggregations, ExploreResultV4, AnalyticsExploreRecord } from '@kong-ui-public/analytics-utilities'
import { defaultLineOptions, lookupDatavisColor, datavisPalette, BORDER_WIDTH, NO_BORDER } from '../utils'
import {
defaultLineOptions,
datavisPalette,
BORDER_WIDTH,
NO_BORDER,
determineBaseColor,
} from '../utils'
import type { Ref } from 'vue'
import { computed } from 'vue'
import type { Dataset, KChartData, ExploreToDatasetDeps, DatasetLabel } from '../types'
Expand Down Expand Up @@ -156,9 +162,7 @@ export default function useExploreResultToTimeDataset(
colorPalette = datavisPalette
}

const baseColor = Array.isArray(colorPalette)
? lookupDatavisColor(i, colorPalette)
: colorPalette[dimension] || lookupDatavisColor(i) // fallback to default datavis palette if no color found
const baseColor = determineBaseColor(i, dimension, isSegmentEmpty, colorPalette)

return {
rawDimension: dimension,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,8 @@ describe('useVitalsExploreDatasets', () => {
rawDimension: 'emptyConsumer',
rawMetric: 'request_count',
label: 'emptyConsumer',
borderColor: '#a86cd5',
backgroundColor: '#a86cd5',
borderColor: '#afb7c5',
backgroundColor: '#afb7c5',
data: [
{
x: START_FOR_DAILY_QUERY.getTime(),
Expand Down
15 changes: 15 additions & 0 deletions packages/analytics/analytics-chart/src/utils/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const latencyColors: AnalyticsChartColors = {
}

export const OTHERS_COLOR = '#dad4c7'
export const EMPTY_COLOR = '#afb7c5'

/**
* Maps the first character of a dataset's label to a predefined list of colors
Expand All @@ -120,3 +121,17 @@ export const lookupColor = (label: string) => {

return (found && found[1]) || kongManangerColorPalette.standard
}

export const determineBaseColor = (i: number, dimensionName: string, isEmpty: boolean, colorPalette: string[] | AnalyticsChartColors): string => {
let baseColor

if (isEmpty) {
baseColor = EMPTY_COLOR
} else if (Array.isArray(colorPalette)) {
baseColor = lookupDatavisColor(i, colorPalette)
} else {
baseColor = colorPalette[dimensionName]
}

return baseColor || lookupDatavisColor(i) // fallback to default datavis palette if no color found
}

0 comments on commit 5bbcfac

Please sign in to comment.