-
Notifications
You must be signed in to change notification settings - Fork 13
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
DM-10830: Optimize the performance of multi-trace chart updates #397
Changes from 7 commits
c8743ad
d76da65
eadf0f8
f1e8e66
f266326
ab8f390
464634f
313a4f5
99d2125
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
* Utilities related to charts | ||
* Created by tatianag on 3/17/16. | ||
*/ | ||
import {get, uniqueId, isUndefined, omitBy, zip, isEmpty, range, set, isObject, isPlainObject, pick, cloneDeep, merge} from 'lodash'; | ||
import {get, uniqueId, isUndefined, omitBy, zip, isEmpty, range, set, isObject, pick, cloneDeep, merge} from 'lodash'; | ||
import shallowequal from 'shallowequal'; | ||
|
||
import {flux} from '../Firefly.js'; | ||
|
@@ -32,13 +32,15 @@ export const HISTOGRAM = 'histogram'; | |
|
||
export const SELECTED_COLOR = '#ffc800'; | ||
export const SELECTED_PROPS = { | ||
name: '__SELECTED', | ||
marker: {color: SELECTED_COLOR}, | ||
error_x: {color: SELECTED_COLOR}, | ||
error_y: {color: SELECTED_COLOR} | ||
}; | ||
|
||
export const HIGHLIGHTED_COLOR = '#ffa500'; | ||
export const HIGHLIGHTED_PROPS = { | ||
name: '__HIGHLIGHTED', | ||
marker: {color: HIGHLIGHTED_COLOR, line: {width: 2, color: '#ffa500'}}, // increase highlight marker with line border | ||
error_x: {color: HIGHLIGHTED_COLOR}, | ||
error_y: {color: HIGHLIGHTED_COLOR} | ||
|
@@ -278,7 +280,7 @@ export function getOptionsUI(chartId) { | |
const {data, fireflyData, activeTrace=0} = getChartData(chartId); | ||
const type = get(data, [activeTrace, 'type'], 'scatter'); | ||
const dataType = get(fireflyData, [activeTrace, 'dataType'], ''); | ||
if (type === 'scatter') { | ||
if (type.includes('scatter')) { | ||
return ScatterOptions; | ||
} else if (type === 'histogram') { | ||
return HistogramOptions; | ||
|
@@ -292,7 +294,7 @@ export function getOptionsUI(chartId) { | |
export function getToolbarUI(chartId, activeTrace=0) { | ||
const {data, fireflyData} = getChartData(chartId); | ||
const type = get(data, [activeTrace, 'type'], ''); | ||
if (type === 'scatter') { | ||
if (type.includes('scatter')) { | ||
return ScatterToolbar; | ||
} else { | ||
return BasicToolbar; | ||
|
@@ -327,7 +329,7 @@ export function newTraceFrom(data, selIndexes, newTraceProps) { | |
}); | ||
} | ||
deepReplace(sdata); | ||
const flatprops = flattenObject(newTraceProps, isPlainObject); | ||
const flatprops = flattenObject(newTraceProps); | ||
Object.entries(flatprops).forEach(([k,v]) => set(sdata, k, v)); | ||
return sdata; | ||
} | ||
|
@@ -474,7 +476,7 @@ function makeTableSources(chartId, data=[], fireflyData=[]) { | |
const currentData = (data.length < fireflyData.length) ? fireflyData : data; | ||
|
||
return currentData.map((d, traceNum) => { | ||
const ds = data[traceNum] ? convertToDS(flattenObject(data[traceNum], isPlainObject)) : {}; //avoid flattening arrays | ||
const ds = data[traceNum] ? convertToDS(flattenObject(data[traceNum])) : {}; //avoid flattening arrays | ||
if (!ds.tbl_id) { | ||
// table id can be a part of fireflyData | ||
const tbl_id = get(fireflyData, `${traceNum}.tbl_id`); | ||
|
@@ -548,6 +550,28 @@ export function applyDefaults(chartData={}) { | |
chartData.layout = merge(defaultLayout, chartData.layout); | ||
} | ||
|
||
// color-blind friendly colors | ||
const TRACE_COLORS = [ '#333333', '#ff3333', '#00ccff','#336600', | ||
'#9900cc', '#ff9933', '#009999', '#66ff33', '#cc9999', | ||
'#333333', '#b22424', '#008fb2', '#244700', | ||
'#6b008f', '#b26b24', '#006b6b', '#47b224', '8F6B6B']; | ||
export function getNewTraceDefaults(type='', traceNum=0) { | ||
if (type.includes(SCATTER)) { | ||
return { | ||
[`data.${traceNum}.type`] : type, //make sure trace type is set | ||
[`data.${traceNum}.marker.color`]: TRACE_COLORS[traceNum] || undefined, | ||
[`data.${traceNum}.marker.line`]: 'none', | ||
[`data.${traceNum}.showlegend`]: true, | ||
['layout.xaxis.range'] : undefined, //clear out fixed range | ||
['layout.yaxis.range'] : undefined, //clear out fixed range | ||
}; | ||
} else { | ||
return { | ||
[`data.${traceNum}.marker.color`]: TRACE_COLORS[traceNum] || undefined, | ||
[`data.${traceNum}.showlegend`]: true | ||
}; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that the defaults behave differently for scatter and scattergl. Also, in scattergl, the spikes (vertical and horizontal droplines meeting at the point) are shown by default, while they are not shown by default in scatter plot. For crowded charts these lines are convenient, but since the spikes do not extend all the way, the direction is wrong when axes are on the opposite sides. None of the spike attributes listed in the documentation take effect for scattergl at the moment. mirror axis attribute does not work either. So the workaround would be to remove the options for opposite axis location. (As well as for reverse.) |
||
|
||
|
||
|
||
|
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.
I think, when the type is not SCATTER this function returns undefined, which is causing the type error, which I mentioned before (when we are trying to use the result as an array).