Skip to content

Commit 6bd05c6

Browse files
committed
Fix on Nivo Canvas
1 parent c75e150 commit 6bd05c6

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

src/chart/Chart.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface ChartProps {
1919
updateReportSetting?: (name, value) => void; // Callback to update a setting for this report.
2020
fields: (fields) => string[]; // List of fields (return values) available for the report.
2121
setFields?: (fields) => void; // Update the list of fields for this report.
22+
theme?: string; // Dashboard theme value.
2223
}
2324

2425
/**

src/chart/Utils.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { tokens } from '@neo4j-ndl/base';
12
import { QueryResult, Record as Neo4jRecord } from 'neo4j-driver';
2-
33
export function recordToNative(input: any): any {
44
if (!input && input !== false) {
55
return null;
@@ -118,11 +118,11 @@ export enum EntityType {
118118
}
119119

120120
export const themeNivo = {
121-
textColor: 'rgb(var(--palette-neutral-text-weak))',
122-
text: { fill: 'rgb(var(--palette-neutral-text-weak))' },
121+
textColor: 'rgb(var(--palette-neutral-text-default))',
122+
text: { fill: 'rgb(var(--palette-neutral-text-default))' },
123123
axis: {
124-
ticks: { text: { fill: 'rgb(var(--palette-neutral-text-weak))' } },
125-
legend: { text: { fill: 'rgb(var(--palette-neutral-text-weak))' } },
124+
ticks: { text: { fill: 'rgb(var(--palette-light-neutral-text-default))' } },
125+
legend: { text: { fill: 'rgb(var(--palette-neutral-text-default))' } },
126126
},
127127
legends: {
128128
text: { fill: 'rgb(var(--palette-neutral-text-weak))' },
@@ -146,3 +146,38 @@ export const themeNivo = {
146146
},
147147
},
148148
};
149+
150+
export const themeNivoCanvas = (theme) => {
151+
let baseDefault =
152+
theme === 'light' ? tokens.palette.light.neutral.text.default : tokens.palette.dark.neutral.text.default;
153+
let baseWeak = theme === 'light' ? tokens.palette.light.neutral.text.weak : tokens.palette.dark.neutral.text.weak;
154+
return {
155+
// textColor: 'rgb(var(--palette-neutral-text-default))',
156+
text: { fill: baseDefault },
157+
axis: {
158+
ticks: { text: { fill: baseDefault } },
159+
legend: { text: { fill: baseDefault } },
160+
},
161+
legends: {
162+
text: { fill: baseWeak },
163+
title: { text: { fill: baseWeak } },
164+
ticks: { text: { fill: baseWeak } },
165+
hidden: { text: { fill: baseWeak } },
166+
},
167+
markers: {
168+
text: { fill: baseDefault },
169+
},
170+
labels: {
171+
text: { fill: baseDefault },
172+
},
173+
annotations: {
174+
text: { fill: baseDefault },
175+
},
176+
tooltip: {
177+
container: {
178+
fill: 'rgb(var(--palette-neutral-text-default))',
179+
background: 'rgb(var(--palette-neutral-bg-strong))',
180+
},
181+
},
182+
};
183+
};

src/chart/bar/BarChart.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getD3ColorsByScheme } from '../../config/ColorConfig';
55
import { evaluateRulesOnDict, useStyleRules } from '../../extensions/styling/StyleRuleEvaluator';
66
import { ChartProps } from '../Chart';
77
import { convertRecordObjectToString, recordToNative } from '../ChartUtils';
8-
import { themeNivo } from '../Utils';
8+
import { themeNivo, themeNivoCanvas } from '../Utils';
99
import { extensionEnabled } from '../../utils/ReportUtils';
1010

1111
/**
@@ -208,10 +208,11 @@ const NeoBarChart = (props: ChartProps) => {
208208
};
209209

210210
const extraProperties = positionLabel == 'off' ? {} : { barComponent: BarComponent };
211-
const BarChartComponent = data.length > 30 ? ResponsiveBarCanvas : ResponsiveBar;
211+
const canvas = data.length > 30;
212+
const BarChartComponent = canvas ? ResponsiveBarCanvas : ResponsiveBar;
212213
const chart = (
213214
<BarChartComponent
214-
theme={themeNivo}
215+
theme={canvas ? themeNivoCanvas(props.theme) : themeNivo}
215216
data={data}
216217
key={`${selection.index}___${selection.value}`}
217218
layout={layout}

src/report/Report.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { getPageNumber } from '../settings/SettingsSelectors';
1919
import { getPrepopulateReportExtension } from '../extensions/state/ExtensionSelectors';
2020
import { deleteSessionStoragePrepopulationReportFunction } from '../extensions/state/ExtensionActions';
2121
import { updateFieldsThunk } from '../card/CardThunks';
22+
import { getDashboardTheme } from '../dashboard/DashboardSelectors';
2223

2324
const DEFAULT_LOADING_ICON = <LoadingSpinner size='large' className='centered' style={{ marginTop: '-30px' }} />;
2425

@@ -54,6 +55,7 @@ export const NeoReport = ({
5455
ChartType = NeoTableChart, // The report component to render with the query results.
5556
prepopulateExtensionName,
5657
deletePrepopulationReportFunction,
58+
theme,
5759
}) => {
5860
const [records, setRecords] = useState(null);
5961
const [timer, setTimer] = useState(null);
@@ -276,6 +278,7 @@ export const NeoReport = ({
276278
updateReportSetting={updateReportSetting}
277279
fields={fields}
278280
setFields={setFields}
281+
theme={theme}
279282
/>
280283
</div>
281284
);
@@ -341,6 +344,7 @@ export const NeoReport = ({
341344
const mapStateToProps = (state, ownProps) => ({
342345
pagenumber: getPageNumber(state),
343346
prepopulateExtensionName: getPrepopulateReportExtension(state, ownProps.id),
347+
theme: getDashboardTheme(state),
344348
});
345349

346350
const mapDispatchToProps = (dispatch) => ({

0 commit comments

Comments
 (0)