-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove konva and add native canvas rendering (#540)
This commit remove the Konva and React-Konva dependencies in favour of a native canvas rendering. In the way we are refactoring the chart-library there weren't any benefit on using this library. The `LineStyle` style has a new property called `dash` to allow dashed lines styles in theme and through styleAccessor. We also fixed some rendering issues: points in stacked area charts are now rendered on top of the areas and the opacity of the bar borders is now correctly rendered.
- Loading branch information
Showing
99 changed files
with
2,277 additions
and
3,169 deletions.
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
Binary file modified
BIN
-476 Bytes
(98%)
...ests-for-all-stories-annotations-rect-styling-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-169 Bytes
(100%)
...ts-for-all-stories-area-chart-band-area-chart-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+387 Bytes
(100%)
...ll-stories-area-chart-stacked-band-area-chart-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+332 Bytes
(100%)
...-stories-area-chart-stacked-w-axis-and-legend-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+257 Bytes
(100%)
...hart-stacked-with-separated-specs-same-naming-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+332 Bytes
(100%)
...ories-area-chart-stacked-with-separated-specs-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.08 KB
(97%)
...-tests-for-all-stories-area-chart-with-4-axes-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-597 Bytes
(98%)
...or-all-stories-axis-customizing-domain-limits-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-43 Bytes
(100%)
...tests-for-all-stories-axis-w-many-tick-labels-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+794 Bytes
(100%)
...al-tests-for-all-stories-axis-with-multi-axis-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+60 Bytes
(100%)
...ests-for-all-stories-bar-chart-band-bar-chart-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-821 Bytes
(99%)
...r-all-stories-bar-chart-with-high-data-volume-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+22 Bytes
(100%)
...ts-for-all-stories-bar-chart-with-value-label-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-306 Bytes
(98%)
...es-grids-multiple-axes-with-the-same-position-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+425 Bytes
(100%)
...stories-interactions-crosshair-with-time-axis-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+371 Bytes
(100%)
...ries-legend-display-values-in-legend-elements-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-59 Bytes
(100%)
...-for-all-stories-legend-legend-spacing-buffer-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.66 KB
(99%)
...l-stories-line-chart-multiserieswithlogvalues-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+79 Bytes
(100%)
...-all-stories-mixed-charts-test-bar-lines-time-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-145 Bytes
(99%)
...s-for-all-stories-rotations-with-ordinal-axis-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+234 Bytes
(100%)
...-year-scale-custom-timezone-same-tone-tooltip-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+291 Bytes
(100%)
...ll-stories-stylings-custom-series-styles-area-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+67 Bytes
(100%)
...ll-stories-stylings-custom-series-styles-bars-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-3.52 KB
(94%)
...al-tests-for-all-stories-stylings-theme-style-visually-looks-correct-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-302 Bytes
(100%)
...st-ts-area-series-stories-accessor-formats-should-show-custom-format-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+387 Bytes
(100%)
...ley-scale-to-data-extent-is-false-should-show-correct-extents-banded-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+387 Bytes
(100%)
...ey-scale-to-data-extent-is-false-should-show-correct-extents-stacked-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+378 Bytes
(100%)
...aley-scale-to-data-extent-is-true-should-show-correct-extents-banded-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+378 Bytes
(100%)
...ley-scale-to-data-extent-is-true-should-show-correct-extents-stacked-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
-406 Bytes
(99%)
...napshots__/axis-stories-test-ts-axis-stories-should-hide-bottom-axis-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+651 Bytes
(100%)
...stories-should-render-proper-tick-count-with-show-overlapping-labels-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
-747 Bytes
(97%)
...shots__/axis-stories-test-ts-axis-stories-should-render-tick-padding-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
-64 Bytes
(100%)
...ories-test-ts-axis-stories-should-render-ticks-with-varied-rotations-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
-69 Bytes
(100%)
...shots__/legend-stories-test-ts-legend-stories-should-0-legend-buffer-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+35 Bytes
(100%)
...hots__/line-stories-test-ts-line-series-stories-rotation-rotation-90-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+4 Bytes
(100%)
...ne-stories-test-ts-line-series-stories-rotation-rotation-negative-90-1-snap.png
Oops, something went wrong.
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
38 changes: 38 additions & 0 deletions
38
src/chart_types/xy_chart/renderer/canvas/annotations/index.ts
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,38 @@ | ||
import { AnnotationDimensions } from '../../../annotations/annotation_utils'; | ||
import { AnnotationSpec, isLineAnnotation, isRectAnnotation } from '../../../utils/specs'; | ||
import { getSpecsById } from '../../../state/utils'; | ||
import { AnnotationId } from '../../../../../utils/ids'; | ||
import { mergeWithDefaultAnnotationLine, mergeWithDefaultAnnotationRect } from '../../../../../utils/themes/theme'; | ||
import { renderLineAnnotations } from './lines'; | ||
import { AnnotationLineProps } from '../../../annotations/line_annotation_tooltip'; | ||
import { renderRectAnnotations } from './rect'; | ||
import { AnnotationRectProps } from '../../../annotations/rect_annotation_tooltip'; | ||
|
||
interface AnnotationProps { | ||
annotationDimensions: Map<AnnotationId, AnnotationDimensions>; | ||
annotationSpecs: AnnotationSpec[]; | ||
} | ||
export function renderAnnotations( | ||
ctx: CanvasRenderingContext2D, | ||
props: AnnotationProps, | ||
renderOnBackground: boolean = true, | ||
) { | ||
const { annotationDimensions, annotationSpecs } = props; | ||
|
||
annotationDimensions.forEach((annotation, id) => { | ||
const spec = getSpecsById<AnnotationSpec>(annotationSpecs, id); | ||
if (!spec) { | ||
return null; | ||
} | ||
const isBackground = !spec.zIndex || (spec.zIndex && spec.zIndex <= 0); | ||
if ((isBackground && renderOnBackground) || (!isBackground && !renderOnBackground)) { | ||
if (isLineAnnotation(spec)) { | ||
const lineStyle = mergeWithDefaultAnnotationLine(spec.style); | ||
renderLineAnnotations(ctx, annotation as AnnotationLineProps[], lineStyle); | ||
} else if (isRectAnnotation(spec)) { | ||
const rectStyle = mergeWithDefaultAnnotationRect(spec.style); | ||
renderRectAnnotations(ctx, annotation as AnnotationRectProps[], rectStyle); | ||
} | ||
} | ||
}); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/chart_types/xy_chart/renderer/canvas/annotations/lines.ts
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,32 @@ | ||
import { Stroke, Line } from '../../../../../geoms/types'; | ||
import { stringToRGB } from '../../../../partition_chart/layout/utils/d3_utils'; | ||
import { AnnotationLineProps } from '../../../annotations/line_annotation_tooltip'; | ||
import { LineAnnotationStyle } from '../../../../../utils/themes/theme'; | ||
import { renderMultiLine } from '../primitives/line'; | ||
|
||
export function renderLineAnnotations( | ||
ctx: CanvasRenderingContext2D, | ||
annotations: AnnotationLineProps[], | ||
lineStyle: LineAnnotationStyle, | ||
) { | ||
const lines = annotations.map<Line>((annotation) => { | ||
const { | ||
start: { x1, y1 }, | ||
end: { x2, y2 }, | ||
} = annotation.linePathPoints; | ||
return { | ||
x1, | ||
y1, | ||
x2, | ||
y2, | ||
}; | ||
}); | ||
const strokeColor = stringToRGB(lineStyle.line.stroke); | ||
strokeColor.opacity = strokeColor.opacity * lineStyle.line.opacity; | ||
const stroke: Stroke = { | ||
color: strokeColor, | ||
width: lineStyle.line.strokeWidth, | ||
}; | ||
|
||
renderMultiLine(ctx, lines, stroke); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/chart_types/xy_chart/renderer/canvas/annotations/rect.ts
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 @@ | ||
import { renderRect } from '../primitives/rect'; | ||
import { Rect, Fill, Stroke } from '../../../../../geoms/types'; | ||
import { AnnotationRectProps } from '../../../annotations/rect_annotation_tooltip'; | ||
import { RectAnnotationStyle } from '../../../../../utils/themes/theme'; | ||
import { stringToRGB } from '../../../../partition_chart/layout/utils/d3_utils'; | ||
import { withContext } from '../../../../../renderers/canvas'; | ||
|
||
export function renderRectAnnotations( | ||
ctx: CanvasRenderingContext2D, | ||
annotations: AnnotationRectProps[], | ||
rectStyle: RectAnnotationStyle, | ||
) { | ||
const rects = annotations.map<Rect>((annotation) => { | ||
return annotation.rect; | ||
}); | ||
const fillColor = stringToRGB(rectStyle.fill); | ||
fillColor.opacity = fillColor.opacity * rectStyle.opacity; | ||
const fill: Fill = { | ||
color: fillColor, | ||
}; | ||
const strokeColor = stringToRGB(rectStyle.stroke); | ||
strokeColor.opacity = strokeColor.opacity * rectStyle.opacity; | ||
const stroke: Stroke = { | ||
color: strokeColor, | ||
width: rectStyle.strokeWidth, | ||
}; | ||
|
||
const rectsLength = rects.length; | ||
|
||
for (let i = 0; i < rectsLength; i++) { | ||
const rect = rects[i]; | ||
withContext(ctx, (ctx) => { | ||
renderRect(ctx, rect, fill, stroke); | ||
}); | ||
} | ||
} |
Oops, something went wrong.