Skip to content

Commit

Permalink
fix: annotations on horizontal bar chart (apache#31308)
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianPendrak authored Dec 5, 2024
1 parent 6af22a9 commit 2816a70
Show file tree
Hide file tree
Showing 3 changed files with 374 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ export default function transformProps(
xAxisType,
colorScale,
sliceId,
orientation,
),
);
else if (isIntervalAnnotationLayer(layer)) {
Expand All @@ -395,6 +396,7 @@ export default function transformProps(
colorScale,
theme,
sliceId,
orientation,
),
);
} else if (isEventAnnotationLayer(layer)) {
Expand All @@ -406,6 +408,7 @@ export default function transformProps(
colorScale,
theme,
sliceId,
orientation,
),
);
} else if (isTimeseriesAnnotationLayer(layer)) {
Expand All @@ -417,6 +420,7 @@ export default function transformProps(
annotationData,
colorScale,
sliceId,
orientation,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
EchartsTimeseriesSeriesType,
ForecastSeriesEnum,
LegendOrientation,
OrientationType,
StackType,
} from '../types';

Expand Down Expand Up @@ -364,8 +365,11 @@ export function transformFormulaAnnotation(
xAxisType: AxisType,
colorScale: CategoricalColorScale,
sliceId?: number,
orientation?: OrientationType,
): SeriesOption {
const { name, color, opacity, width, style } = layer;
const isHorizontal = orientation === OrientationType.Horizontal;

return {
name,
id: name,
Expand All @@ -379,7 +383,9 @@ export function transformFormulaAnnotation(
},
type: 'line',
smooth: true,
data: evalFormula(layer, data, xAxisCol, xAxisType),
data: evalFormula(layer, data, xAxisCol, xAxisType).map(([x, y]) =>
isHorizontal ? [y, x] : [x, y],
),
symbolSize: 0,
};
}
Expand All @@ -391,25 +397,25 @@ export function transformIntervalAnnotation(
colorScale: CategoricalColorScale,
theme: SupersetTheme,
sliceId?: number,
orientation?: OrientationType,
): SeriesOption[] {
const series: SeriesOption[] = [];
const annotations = extractRecordAnnotations(layer, annotationData);
annotations.forEach(annotation => {
const { name, color, opacity, showLabel } = layer;
const { descriptions, intervalEnd, time, title } = annotation;
const label = formatAnnotationLabel(name, title, descriptions);
const isHorizontal = orientation === OrientationType.Horizontal;
const intervalData: (
| MarkArea1DDataItemOption
| MarkArea2DDataItemOption
)[] = [
[
{
name: label,
xAxis: time,
},
{
xAxis: intervalEnd,
...(isHorizontal ? { yAxis: time } : { xAxis: time }),
},
isHorizontal ? { yAxis: intervalEnd } : { xAxis: intervalEnd },
],
];
const intervalLabel: SeriesLabelOption = showLabel
Expand Down Expand Up @@ -466,17 +472,19 @@ export function transformEventAnnotation(
colorScale: CategoricalColorScale,
theme: SupersetTheme,
sliceId?: number,
orientation?: OrientationType,
): SeriesOption[] {
const series: SeriesOption[] = [];
const annotations = extractRecordAnnotations(layer, annotationData);
annotations.forEach(annotation => {
const { name, color, opacity, style, width, showLabel } = layer;
const { descriptions, time, title } = annotation;
const label = formatAnnotationLabel(name, title, descriptions);
const isHorizontal = orientation === OrientationType.Horizontal;
const eventData: MarkLine1DDataItemOption[] = [
{
name: label,
xAxis: time,
...(isHorizontal ? { yAxis: time } : { xAxis: time }),
},
];

Expand Down Expand Up @@ -539,18 +547,24 @@ export function transformTimeseriesAnnotation(
annotationData: AnnotationData,
colorScale: CategoricalColorScale,
sliceId?: number,
orientation?: OrientationType,
): SeriesOption[] {
const series: SeriesOption[] = [];
const { hideLine, name, opacity, showMarkers, style, width, color } = layer;
const result = annotationData[name];
const isHorizontal = orientation === OrientationType.Horizontal;
if (isTimeseriesAnnotationResult(result)) {
result.forEach(annotation => {
const { key, values } = annotation;
series.push({
type: 'line',
id: key,
name: key,
data: values.map(row => [row.x, row.y] as [OptionName, number]),
data: values.map(({ x, y }) =>
isHorizontal
? ([y, x] as [number, OptionName])
: ([x, y] as [OptionName, number]),
),
symbolSize: showMarkers ? markerSize : 0,
lineStyle: {
opacity: parseAnnotationOpacity(opacity),
Expand Down
Loading

0 comments on commit 2816a70

Please sign in to comment.