Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
fix(data-table): fix black histogram background (#3807)
Igor Dykhtade50c0edecae
diff --git a/src/components/src/common/histogram-plot.tsx b/src/components/src/common/histogram-plot.tsxindex 562f581d4..f55e0fe61 100644--- a/src/components/src/common/histogram-plot.tsx+++ b/src/components/src/common/histogram-plot.tsx@@ -23,10 +23,10 @@ const histogramStyle = {unHighlightedW: 0.7};-const HistogramWrapper = styled.svg`+const HistogramWrapper = styled.svg<{$recessed?: boolean}>`overflow: visible;border-radius: 2px;- background: ${props => props.theme.rangePlotBgd};+ background: ${props => (props.$recessed ? props.theme.rangePlotBgd : 'transparent')};`;const HistogramMaskRect = styled.rect`@@ -93,6 +93,8 @@ export interface HistogramPlotProps {countProp?: string;range?: number[];breakLines?: number[];+ /** Dark plot surface for the range brush. Column histograms leave this off. */+ recessed?: boolean;}function HistogramPlotFactory() {@@ -109,7 +111,8 @@ function HistogramPlotFactory() {range,value,brushComponent,- breakLines+ breakLines,+ recessed}: HistogramPlotProps) => {const groupKeys = useMemo(() =>@@ -183,6 +186,7 @@ function HistogramPlotFactory() {<HistogramWrapperwidth={width}height={height}+ $recessed={recessed}style={{margin: `${margin.top}px ${margin.right}px ${margin.bottom}px ${margin.left}px`}}><defs>@@ -282,6 +286,7 @@ function HistogramPlotFactory() {<HistogramWrapperwidth={width}height={height}+ $recessed={recessed}style={{margin: `${margin.top}px ${margin.right}px ${margin.bottom}px ${margin.left}px`}}><defs>diff --git a/src/components/src/common/range-plot.tsx b/src/components/src/common/range-plot.tsxindex db1168cab..d8213ef45 100644--- a/src/components/src/common/range-plot.tsx+++ b/src/components/src/common/range-plot.tsx@@ -168,6 +168,7 @@ export default function RangePlotFactory(colorsByGroup={groupColors}range={range}{...commonProps}+ recessed/>);};diff --git a/test/browser/components/common/histogram-plot-test.js b/test/browser/components/common/histogram-plot-test.jsindex 279d2d90c..9ec351b15 100644--- a/test/browser/components/common/histogram-plot-test.js+++ b/test/browser/components/common/histogram-plot-test.js@@ -5,6 +5,7 @@ import React from 'react';import test from 'tape';import {mountWithTheme} from 'test/helpers/component-utils';import {appInjector, HistogramPlotFactory, HISTOGRAM_MASK_MODE} from '@kepler.gl/components';+import {theme} from '@kepler.gl/styles';const HistogramPlot = appInjector.get(HistogramPlotFactory);@@ -43,3 +44,52 @@ test('Components -> HistogramPlot -> brush is painted above the bars', t => {t.end();});++// Styled-components writes the plot color into a stylesheet, not an inline style.+const paintedBackground = node => {+ const classes = new Set((node.getAttribute('class') || '').split(/\s+/).filter(Boolean));+ let background = '';+ Array.from(document.styleSheets).forEach(sheet => {+ let rules = [];+ try {+ rules = Array.from(sheet.cssRules || []);+ } catch (err) {+ return;+ }+ rules.forEach(rule => {+ if (!rule.selectorText || !rule.style) return;+ const matches = rule.selectorText.split(',').some(selector => {+ const required = selector.match(/\.[\w-]+/g) || [];+ return required.length > 0 && required.every(token => classes.has(token.slice(1)));+ });+ if (!matches) return;+ const value =+ rule.style.getPropertyValue('background-color') ||+ rule.style.getPropertyValue('background');+ if (value) background = value.trim();+ });+ });+ return background;+};++test('Components -> HistogramPlot -> column histograms stay on the light data table', t => {+ const columnStats = mountWithTheme(+ <HistogramPlot {...histogramProps} isMasked={HISTOGRAM_MASK_MODE.NoMask} />+ );+ t.equal(+ paintedBackground(columnStats.find('svg').getDOMNode()).toLowerCase(),+ 'transparent',+ 'should leave the data-table histogram transparent'+ );++ const rangePlot = mountWithTheme(+ <HistogramPlot {...histogramProps} isMasked={HISTOGRAM_MASK_MODE.NoMask} recessed />+ );+ t.equal(+ paintedBackground(rangePlot.find('svg').getDOMNode()).toLowerCase(),+ theme.rangePlotBgd.toLowerCase(),+ 'should keep the recessed surface behind the range brush'+ );++ t.end();+});