-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
image trace type #4289
Merged
image trace type #4289
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8429245
image: attributes
antoinerg e86c95b
image: implementation
antoinerg e7eeb38
add category 'noSortingByValue' and tag appropriate Cartesian traces
antoinerg 73c0740
image: fix style, update attribute's valType and description
antoinerg 10c9914
image: put imagelayer underneath heatmap
antoinerg b998a17
image: fix zmin/zmax description, test zmin/zmax with wrong length array
antoinerg dec9469
image: remove dimensions in zmin attribute definition
antoinerg 15c06fa
image: handle missing pixels in z
antoinerg 2d393dd
image: use maxRowLength to find the width of z
antoinerg fa04037
image: fix log axis range, add support for categorical axis
antoinerg 0eb6604
image: add editType clearAxisTypes to `x0` and `y0`
antoinerg e2a9c6e
image: :lock: down that `x0` and `y0` can be restyled to/from category
antoinerg a98ac44
image: in hovertemplate, rename c to color
antoinerg fd51e20
image: add (hover)text attributes with test
antoinerg 5d7f9a4
image: :hocho: duplicated logic in event_data, enforce dim of color
antoinerg e4cac27
image: do not display color information by default
antoinerg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Copyright 2012-2019, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = require('../src/traces/image'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* Copyright 2012-2019, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var plotAttrs = require('../../plots/attributes'); | ||
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs; | ||
var extendFlat = require('../../lib/extend').extendFlat; | ||
var colormodel = require('./constants').colormodel; | ||
|
||
var cm = ['rgb', 'rgba', 'hsl', 'hsla']; | ||
var zminDesc = []; | ||
var zmaxDesc = []; | ||
for(var i = 0; i < cm.length; i++) { | ||
zminDesc.push('For the `' + cm[i] + '` colormodel, it is [' + colormodel[cm[i]].min.join(', ') + '].'); | ||
zmaxDesc.push('For the `' + cm[i] + '` colormodel, it is [' + colormodel[cm[i]].max.join(', ') + '].'); | ||
} | ||
|
||
module.exports = extendFlat({ | ||
z: { | ||
valType: 'data_array', | ||
role: 'info', | ||
editType: 'calc', | ||
description: [ | ||
'A 2-dimensional array in which each element is an array of 3 or 4 numbers representing a color.', | ||
].join(' ') | ||
}, | ||
colormodel: { | ||
valType: 'enumerated', | ||
values: cm, | ||
dflt: 'rgb', | ||
role: 'info', | ||
editType: 'plot', | ||
description: 'Color model used to map the numerical color components described in `z` into colors.' | ||
}, | ||
zmin: { | ||
valType: 'info_array', | ||
items: [ | ||
{valType: 'number', editType: 'plot'}, | ||
{valType: 'number', editType: 'plot'}, | ||
{valType: 'number', editType: 'plot'}, | ||
{valType: 'number', editType: 'plot'} | ||
], | ||
role: 'info', | ||
editType: 'plot', | ||
description: [ | ||
'Array defining the lower bound for each color component.', | ||
'Note that the default value will depend on the colormodel.', | ||
zminDesc.join(' ') | ||
].join(' ') | ||
}, | ||
zmax: { | ||
valType: 'info_array', | ||
items: [ | ||
{valType: 'number', editType: 'plot'}, | ||
{valType: 'number', editType: 'plot'}, | ||
{valType: 'number', editType: 'plot'}, | ||
{valType: 'number', editType: 'plot'} | ||
], | ||
role: 'info', | ||
editType: 'plot', | ||
description: [ | ||
'Array defining the higher bound for each color component.', | ||
'Note that the default value will depend on the colormodel.', | ||
zmaxDesc.join(' ') | ||
].join(' ') | ||
}, | ||
x0: { | ||
valType: 'number', | ||
dflt: 0, | ||
role: 'info', | ||
editType: 'calc', | ||
etpinard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
description: 'Set the image\'s x position.' | ||
}, | ||
y0: { | ||
valType: 'number', | ||
dflt: 0, | ||
role: 'info', | ||
editType: 'calc', | ||
description: 'Set the image\'s y position.' | ||
}, | ||
dx: { | ||
valType: 'number', | ||
dflt: 1, | ||
role: 'info', | ||
editType: 'calc', | ||
description: 'Set the pixel\'s horizontal size.' | ||
}, | ||
dy: { | ||
valType: 'number', | ||
dflt: 1, | ||
role: 'info', | ||
editType: 'calc', | ||
description: 'Set the pixel\'s vertical size' | ||
}, | ||
hoverinfo: extendFlat({}, plotAttrs.hoverinfo, { | ||
flags: ['x', 'y', 'z', 'color', 'name'] | ||
}), | ||
hovertemplate: hovertemplateAttrs({}, { | ||
keys: ['z', 'c', 'colormodel'] | ||
etpinard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright 2012-2019, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var Axes = require('../../plots/cartesian/axes'); | ||
|
||
module.exports = function calc(gd, trace) { | ||
var xa = Axes.getFromId(gd, trace.xaxis || 'x'); | ||
var ya = Axes.getFromId(gd, trace.yaxis || 'y'); | ||
|
||
var x0 = trace.x0 - trace.dx / 2; | ||
var y0 = trace.y0 - trace.dy / 2; | ||
var h = trace.z.length; | ||
var w = trace.z[0].length; | ||
etpinard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
trace._extremes[xa._id] = Axes.findExtremes(xa, [x0, x0 + w * trace.dx]); | ||
trace._extremes[ya._id] = Axes.findExtremes(ya, [y0, y0 + h * trace.dy]); | ||
|
||
var cd0 = { | ||
x0: x0, | ||
y0: y0, | ||
z: trace.z, | ||
w: w, | ||
h: h | ||
}; | ||
return [cd0]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright 2012-2019, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
colormodel: { | ||
rgb: { | ||
min: [0, 0, 0], | ||
max: [255, 255, 255], | ||
fmt: function(c) {return c.slice(0, 3);}, | ||
suffix: ['', '', ''] | ||
}, | ||
rgba: { | ||
min: [0, 0, 0, 0], | ||
max: [255, 255, 255, 1], | ||
fmt: function(c) {return c.slice(0, 4);}, | ||
suffix: ['', '', '', ''] | ||
}, | ||
hsl: { | ||
min: [0, 0, 0], | ||
max: [360, 100, 100], | ||
fmt: function(c) { | ||
var p = c.slice(0, 3); | ||
p[1] = p[1] + '%'; | ||
p[2] = p[2] + '%'; | ||
return p; | ||
}, | ||
suffix: ['°', '%', '%'] | ||
}, | ||
hsla: { | ||
min: [0, 0, 0, 0], | ||
max: [360, 100, 100, 1], | ||
fmt: function(c) { | ||
var p = c.slice(0, 4); | ||
p[1] = p[1] + '%'; | ||
p[2] = p[2] + '%'; | ||
return p; | ||
}, | ||
suffix: ['°', '%', '%', ''] | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright 2012-2019, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
var Lib = require('../../lib'); | ||
var attributes = require('./attributes'); | ||
var constants = require('./constants'); | ||
|
||
module.exports = function supplyDefaults(traceIn, traceOut) { | ||
function coerce(attr, dflt) { | ||
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt); | ||
} | ||
var z = coerce('z'); | ||
if(z === undefined || !z.length || !z[0] || !z[0].length) { | ||
traceOut.visible = false; | ||
return; | ||
} | ||
|
||
coerce('x0'); | ||
coerce('y0'); | ||
coerce('dx'); | ||
coerce('dy'); | ||
var colormodel = coerce('colormodel'); | ||
|
||
coerce('zmin', constants.colormodel[colormodel].min); | ||
coerce('zmax', constants.colormodel[colormodel].max); | ||
|
||
coerce('hovertemplate'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright 2012-2019, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function eventData(out, pt) { | ||
out.colormodel = pt.trace.colormodel; | ||
if('xVal' in pt) out.x = pt.xVal; | ||
if('yVal' in pt) out.y = pt.yVal; | ||
if(pt.xa) out.xaxis = pt.xa; | ||
if(pt.ya) out.yaxis = pt.ya; | ||
out.c = pt.c; | ||
return out; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* Copyright 2012-2019, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var Fx = require('../../components/fx'); | ||
var Lib = require('../../lib'); | ||
var constants = require('./constants'); | ||
|
||
module.exports = function hoverPoints(pointData, xval, yval) { | ||
var cd0 = pointData.cd[0]; | ||
var trace = cd0.trace; | ||
var xa = pointData.xa; | ||
var ya = pointData.ya; | ||
|
||
// Return early if not on image | ||
if(Fx.inbox(xval - cd0.x0, xval - (cd0.x0 + cd0.w * trace.dx), 0) > 0 || | ||
Fx.inbox(yval - cd0.y0, yval - (cd0.y0 + cd0.h * trace.dy), 0) > 0) { | ||
return; | ||
} | ||
|
||
// Find nearest pixel's index | ||
var nx = Math.floor((xval - cd0.x0) / trace.dx); | ||
var ny = Math.floor(Math.abs(yval - cd0.y0) / trace.dy); | ||
|
||
var hoverinfo = cd0.hi || trace.hoverinfo; | ||
var fmtColor; | ||
if(hoverinfo) { | ||
var parts = hoverinfo.split('+'); | ||
if(parts.indexOf('all') !== -1) parts = ['color']; | ||
if(parts.indexOf('color') !== -1) fmtColor = true; | ||
} | ||
|
||
var colormodel = trace.colormodel; | ||
var dims = colormodel.length; | ||
var c = trace._scaler(cd0.z[ny][nx]); | ||
var s = constants.colormodel[colormodel].suffix; | ||
|
||
var colorstring = []; | ||
if(trace.hovertemplate || fmtColor) { | ||
colorstring.push('[' + [c[0] + s[0], c[1] + s[1], c[2] + s[2]].join(', ')); | ||
if(dims === 4) colorstring.push(', ' + c[3] + s[3]); | ||
colorstring.push(']'); | ||
colorstring = colorstring.join(''); | ||
pointData.extraText = colormodel.toUpperCase() + ': ' + colorstring; | ||
} | ||
|
||
var py = ya.c2p(cd0.y0 + (ny + 0.5) * trace.dy); | ||
var xVal = cd0.x0 + (nx + 0.5) * trace.dx; | ||
var yVal = cd0.y0 + (ny + 0.5) * trace.dy; | ||
etpinard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var zLabel = '[' + cd0.z[ny][nx].slice(0, trace.colormodel.length).join(', ') + ']'; | ||
return [Lib.extendFlat(pointData, { | ||
index: [ny, nx], | ||
x0: xa.c2p(cd0.x0 + nx * trace.dx), | ||
x1: xa.c2p(cd0.x0 + (nx + 1) * trace.dx), | ||
y0: py, | ||
y1: py, | ||
c: c, | ||
xVal: xVal, | ||
xLabelVal: xVal, | ||
yVal: yVal, | ||
yLabelVal: yVal, | ||
zLabelVal: zLabel, | ||
hovertemplateLabels: { | ||
'zLabel': zLabel, | ||
'cLabel': colorstring, | ||
'c[0]Label': c[0] + s[0], | ||
'c[1]Label': c[1] + s[1], | ||
'c[2]Label': c[2] + s[2] | ||
} | ||
})]; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So no
x
andy
for this iteration? Is that intended?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, this wasn't a requirement for that iteration so I did not include it. For your information, most other libraries do not support this either. It is usually assumed that an image is made of pixels of identical size arranged in a regular fashion as in a square crystal lattice. I'd be surprised if users ask for
x
andy
but we'll see 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x0
anddx
seem enough for a v1... any obvious cases where that wouldn't be enough? @jonmmease @emmanuelle @alexcjohnson ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I'm also very much ok with not implementing
x
andy
in this iteration.