Skip to content

Commit

Permalink
[feat] Implemented ability to invert time series trend colors (#2692)
Browse files Browse the repository at this point in the history
- Pass through properties to invert time series trend colors

Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
  • Loading branch information
igorDykhta authored Oct 14, 2024
1 parent ecb5ed4 commit b28a263
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/components/src/common/range-plot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ interface RangePlotProps {
animationWindow?: string;
filter?: Filter;
datasets?: Datasets;

invertTrendColor?: boolean;
}

RangePlotFactory.deps = [RangeBrushFactory, HistogramPlotFactory, LineChartFactory];
Expand Down
4 changes: 4 additions & 0 deletions src/components/src/common/range-slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ interface RangeSliderProps {
animationWindow?: string;
filter?: Filter;
datasets?: Datasets;

invertTrendColor?: boolean;
}

RangeSliderFactory.deps = [RangePlotFactory];
Expand Down Expand Up @@ -211,6 +213,7 @@ export default function RangeSliderFactory(
showInput,
histogram,
lineChart,
invertTrendColor,
range,
onChange = noop,
sliderHandleWidth,
Expand Down Expand Up @@ -238,6 +241,7 @@ export default function RangeSliderFactory(
<RangePlot
histogram={histogram}
lineChart={this.props.lineChart}
invertTrendColor={invertTrendColor}
plotType={this.props.plotType}
isEnlarged={this.props.isEnlarged}
onBrush={(val0, val1) => onChange([val0, val1])}
Expand Down
3 changes: 3 additions & 0 deletions src/components/src/common/time-range-slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type TimeRangeSliderProps = {
setFilterAnimationWindow?: (id: string) => void;
onChange: (v: number[]) => void;
timeline: Timeline;
invertTrendColor?: boolean;
};

const StyledSliderContainer = styled.div<StyledSliderContainerProps>`
Expand Down Expand Up @@ -89,6 +90,7 @@ export default function TimeRangeSliderFactory(
histogram,
plotType,
lineChart,
invertTrendColor,
step,
isAnimatable,
speed,
Expand Down Expand Up @@ -130,6 +132,7 @@ export default function TimeRangeSliderFactory(
value1={value[1]}
histogram={histogram}
lineChart={lineChart}
invertTrendColor={invertTrendColor}
plotType={plotType}
isEnlarged={isEnlarged}
showInput={false}
Expand Down
4 changes: 3 additions & 1 deletion src/schemas/src/vis-state-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,9 @@ export const filterPropsV1 = {
layerId: null,
speed: null,

enabled: null
enabled: null,

invertTrendColor: null
};

export const propertiesV0 = {
Expand Down
3 changes: 2 additions & 1 deletion src/types/reducers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export type TimeRangeFilter = FilterBase<LineChart> &
[key: string]: any;
};
animationWindow: string;
invertTrendColor: boolean;
};

export type PolygonFilter = FilterBase<LineChart> & {
Expand Down Expand Up @@ -520,11 +521,11 @@ export type TypedTimeRangeFilter = FilterBaseOmitRedudant &
fieldType: 'timestamp';
fixedDomain: true;
value: [number, number];
bins?: object;
plotType: {
[key: string]: any;
};
animationWindow: string;
invertTrendColor: boolean;
};

export type TypedPolygonFilter = FilterBaseOmitRedudant & {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/src/data-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export const arrayMove = <T>(array: T[], from: number, to: number): T[] => {
* @param field
*/
export function getFormatter(
format: string | Record<string, string>,
format: string | Record<string, string> | null,
field?: Field
): FieldFormatter {
if (!format) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/src/dataset-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ export function analyzerTypeToFieldType(aType: string): string {

const TIME_DISPLAY = '2020-05-11 14:00';

const addTimeLabel = (formats: TimeLabelFormat[]) =>
export const addTimeLabel = (formats: TimeLabelFormat[]) =>
formats.map(f => ({
...f,
label:
Expand All @@ -590,7 +590,7 @@ export function getFieldFormatLabels(fieldType?: string): TooltipFormat[] {
return addTimeLabel(formatLabels);
}

export function getFormatLabels(fields: TooltipFields[], fieldName: string): TooltipFormat[] {
export const getFormatLabels = (fields: TooltipFields[], fieldName: string): TooltipFormat[] => {
const fieldType = fields.find(f => f.name === fieldName)?.type;
return getFieldFormatLabels(fieldType);
}
};
3 changes: 2 additions & 1 deletion src/utils/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
// Copyright contributors to the kepler.gl project

import {TOOLTIP_KEY} from '@kepler.gl/constants';
import {TimeLabelFormat} from '@kepler.gl/types';

export const getFormatValue = fmt => fmt[TOOLTIP_KEY];
export const getFormatValue = (fmt: TimeLabelFormat): string | null => fmt[TOOLTIP_KEY];

0 comments on commit b28a263

Please sign in to comment.