You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Several methods like 'calculateLabelPosition' of SunburstArcLabelDecorator require downcasting. For example:
@overrideArcLabelPositioncalculateLabelPosition(
TextElement labelElement,
TextStyle labelStyle,
int insideArcWidth,
int outsideArcWidth,
ArcRendererElement<D> arcRendererElement,
ArcLabelPosition labelPosition,
) {
assert(arcRendererElement isSunburstArcRendererElement);
if ((arcRendererElement asSunburstArcRendererElement).isOuterMostRing ==true) {
returnsuper.calculateLabelPosition(
labelElement,
labelStyle,
insideArcWidth,
outsideArcWidth,
arcRendererElement,
outerRingArcLabelPosition,
);
} elseif (arcRendererElement.isLeaf ==true) {
returnsuper.calculateLabelPosition(
labelElement,
labelStyle,
insideArcWidth,
outsideArcWidth,
arcRendererElement,
innerRingLeafArcLabelPosition,
);
} else {
/// TODO: Improve label handling for sunburst chart. When a /// more sophisticated collision detection is in place, we can draw the /// label for inner arc outside when it doesn't collide with outer arcs.// Force label for arc on the inner ring inside.returnArcLabelPosition.inside;
}
}
You can see that in the above method, there is a runtime assertion that could cause an exception when this would not be necessary with an extra type argument. If we gave an extra type like this:
classSunburstArcLabelDecorator<D>
extendsArcLabelDecorator<D, SunburstArcRendererElement<D>> { }
/// New base type for renderer elementsabstractclassBaseRendererElement<D> {
Color? color;
int? index;
num? key;
D? domain;
lateImmutableSeries<D> series;
voidupdateAnimationPercent(
BaseRendererElement<D> previous,
BaseRendererElement<D> target,
double animationPercent,
);
// BaseRendererElement<D> clone();
}
// ...// We can do this:@overrideArcLabelPositioncalculateLabelPosition(
TextElement labelElement,
TextStyle labelStyle,
int insideArcWidth,
int outsideArcWidth,
SunburstArcRendererElement<D> arcRendererElement,
ArcLabelPosition labelPosition,
) {
if (arcRendererElement.isOuterMostRing ??false) {
returnsuper.calculateLabelPosition(
labelElement,
labelStyle,
insideArcWidth,
outsideArcWidth,
arcRendererElement,
outerRingArcLabelPosition,
);
} elseif (arcRendererElement.isLeaf ==true) {
returnsuper.calculateLabelPosition(
labelElement,
labelStyle,
insideArcWidth,
outsideArcWidth,
arcRendererElement,
innerRingLeafArcLabelPosition,
);
} else {
/// TODO: Improve label handling for sunburst chart. When a /// more sophisticated collision detection is in place, we can draw the /// label for inner arc outside when it doesn't collide with outer arcs.// Force label for arc on the inner ring inside.returnArcLabelPosition.inside;
}
}
}
This makes the assertion exception impossible in the first place. This means we have to ripple the new type arguments all throughout the common package like this:
It's a big change, but I don't think it would be possible to do this without affecting the example app, and most other apps won't need to change code unless there are a lot of custom charts.
I have started on this change in the types2 branch. You can see how this change affects the common package in this branch.
Any discussion around why this might not work are welcome, but essentially, this removes a lot of dynamic typing, would allow for better compiler optimizations, and less need for casting and runtime errors.
The text was updated successfully, but these errors were encountered:
MelbourneDeveloper
changed the title
ArcRendererElement Generic Type Argument
RendererElement Generic Type Argument
Sep 28, 2024
Several methods like 'calculateLabelPosition' of
SunburstArcLabelDecorator
require downcasting. For example:You can see that in the above method, there is a runtime assertion that could cause an exception when this would not be necessary with an extra type argument. If we gave an extra type like this:
This makes the assertion exception impossible in the first place. This means we have to ripple the new type arguments all throughout the common package like this:
It's a big change, but I don't think it would be possible to do this without affecting the example app, and most other apps won't need to change code unless there are a lot of custom charts.
I have started on this change in the
types2
branch. You can see how this change affects the common package in this branch.Any discussion around why this might not work are welcome, but essentially, this removes a lot of dynamic typing, would allow for better compiler optimizations, and less need for casting and runtime errors.
The text was updated successfully, but these errors were encountered: