-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
feat: Make time shifted series colors match the original series #24048
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* eslint-disable camelcase */ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitationsxw | ||
* under the License. | ||
*/ | ||
import { JsonObject } from '@superset-ui/core'; | ||
import { isString } from 'lodash'; | ||
|
||
export const hasTimeOffset = ( | ||
series: JsonObject, | ||
timeCompare: string[], | ||
): boolean => | ||
isString(series.name) | ||
? !!timeCompare.find( | ||
timeOffset => | ||
// offset is represented as <offset>, group by list | ||
series.name.includes(`${timeOffset},`) || | ||
// offset is represented as <metric>__<offset> | ||
series.name.includes(`__${timeOffset}`), | ||
) | ||
: false; | ||
|
||
export const getOriginalSeries = ( | ||
seriesName: string, | ||
timeCompare: string[], | ||
): string => { | ||
let result = seriesName; | ||
timeCompare.forEach(compare => { | ||
// offset is represented as <offset>, group by list | ||
result = result.replace(`${compare},`, ''); | ||
// offset is represented as <metric>__<offset> | ||
result = result.replace(`__${compare}`, ''); | ||
}); | ||
return result.trim(); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { getOriginalSeries } from '@superset-ui/chart-controls'; | ||
|
||
test('returns the series name when time compare is empty', () => { | ||
const seriesName = 'sum'; | ||
expect(getOriginalSeries(seriesName, [])).toEqual(seriesName); | ||
}); | ||
|
||
test('returns the original series name', () => { | ||
const seriesName = 'sum__1_month_ago'; | ||
const timeCompare = ['1_month_ago']; | ||
expect(getOriginalSeries(seriesName, timeCompare)).toEqual('sum'); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,12 @@ | |
* under the License. | ||
*/ | ||
/* eslint-disable camelcase */ | ||
import { invert } from 'lodash'; | ||
import { | ||
AnnotationLayer, | ||
AxisType, | ||
CategoricalColorNamespace, | ||
ensureIsArray, | ||
GenericDataType, | ||
getMetricLabel, | ||
getNumberFormatter, | ||
|
@@ -36,6 +38,7 @@ import { | |
} from '@superset-ui/core'; | ||
import { | ||
extractExtraMetrics, | ||
getOriginalSeries, | ||
isDerivedSeries, | ||
} from '@superset-ui/chart-controls'; | ||
import { EChartsCoreOption, SeriesOption } from 'echarts'; | ||
|
@@ -227,30 +230,43 @@ export default function transformProps( | |
contributionMode || isAreaExpand ? ',.0%' : yAxisFormat, | ||
); | ||
|
||
const array = ensureIsArray(chartProps.rawFormData?.time_compare); | ||
const inverted = invert(verboseMap); | ||
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. The data series are transformed to use the verbose name but I need the original name to compare against the result. |
||
|
||
rawSeries.forEach(entry => { | ||
const lineStyle = isDerivedSeries(entry, chartProps.rawFormData) | ||
? { type: 'dashed' as ZRLineType } | ||
: {}; | ||
const transformedSeries = transformSeries(entry, colorScale, { | ||
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. A thought for future improvement - we may want to use different patterns to disambiguate the different derived series from one another. dasharray could be useful to create half a dozen or so different patterns: 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. @villebro we did a quick hackathon on this, and the echart option works great. We haven't put up a PR yet because there's more that needs to be done around toggling the visualization on/off per user. 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. @eschutho nice, this would be a really nice improvement! ❤️ |
||
area, | ||
filterState, | ||
seriesContexts, | ||
markerEnabled, | ||
markerSize, | ||
areaOpacity: opacity, | ||
seriesType, | ||
stack, | ||
formatter, | ||
showValue, | ||
onlyTotal, | ||
totalStackedValues: sortedTotalValues, | ||
showValueIndexes, | ||
thresholdValues, | ||
richTooltip, | ||
sliceId, | ||
isHorizontal, | ||
lineStyle, | ||
}); | ||
|
||
const entryName = String(entry.name || ''); | ||
const seriesName = inverted[entryName] || entryName; | ||
const colorScaleKey = getOriginalSeries(seriesName, array); | ||
|
||
const transformedSeries = transformSeries( | ||
entry, | ||
colorScale, | ||
colorScaleKey, | ||
{ | ||
area, | ||
filterState, | ||
seriesContexts, | ||
markerEnabled, | ||
markerSize, | ||
areaOpacity: opacity, | ||
seriesType, | ||
stack, | ||
formatter, | ||
showValue, | ||
onlyTotal, | ||
totalStackedValues: sortedTotalValues, | ||
showValueIndexes, | ||
thresholdValues, | ||
richTooltip, | ||
sliceId, | ||
isHorizontal, | ||
lineStyle, | ||
}, | ||
); | ||
if (transformedSeries) { | ||
if (stack === StackControlsValue.Stream) { | ||
// bug in Echarts - `stackStrategy: 'all'` doesn't work with nulls, so we cast them to 0 | ||
|
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.
@villebro I tried changing the way metrics with and without dimensions are displayed but ended up in a rabbit hole. I decided to restrain the scope of the PR. If we decide to change that later, it will be easy to simplify this code.
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.
Sounds good, I can take a stab at it, too 👍