diff --git a/modules/core/src/lib/attribute/attribute-manager.ts b/modules/core/src/lib/attribute/attribute-manager.ts index 8d518893cdb..bd471597478 100644 --- a/modules/core/src/lib/attribute/attribute-manager.ts +++ b/modules/core/src/lib/attribute/attribute-manager.ts @@ -208,7 +208,7 @@ export default class AttributeManager { } else if ( typeof accessorName === 'string' && !buffers[accessorName] && - attribute.setConstantValue(props[accessorName]) + attribute.setConstantValue(context, props[accessorName]) ) { // Step 3: try set constant value from props // Note: if buffers[accessorName] is supplied, ignore props[accessorName] @@ -380,7 +380,7 @@ export default class AttributeManager { // The attribute is flagged as constant outside of an update cycle // Skip allocation and updater call // @ts-ignore value can be set to an array by user but always cast to typed array during attribute update - attribute.setConstantValue(attribute.value); + attribute.setConstantValue(opts.context, attribute.value); return; } diff --git a/modules/core/src/lib/attribute/attribute.ts b/modules/core/src/lib/attribute/attribute.ts index d2c532bdee9..8e73919cb38 100644 --- a/modules/core/src/lib/attribute/attribute.ts +++ b/modules/core/src/lib/attribute/attribute.ts @@ -254,7 +254,7 @@ export default class Attribute extends DataColumn { t.ok(attribute.allocate(4), 'allocate successful'); t.is(attribute.value, allocatedValue, 'reused the same typed array'); - attribute.setConstantValue([1, 1]); + attribute.setConstantValue(this, [1, 1]); t.deepEquals(attribute.value, [1, 1], 'value overwritten by external constant'); - attribute.setConstantValue(undefined); + attribute.setConstantValue(this, undefined); t.ok(attribute.allocate(4), 'allocate successful'); t.is(attribute.value, allocatedValue, 'reused the same typed array'); @@ -136,14 +136,14 @@ test('Attribute#setConstantValue', t => { t.ok(attribute.getValue().positions instanceof Buffer, 'attribute is using packed buffer'); attribute.needsRedraw({clearChangedFlags: true}); - attribute.setConstantValue([0, 0, 0]); + attribute.setConstantValue(this, [0, 0, 0]); t.deepEqual(attribute.getValue().positions, [0, 0, 0], 'attribute set to constant value'); t.ok(attribute.needsRedraw({clearChangedFlags: true}), 'attribute marked needs redraw'); - attribute.setConstantValue([0, 0, 0]); + attribute.setConstantValue(this, [0, 0, 0]); t.notOk(attribute.needsRedraw({clearChangedFlags: true}), 'attribute should not need redraw'); - attribute.setConstantValue([0, 0, 1]); + attribute.setConstantValue(this, [0, 0, 1]); t.deepEqual(attribute.getValue().positions, [0, 0, 1], 'attribute set to constant value'); t.ok(attribute.needsRedraw({clearChangedFlags: true}), 'attribute marked needs redraw'); @@ -156,7 +156,7 @@ test('Attribute#setConstantValue', t => { accessor: 'getColor' }); - attribute.setConstantValue([255, 255, 0]); + attribute.setConstantValue(this, [255, 255, 0]); t.deepEqual(attribute.getValue().colors, [1, 1, 0], 'constant value is normalized'); t.end(); @@ -277,7 +277,8 @@ test('Attribute#updateBuffer', t => { {id: 'E', value: 0, color: undefined} ], getColor: d => d.color, - getValue: d => d.value + getValue: d => d.value, + getValueConstant: [20] }; const TEST_PARAMS = [ @@ -341,6 +342,18 @@ test('Attribute#updateBuffer', t => { standard: [20, 40, 14, 0], 'variable size': [20, 20, 40, 14, 14, 14, 14, 0, 0, 0] }, + { + title: 'constant accessor with transform', + attribute: new Attribute(device, { + id: 'values', + type: 'float32', + size: 1, + accessor: 'getValueConstant', + transform: x => x * 2 + }), + standard: [40, 40, 40, 40], + 'variable size': [40, 40, 40, 40, 40, 40, 40, 40, 40, 40] + }, { title: 'custom accessor', attribute: new Attribute(device, { @@ -1114,7 +1127,7 @@ test('Attribute#updateBuffer', t => { t.is(bounds, attribute.getBounds(), 'bounds is cached'); attribute.setNeedsUpdate(); - attribute.setConstantValue([-1, 0, 1]); + attribute.setConstantValue(this, [-1, 0, 1]); bounds = attribute.getBounds(); t.deepEqual(