Skip to content

Commit

Permalink
Add meta scope for view element mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Shamann committed Jul 5, 2021
1 parent 700c45a commit b47df22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/DataRenderer/mappers/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } : {};
Expand Down Expand Up @@ -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;
Expand All @@ -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 };
},
Expand Down
1 change: 1 addition & 0 deletions src/store/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit b47df22

Please sign in to comment.