diff --git a/src/DataRenderer/mappers/views/index.ts b/src/DataRenderer/mappers/views/index.ts index 8630c54..31ddc44 100644 --- a/src/DataRenderer/mappers/views/index.ts +++ b/src/DataRenderer/mappers/views/index.ts @@ -10,7 +10,7 @@ import { Geometry } from '@antv/g2plot/lib/adaptor/geometries/base'; import jp from 'json-pointer'; import { JSONPath } from 'jsonpath-plus'; -import { cloneDeep, isEmpty } from 'lodash-es'; +import { cloneDeep, isEmpty, pickBy } from 'lodash-es'; function assignValue(property: any, value: any) { return value !== undefined ? { [property]: value } : {}; @@ -134,7 +134,7 @@ export default function ViewPartMapper(mappings: any, dataMappings: any) { data, ); - const createGeometry = (element: any) => assignObjectValue(mappings, element); + const createGeometry = (element: any): Geometry => assignObjectValue(mappings, element); const getGeometryMeta = (element: any, viewElementGeometry: Geometry) => { const { meta: elementMeta } = element; @@ -154,11 +154,19 @@ export default function ViewPartMapper(mappings: any, dataMappings: any) { return {}; }; + const computeAdditionalMeta = (viewElement: any) => { + const isMetaMappingProperty = (m: any) => m.scope === 'meta'; + const metaMappings = pickBy(mappings, isMetaMappingProperty); + return assignObjectValue(metaMappings, viewElement); + }; + return { createChartViewPart(element: any, viewElementData: any[]) { - const geometry: Geometry = createGeometry(element); - const geometryData = applyDataMappings(geometry, viewElementData, element); - const geometryMeta = getGeometryMeta(element, geometry); + const computedMeta = computeAdditionalMeta(element); + const mappingContext = { ...element, ...computedMeta }; + const geometry = createGeometry(mappingContext); + const geometryData = applyDataMappings(geometry, viewElementData, mappingContext); + const geometryMeta = getGeometryMeta(mappingContext, geometry); const options = extractGeometryOptions(geometry); return { geometry, meta: geometryMeta, data: geometryData, options }; }, diff --git a/src/store/data.ts b/src/store/data.ts index df3f0df..b5cf98d 100644 --- a/src/store/data.ts +++ b/src/store/data.ts @@ -56,6 +56,7 @@ export const timeSeriesViewKinds = [ value: '(observedProperty,hasFeatureOfInterest) => hasFeatureOfInterest + "#" + observedProperty.replace(/^[A-Za-z0-9-]*:/, "").toLowerCase()', applyTo: '$.[observedProperty,hasFeatureOfInterest]', + scope: 'meta', }, // adjust: { // type: 'object',