@@ -59,26 +59,11 @@ export const getColorSpec = (
5959 return { value : DEFAULT_COLOR } ;
6060} ;
6161
62- // Replace dots in field names with an alternative UTF-8 character
63- // since VEGA treats dots in field names as nested values and escaping
64- // in columns/rows for repeated charts isn't working as expected .
62+ // Escapes the characters .[] in field names with double backslashes
63+ // since VEGA treats dots/brackets in field names as nested values.
64+ // See https://vega.github.io/vega-lite/docs/field.html for details .
6565function getEscapedVegaFieldName ( fieldName : string ) {
66- return fieldName . replace ( / \. / g, '․' ) ;
67- }
68-
69- // Replace dots for all keys of all data items with an alternative UTF-8 character
70- // since VEGA treats dots in field names as nested values and escaping
71- // in columns/rows for repeated charts isn't working as expected.
72- function getEscapedVegaValues ( values : VegaValue [ ] ) : VegaValue [ ] {
73- return values . map ( ( d ) =>
74- Object . keys ( d ) . reduce (
75- ( p , c ) => ( {
76- ...p ,
77- [ getEscapedVegaFieldName ( c ) ] : d [ c ] ,
78- } ) ,
79- { } as VegaValue
80- )
81- ) ;
66+ return fieldName . replace ( / ( [ \. | \[ | \] ] ) / g, '\\$1' ) ;
8267}
8368
8469type VegaValue = Record < string , string | number > ;
@@ -92,7 +77,7 @@ export const getScatterplotMatrixVegaLiteSpec = (
9277 legendType ?: LegendType ,
9378 dynamicSize ?: boolean
9479) : TopLevelSpec => {
95- const vegaValues = getEscapedVegaValues ( values ) ;
80+ const vegaValues = values ;
9681 const vegaColumns = columns . map ( getEscapedVegaFieldName ) ;
9782 const outliers = resultsField !== undefined ;
9883
@@ -193,7 +178,10 @@ export const getScatterplotMatrixVegaLiteSpec = (
193178 ...( color !== undefined
194179 ? [ { type : colorSpec . type , field : getEscapedVegaFieldName ( color ) } ]
195180 : [ ] ) ,
196- ...vegaColumns . map ( ( d ) => ( { type : LEGEND_TYPES . QUANTITATIVE , field : d } ) ) ,
181+ ...vegaColumns . map ( ( d ) => ( {
182+ type : LEGEND_TYPES . QUANTITATIVE ,
183+ field : d ,
184+ } ) ) ,
197185 ...( outliers
198186 ? [ { type : LEGEND_TYPES . QUANTITATIVE , field : escapedOutlierScoreField , format : '.3f' } ]
199187 : [ ] ) ,
0 commit comments