Skip to content

Commit 7be804e

Browse files
committed
one source of truth for event data keys used for doc and test
1 parent 6f86522 commit 7be804e

File tree

10 files changed

+48
-10
lines changed

10 files changed

+48
-10
lines changed

Diff for: src/components/fx/hovertemplate_attributes.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ module.exports = function(opts, extra) {
1515
var descPart = extra.description ? ' ' + extra.description : '';
1616
var keys = extra.keys || [];
1717
if(keys.length > 0) {
18+
var quotedKeys = [];
1819
for(var i = 0; i < keys.length; i++) {
19-
keys[i] = '`' + keys[i] + '`';
20+
quotedKeys[i] = '`' + keys[i] + '`';
2021
}
2122
descPart = descPart + 'This trace supports the additional ';
2223
if(keys.length === 1) {
23-
descPart = 'variable ' + keys[0];
24+
descPart = 'variable ' + quotedKeys[0];
2425
} else {
25-
descPart = 'variables ' + keys.slice(0, -1).join(', ') + ' and ' + keys.slice(-1) + '.';
26+
descPart = 'variables ' + quotedKeys.slice(0, -1).join(', ') + ' and ' + quotedKeys.slice(-1) + '.';
2627
}
2728
}
2829

Diff for: src/traces/bar/attributes.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var hovertemplateAttrs = require('../../components/fx/hovertemplate_attributes')
1313
var colorAttributes = require('../../components/colorscale/attributes');
1414
var colorbarAttrs = require('../../components/colorbar/attributes');
1515
var fontAttrs = require('../../plots/font_attributes');
16+
var constants = require('./constants.js')
1617

1718
var extendFlat = require('../../lib/extend').extendFlat;
1819

@@ -60,7 +61,9 @@ module.exports = {
6061

6162
text: scatterAttrs.text,
6263
hovertext: scatterAttrs.hovertext,
63-
hovertemplate: hovertemplateAttrs(),
64+
hovertemplate: hovertemplateAttrs({}, {
65+
keys: constants.eventDataKeys
66+
}),
6467

6568
textposition: {
6669
valType: 'enumerated',

Diff for: src/traces/bar/constants.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright 2012-2018, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
10+
'use strict';
11+
12+
module.exports = {
13+
eventDataKeys: []
14+
};

Diff for: src/traces/histogram/attributes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
var barAttrs = require('../bar/attributes');
1212
var hovertemplateAttrs = require('../../components/fx/hovertemplate_attributes');
1313
var makeBinAttrs = require('./bin_attributes');
14+
var constants = require('./constants');
1415

1516
module.exports = {
1617
x: {
@@ -187,7 +188,7 @@ module.exports = {
187188
},
188189

189190
hovertemplate: hovertemplateAttrs({}, {
190-
keys: ['binNumber']
191+
keys: constants.eventDataKeys
191192
}),
192193

193194
marker: barAttrs.marker,

Diff for: src/traces/histogram/constants.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright 2012-2018, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
10+
'use strict';
11+
12+
module.exports = {
13+
eventDataKeys: ['binNumber']
14+
};

Diff for: src/traces/scatter/attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ module.exports = {
205205
].join(' ')
206206
},
207207
hovertemplate: hovertemplateAttrs({}, {
208-
keys: ['marker.size', 'marker.color']
208+
keys: constants.eventDataKeys
209209
}),
210210
line: {
211211
color: {

Diff for: src/traces/scatter/constants.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ module.exports = {
2121

2222
// number of viewport sizes away from the visible region
2323
// at which we clip all lines to the perimeter
24-
maxScreensAway: 20
24+
maxScreensAway: 20,
25+
26+
eventDataKeys: ['marker.size', 'marker.color']
2527
};

Diff for: test/jasmine/tests/bar_test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var checkTicks = require('../assets/custom_assertions').checkTicks;
1414
var supplyAllDefaults = require('../assets/supply_defaults');
1515

1616
var checkEventData = require('../assets/check_event_data');
17+
var constants = require('@src/traces/bar/constants');
1718

1819
var customAssertions = require('../assets/custom_assertions');
1920
var assertClip = customAssertions.assertClip;
@@ -1861,7 +1862,7 @@ describe('bar hover', function() {
18611862

18621863
describe('event data', function() {
18631864
var mock = require('@mocks/stacked_bar');
1864-
checkEventData(mock, 216, 309, []);
1865+
checkEventData(mock, 216, 309, constants.eventDataKeys);
18651866
});
18661867

18671868
function mockBarPlot(dataWithoutTraceType, layout) {

Diff for: test/jasmine/tests/histogram_test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var supplyAllDefaults = require('../assets/supply_defaults');
1414
var failTest = require('../assets/fail_test');
1515

1616
var checkEventData = require('../assets/check_event_data');
17+
var constants = require('@src/traces/histogram/constants');
1718

1819
describe('Test histogram', function() {
1920
'use strict';
@@ -1064,5 +1065,5 @@ describe('getBinSpanLabelRound', function() {
10641065

10651066
describe('event data', function() {
10661067
var mock = require('@mocks/hist_category');
1067-
checkEventData(mock, 100, 200, ['binNumber']);
1068+
checkEventData(mock, 100, 200, constants.eventDataKeys);
10681069
});

Diff for: test/jasmine/tests/scatter_test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var assertClip = customAssertions.assertClip;
1515
var assertNodeDisplay = customAssertions.assertNodeDisplay;
1616
var assertMultiNodeOrder = customAssertions.assertMultiNodeOrder;
1717
var checkEventData = require('../assets/check_event_data');
18+
var constants = require('@src/traces/scatter/constants');
1819

1920
var getOpacity = function(node) { return Number(node.style.opacity); };
2021
var getFillOpacity = function(node) { return Number(node.style['fill-opacity']); };
@@ -1812,5 +1813,5 @@ describe('Test scatter *clipnaxis*:', function() {
18121813

18131814
describe('event data', function() {
18141815
var mock = require('@mocks/scatter-colorscale-colorbar');
1815-
checkEventData(mock, 540, 260, ['marker.size', 'marker.color']);
1816+
checkEventData(mock, 540, 260, constants.eventDataKeys);
18161817
});

0 commit comments

Comments
 (0)