Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
fix(export): restore annotation and chart panels (#3853)
Igor Dykhtac7a6399f55f4
diff --git a/esbuild/umd-esbuild.config.mjs b/esbuild/umd-esbuild.config.mjsindex 34b9f4bff..a5dea6b1b 100644--- a/esbuild/umd-esbuild.config.mjs+++ b/esbuild/umd-esbuild.config.mjs@@ -134,7 +134,11 @@ const config = {// and throw `arrow type not supported: tL` in the minified exported HTML.// Force a single copy, matching the demo-app / website bundler aliases.alias: {- 'apache-arrow': join(NODE_MODULES_DIR, 'apache-arrow')+ 'apache-arrow': join(NODE_MODULES_DIR, 'apache-arrow'),+ // The clean source worktree has not built package subpath artifacts yet.+ // Keep charts optional for @kepler.gl/components consumers while letting+ // the root UMD bundle explicitly opt into its source entrypoint.+ '@kepler.gl/components/charts': join(SRC_DIR, 'components/src/charts.ts')},plugins: [diff --git a/src/components/src/map/charts/chart-manager.tsx b/src/components/src/map/charts/chart-manager.tsxindex 0833c191b..85aeb297f 100644--- a/src/components/src/map/charts/chart-manager.tsx+++ b/src/components/src/map/charts/chart-manager.tsx@@ -34,7 +34,7 @@ export type ChartManagerState = {};/** When false, only pinned charts are shown (panel control is inactive). */panelActive?: boolean;- /** Image export: show all charts without edit chrome. */+ /** Immutable export: show all charts without edit or pin chrome. */isExport?: boolean;children?: React.ReactNode;};@@ -194,6 +194,7 @@ export default function ChartManagerFactory(layers={layers}visStateActions={visStateActions as typeof VisStateActions}readOnly={!panelActive || isExport}+ hidePinAction={isExport}/></StyledChartPanelContent></StyledChartPanel>diff --git a/src/components/src/map/charts/chart-panel.spec.tsx b/src/components/src/map/charts/chart-panel.spec.tsxnew file mode 100644index 000000000..3dfee02b8--- /dev/null+++ b/src/components/src/map/charts/chart-panel.spec.tsx@@ -0,0 +1,56 @@+// SPDX-License-Identifier: MIT+// Copyright contributors to the kepler.gl project++import React from 'react';+import {IntlProvider} from 'react-intl';++import {createBigNumberChart} from '@kepler.gl/charts';+import {messages} from '@kepler.gl/localization';+import {renderWithTheme} from 'test/helpers/component-jest-utils';++import {ChartPanelContentFactory} from './chart-panel';++jest.mock('../../side-panel/common/source-data-selector', () => {+ const SourceDataSelectorFactory = () => () => null;+ SourceDataSelectorFactory.deps = [];+ return {__esModule: true, default: SourceDataSelectorFactory};+});++const EmptyControl = () => null;+const ChartPanelContent = ChartPanelContentFactory(+ EmptyControl as any,+ EmptyControl as any,+ EmptyControl as any,+ EmptyControl as any+);+const chart = createBigNumberChart({id: 'chart-1', title: 'Rows', pinned: true});++function renderChartPanel(hidePinAction: boolean) {+ return renderWithTheme(+ <IntlProvider locale="en" messages={messages.en}>+ <ChartPanelContent+ charts={[chart]}+ datasets={{}}+ layers={[]}+ readOnly+ hidePinAction={hidePinAction}+ />+ </IntlProvider>+ );+}++describe('ChartPanelContent', () => {+ test('keeps ordinary pinned charts dismissible', () => {+ const {getByLabelText, getByText} = renderChartPanel(false);++ expect(getByLabelText('Unpin chart')).toBeInTheDocument();+ expect(getByText('Select a dataset to plot this chart.')).toBeInTheDocument();+ });++ test('renders immutable export charts without pin actions', () => {+ const {queryByLabelText, getByText} = renderChartPanel(true);++ expect(queryByLabelText('Unpin chart')).toBeNull();+ expect(getByText('Select a dataset to plot this chart.')).toBeInTheDocument();+ });+});diff --git a/src/components/src/map/charts/chart-panel.tsx b/src/components/src/map/charts/chart-panel.tsxindex 4cd530b6c..d72f4d458 100644--- a/src/components/src/map/charts/chart-panel.tsx+++ b/src/components/src/map/charts/chart-panel.tsx@@ -469,6 +469,8 @@ export type ChartPanelProps = {visStateActions?: typeof VisStateActions;/** When true, hide edit chrome and only render chart views (pinned overlay). */readOnly?: boolean;+ /** Hide the pinned-overlay action when the chart view is fully immutable. */+ hidePinAction?: boolean;};ChartPanelContentFactory.deps = [@@ -489,7 +491,8 @@ export function ChartPanelContentFactory(datasets,layers,visStateActions,- readOnly = false+ readOnly = false,+ hidePinAction = false}) => {const [colorUIByChart, setColorUIByChart] = useState<Record<string, ColorUI>>({});@@ -650,8 +653,12 @@ export function ChartPanelContentFactory(? String(chart.crossFilter.value.x): undefined;return (- <ChartCard key={chart.id} className="chart-card" $showPinOnHover={readOnly}>- {readOnly ? (+ <ChartCard+ key={chart.id}+ className="chart-card"+ $showPinOnHover={readOnly && !hidePinAction}+ >+ {readOnly && !hidePinAction ? (<><ChartHeaderActionclassName="chart-card__pin-action"diff --git a/src/index.js b/src/index.jsindex afb5548f5..91b2b7131 100644--- a/src/index.js+++ b/src/index.js@@ -18,6 +18,9 @@ export * from '@kepler.gl/processors';// Componentsexport * from '@kepler.gl/components';+// Exported HTML maps load the root UMD bundle and need the optional chart+// manager without pulling it into the regular components barrel.+export {ChartManagerFactory} from '@kepler.gl/components/charts';// Layersexport * from '@kepler.gl/layers';diff --git a/src/utils/src/export-map-html.ts b/src/utils/src/export-map-html.tsindex cd0d05f6c..413cc0d6f 100644--- a/src/utils/src/export-map-html.ts+++ b/src/utils/src/export-map-html.ts@@ -372,24 +372,57 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {/** END STORE **//** COMPONENTS **/- /** Custom map control factory to add Effects button + panel **/+ /** Custom map control factory to restore export editing and chart display. **/var CustomMapControlFactory = (function createCustomMapControl(react, keplerGl) {var EffectControlFactory = keplerGl.EffectControlFactory;var EffectManagerFactory = keplerGl.EffectManagerFactory;+ var AnnotationControlFactory = keplerGl.AnnotationControlFactory;+ var AnnotationManagerFactory = keplerGl.AnnotationManagerFactory;+ var ChartControlFactory = keplerGl.ChartControlFactory;+ var ChartManagerFactory = keplerGl.ChartManagerFactory;var MapControlFactory = keplerGl.MapControlFactory;- if (!EffectControlFactory || !EffectManagerFactory || !MapControlFactory) {- console.warn('kepler.gl: Effect factories not available, skipping effect control injection');+ if (+ !EffectControlFactory ||+ !EffectManagerFactory ||+ !AnnotationControlFactory ||+ !AnnotationManagerFactory ||+ !ChartControlFactory ||+ !ChartManagerFactory ||+ !MapControlFactory+ ) {+ console.warn('kepler.gl: Export control factories not available, skipping control injection');return null;}- function EffectMapControlFactory(EffectControl, EffectManager) {- var args = Array.prototype.slice.call(arguments, 2);+ function ExportMapControlFactory(+ EffectControl,+ EffectManager,+ AnnotationControl,+ AnnotationManager,+ ChartControl,+ ChartManager+ ) {+ var args = Array.prototype.slice.call(arguments, 6);var MapControl = MapControlFactory.apply(null, args);- var actionComponents = (MapControl.defaultActionComponents || []).concat([EffectControl]);-- var EffectMapControl = function EffectMapControl(props) {- var showEffects = Boolean(props.mapControls && props.mapControls.effect && props.mapControls.effect.active);+ var defaultActionComponents = MapControl.defaultActionComponents || [];++ var ExportMapControl = function ExportMapControl(props) {+ var readOnly = Boolean(props.readOnly);+ var mapControls = props.mapControls || {};+ var charts = props.charts || [];+ var actionComponents = defaultActionComponents.filter(function(ActionComponent) {+ return !readOnly || ActionComponent !== AnnotationControl;+ });+ if (!readOnly) {+ actionComponents = actionComponents.concat([ChartControl, EffectControl]);+ }+ var showEffects = !readOnly && Boolean(mapControls.effect && mapControls.effect.active);+ var showAnnotations = !readOnly && Boolean(mapControls.annotation && mapControls.annotation.active);+ var showChartPanel = !readOnly && Boolean(mapControls.chart && mapControls.chart.active);+ var hasPinnedCharts = charts.some(function(chart) { return chart.pinned !== false; });+ var showCharts = readOnly ? charts.length > 0 : showChartPanel || hasPinnedCharts;+ var rightPanelVisible = showEffects || showAnnotations || showCharts;return react.createElement('div',{style: {@@ -406,7 +439,7 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {{style: {position: 'relative', pointerEvents: 'all'}},react.createElement(MapControl, Object.assign({}, props, {top: 0, actionComponents: actionComponents}))),- showEffects+ rightPanelVisible? react.createElement('div', {style: {maxHeight: '100%',@@ -416,16 +449,30 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {pointerEvents: 'all',marginTop: '10px'}- }, react.createElement(EffectManager, null))+ },+ showAnnotations ? react.createElement(AnnotationManager, null) : null,+ showCharts ? react.createElement(ChartManager, {+ panelActive: showChartPanel,+ isExport: readOnly+ }) : null,+ showEffects ? react.createElement(EffectManager, null) : null+ ): null);};- return EffectMapControl;+ return ExportMapControl;}- EffectMapControlFactory.deps = [EffectControlFactory, EffectManagerFactory].concat(MapControlFactory.deps);-- return [MapControlFactory, EffectMapControlFactory];+ ExportMapControlFactory.deps = [+ EffectControlFactory,+ EffectManagerFactory,+ AnnotationControlFactory,+ AnnotationManagerFactory,+ ChartControlFactory,+ ChartManagerFactory+ ].concat(MapControlFactory.deps);++ return [MapControlFactory, ExportMapControlFactory];}(React, KeplerGl));var KeplerGlComponent = CustomMapControlFactorydiff --git a/test/node/utils/export-utils-test.js b/test/node/utils/export-utils-test.jsindex 45071b093..3387f43bf 100644--- a/test/node/utils/export-utils-test.js+++ b/test/node/utils/export-utils-test.js@@ -68,6 +68,58 @@ test('exportUtils -> ExportHtml includes map info', t => {t.end();});+test('exportUtils -> ExportHtml mounts editable and view-only export controls', t => {+ const editHtml = exportMapToHTML({+ datasets: [],+ config: {version: 'v1', config: {}},+ mode: 'EDIT'+ });+ const readHtml = exportMapToHTML({+ datasets: [],+ config: {version: 'v1', config: {}},+ mode: 'READ'+ });++ for (const factory of [+ 'EffectManagerFactory',+ 'AnnotationManagerFactory',+ 'ChartControlFactory',+ 'ChartManagerFactory'+ ]) {+ t.ok(editHtml.includes(`keplerGl.${factory}`), `editable exports should load ${factory}`);+ }+ t.ok(+ editHtml.includes('actionComponents = actionComponents.concat([ChartControl, EffectControl])'),+ 'editable exports should add chart and effect controls'+ );+ t.ok(+ editHtml.includes('showAnnotations ? react.createElement(AnnotationManager, null) : null'),+ 'editable exports should mount the annotation manager'+ );+ t.ok(+ editHtml.includes('showCharts ? react.createElement(ChartManager'),+ 'editable exports should mount the chart manager'+ );+ t.ok(+ readHtml.includes('var readOnly = Boolean(props.readOnly)') &&+ readHtml.includes('return !readOnly || ActionComponent !== AnnotationControl'),+ 'read-only exports should remove the stock annotation editing control'+ );+ t.ok(+ readHtml.includes('var showEffects = !readOnly') &&+ readHtml.includes('var showAnnotations = !readOnly') &&+ readHtml.includes('if (!readOnly) {'),+ 'read-only exports should suppress effect, annotation, and chart editing controls'+ );+ t.ok(+ readHtml.includes('var showCharts = readOnly ? charts.length > 0') &&+ readHtml.includes('isExport: readOnly'),+ 'read-only exports should retain immutable chart rendering'+ );++ t.end();+});+test('exportUtils -> ExportHtml escapes script terminators in map info', t => {const html = exportMapToHTML({datasets: [],