Skip to content

Commit e5b7df1

Browse files
authored
rollback change, and truncate tooltip (#3300)
* rollback change, and truncate tooltip Signed-off-by: bdjulbic <bdjulbic@foursquare.com> * truncate to 256 Signed-off-by: bdjulbic <bdjulbic@foursquare.com> * truncate to 256 Signed-off-by: bdjulbic <bdjulbic@foursquare.com> --------- Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
1 parent cbb3204 commit e5b7df1

3 files changed

Lines changed: 11 additions & 68 deletions

File tree

src/common-utils/src/data-type.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,6 @@ import {h3IsValid} from './h3-utils';
1111

1212
const H3_ANALYZER_TYPE = 'H3';
1313

14-
// Returns true if the value is likely a WKT geometry string (heuristic check).
15-
const WKT_PREFIX_RE =
16-
/^(?:SRID=\d+\s*;\s*)?(?:POINT|LINESTRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)(?:\s+(?:Z|M|ZM))?\s*\(/i;
17-
18-
export function isWkt(value: unknown): boolean {
19-
if (typeof value !== 'string') {
20-
return false;
21-
}
22-
23-
const s = value.trim();
24-
if (s.length < 10) {
25-
return false;
26-
}
27-
28-
if (!s.includes('(') || !s.includes(')')) {
29-
return false;
30-
}
31-
32-
return WKT_PREFIX_RE.test(s);
33-
}
34-
3514
export const ACCEPTED_ANALYZER_TYPES = [
3615
AnalyzerDATA_TYPES.DATE,
3716
AnalyzerDATA_TYPES.TIME,
@@ -288,11 +267,6 @@ export function getFieldsFromData(data: RowData, fieldOrder: string[]): Field[]
288267
type = data.some(d => isHexWkb(d[name])) ? AnalyzerDATA_TYPES.GEOMETRY : type;
289268
}
290269

291-
// quick check if string is wkt
292-
if (type === AnalyzerDATA_TYPES.STRING) {
293-
type = data.some(d => isWkt(d[name])) ? AnalyzerDATA_TYPES.GEOMETRY_FROM_STRING : type;
294-
}
295-
296270
return {
297271
name,
298272
id: name,

src/components/src/map/layer-hover-info.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import React, {useMemo} from 'react';
55
import styled from 'styled-components';
6+
import truncate from 'lodash/truncate';
67
import {CompareType, Field, Merge, TooltipField} from '@kepler.gl/types';
78
import {CenterFlexbox} from '../common/styled-components';
89
import {Layers} from '../common/icons';
@@ -66,12 +67,19 @@ interface RowProps {
6667
url?: string;
6768
}
6869

70+
const TOOLTIP_VALUE_MAX_LENGTH = 256;
71+
6972
const Row: React.FC<RowProps> = ({name, value, deltaValue, url}) => {
7073
// Set 'url' to 'value' if it looks like a url
7174
if (!url && value && typeof value === 'string' && value.match(/^http/)) {
7275
url = value;
7376
}
7477

78+
const displayValue =
79+
typeof value === 'string' && value.length > TOOLTIP_VALUE_MAX_LENGTH
80+
? truncate(value, {length: TOOLTIP_VALUE_MAX_LENGTH})
81+
: value;
82+
7583
const asImg = /<img>/.test(name);
7684
return (
7785
<tr className="layer-hover-info__row" key={name}>
@@ -81,11 +89,11 @@ const Row: React.FC<RowProps> = ({name, value, deltaValue, url}) => {
8189
<img src={value} />
8290
) : url ? (
8391
<a target="_blank" rel="noopener noreferrer" href={url}>
84-
{value}
92+
{displayValue}
8593
</a>
8694
) : (
8795
<>
88-
<span>{value}</span>
96+
<span>{displayValue}</span>
8997
{notNullorUndefined(deltaValue) ? (
9098
<span
9199
className={`row__delta-value ${

test/node/utils/dataset-utils-test.js

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import test from 'tape';
55
import {findDefaultColorField, createNewDataEntry} from '@kepler.gl/utils';
6-
import {isHexWkb, isWkt} from '@kepler.gl/common-utils';
7-
6+
import {isHexWkb} from '@kepler.gl/common-utils';
87
import {processCsvData} from '@kepler.gl/processors';
98

109
import csvData from 'test/fixtures/test-layer-data';
@@ -89,42 +88,4 @@ test('datasetUtils.isHexWkb', t => {
8988

9089
const validEWktNDR = '0020000001000013ff0000000000400000000000000040';
9190
t.ok(isHexWkb(validEWktNDR), 'A valid hex ewkb in NDR should be valid');
92-
t.end();
93-
});
94-
95-
test('datasetUtils.isWkt', t => {
96-
// non-strings
97-
t.notOk(isWkt(null), 'null is not a valid WKT');
98-
t.notOk(isWkt(undefined), 'undefined is not a valid WKT');
99-
t.notOk(isWkt(123), 'number is not a valid WKT');
100-
t.notOk(isWkt({}), 'object is not a valid WKT');
101-
102-
// regular strings / known non-WKT identifiers
103-
t.notOk(isWkt(''), 'empty string is not a valid WKT');
104-
t.notOk(isWkt('hello world'), 'regular string is not a valid WKT');
105-
t.notOk(isWkt('06075'), 'FIPS code should not be a valid WKT');
106-
t.notOk(isWkt('8a2a1072b59ffff'), 'H3 code should not be a valid WKT');
107-
108-
// edge cases (missing coordinates / parentheses)
109-
t.notOk(isWkt('POINT'), 'POINT without coordinates should not be a valid WKT');
110-
t.notOk(isWkt('POINT 1 2'), 'POINT without parentheses should not be a valid WKT');
111-
t.notOk(isWkt('SRID=4326;POINT'), 'SRID prefix without geometry should not be a valid WKT');
112-
t.notOk(isWkt('POINT (1 2'), 'missing closing parenthesis should not be a valid WKT');
113-
t.notOk(isWkt('POINT ( )'), 'empty coordinates should not be a valid WKT');
114-
115-
// valid WKT examples (heuristic)
116-
t.ok(isWkt('POINT (1 2)'), 'POINT should be recognized as WKT');
117-
t.ok(isWkt('POINT(1 2)'), 'POINT without space before parentheses should be recognized as WKT');
118-
t.ok(isWkt('LINESTRING (0 0, 1 1)'), 'LINESTRING should be recognized as WKT');
119-
t.ok(isWkt('POLYGON ((0 0, 1 0, 1 1, 0 0))'), 'POLYGON should be recognized as WKT');
120-
t.ok(
121-
isWkt('SRID=4326;POINT(1 2)'),
122-
'WKT with SRID prefix should be recognized as WKT'
123-
);
124-
t.ok(isWkt('POINT Z (1 2 3)'), 'WKT with Z dimension should be recognized as WKT');
125-
126-
// not WKT but contains parentheses
127-
t.notOk(isWkt('HELLO (1 2)'), 'non-WKT string with parentheses should not be valid WKT');
128-
129-
t.end();
13091
});

0 commit comments

Comments
 (0)