Skip to content

Commit 4f6ea7e

Browse files
committed
introduce axis breaks attributes
... including potential future attributes `gap` and `gapmode`
1 parent 80262b5 commit 4f6ea7e

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

src/plots/cartesian/layout_attributes.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,135 @@ module.exports = {
248248
'Moreover, note that matching axes must have the same `type`.'
249249
].join(' ')
250250
},
251+
252+
breaks: templatedArray('break', {
253+
enabled: {
254+
valType: 'boolean',
255+
role: 'info',
256+
dflt: true,
257+
editType: 'calc',
258+
description: [
259+
'Determines whether this axis break is enabled or disabled.'
260+
].join(' ')
261+
},
262+
263+
bounds: {
264+
valType: 'info_array',
265+
role: 'info',
266+
items: [
267+
{valType: 'any', editType: 'calc'},
268+
{valType: 'any', editType: 'calc'}
269+
],
270+
editType: 'calc',
271+
description: [
272+
'Sets the lower and upper bounds of this axis break.',
273+
'Can be used with `operation` to determine the behavior at the bounds.',
274+
'On *date* axes, it can be used `pattern`.'
275+
].join(' ')
276+
},
277+
278+
pattern: {
279+
valType: 'enumerated',
280+
// TODO could add '%H:%M:%S'
281+
values: ['%w', '%H', ''],
282+
dflt: '',
283+
role: 'info',
284+
editType: 'calc',
285+
description: [
286+
'Only coerced on *date* axes.',
287+
'Determines a pattern on the time line that generates breaks.',
288+
'If *%w* - Sunday-based weekday as a decimal number [0, 6].',
289+
'If *%H* - hour (24-hour clock) as a decimal number [0, 23].',
290+
'These are the same directive as in `tickformat`, see',
291+
'https://github.com/d3/d3-time-format#locale_format',
292+
'for more info.',
293+
'Examples:',
294+
'- { pattern: \'%w\', bounds: [6, 0], operation: \'[]\' }',
295+
' breaks from Saturday to Monday (i.e. skips the weekends).',
296+
'- { pattern: \'%H\', bounds: [17, 8] }',
297+
' breaks from 5pm to 8am (i.e. skips non-work hours).'
298+
].join(' ')
299+
},
300+
301+
values: {
302+
valType: 'info_array',
303+
freeLength: true,
304+
role: 'info',
305+
editType: 'calc',
306+
items: {
307+
valType: 'any',
308+
editType: 'calc'
309+
},
310+
description: [
311+
'Sets the coordinate values corresponding to the breaks.',
312+
'An alternative to `bounds`.',
313+
'Use `dvalue` to set the spread of the values along the axis.'
314+
].join(' ')
315+
},
316+
dvalue: {
317+
// TODO could become 'any' to add support for 'months', 'years'
318+
valType: 'number',
319+
role: 'info',
320+
editType: 'calc',
321+
min: 0,
322+
description: [
323+
'Sets the spread of each `values` item.',
324+
'For *linear* axes, the default is *1*.',
325+
'For *date* axes, the default is one day in milliseconds.'
326+
].join(' ')
327+
},
328+
329+
operation: {
330+
valType: 'enumerated',
331+
values: ['[]', '()', '[)', '(]'],
332+
dflt: '()',
333+
role: 'info',
334+
editType: 'calc',
335+
description: [
336+
'Determines if we include or not the bound values within the break.',
337+
'Closed interval bounds (i.e. starting with *[* or ending with *]*)',
338+
'include the bound value within the break and thus make coordinates',
339+
'equal to the bound disappear.',
340+
'Open interval bounds (i.e. starting with *(* or ending with *)*)',
341+
'does not include the bound value within the break and thus keep coordinates',
342+
'equal to the bound on the axis.'
343+
].join(' ')
344+
},
345+
346+
/*
347+
gap: {
348+
valType: 'number',
349+
min: 0,
350+
dflt: 0, // for *date* axes, maybe something else for *linear*
351+
editType: 'calc',
352+
role: 'info',
353+
description: [
354+
'Sets the gap distance between the start and the end of this break.',
355+
'Use with `gapmode` to set the unit of measurement.'
356+
].join(' ')
357+
},
358+
gapmode: {
359+
valType: 'enumerated',
360+
values: ['pixels', 'fraction'],
361+
dflt: 'pixels',
362+
editType: 'calc',
363+
role: 'info',
364+
description: [
365+
'Determines if the `gap` value corresponds to a pixel length',
366+
'or a fraction of the plot area.'
367+
].join(' ')
368+
},
369+
*/
370+
371+
// To complete https://github.com/plotly/plotly.js/issues/4210
372+
// we additionally need `gap` and make this work on *linear*, and
373+
// possibly all other cartesian axis types. We possibly would also need
374+
// some style attributes controlling the zig-zag on the corresponding
375+
// axis.
376+
377+
editType: 'calc'
378+
}),
379+
251380
// ticks
252381
tickmode: {
253382
valType: 'enumerated',

0 commit comments

Comments
 (0)