From 024785b417f01ee421117de8ba694c08082c0249 Mon Sep 17 00:00:00 2001 From: boygirl Date: Mon, 19 Jun 2017 16:04:24 -0700 Subject: [PATCH] add victory-legend, fix label spacing --- demo/demo.js | 57 ++++++++++++++++++++++++++++++++ lib/components/victory-label.js | 3 +- lib/components/victory-legend.js | 36 ++++++++++++++++++++ lib/index.js | 1 + 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 lib/components/victory-legend.js diff --git a/demo/demo.js b/demo/demo.js index 6045e2bf..d7b77f22 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -29,6 +29,7 @@ import { VictoryCursorContainer, VictoryPie, VictoryLabel, + VictoryLegend, createContainer } from "victory-native"; @@ -63,6 +64,51 @@ const candleData = [ { x: 8, open: 80, close: 81, high: 83, low: 75 } ]; +const legendData = [{ + name: "Series 1", + symbol: { + type: "circle", + fill: "green" + } +}, { + name: "Long Series Name", + symbol: { + type: "triangleUp", + fill: "blue" + } +}, { + name: "Series 3", + symbol: { + type: "diamond", + fill: "pink" + } +}, { + name: "Series 4", + symbol: { + type: "plus" + } +}, { + name: "Series 5", + symbol: { + type: "star", + fill: "red" + }, + labels: { + fill: "purple" + } +}, { + name: "Series 6", + symbol: { + type: "circle", + fill: "orange" + }, + labels: { + fill: "blue" + } +}]; + +const legendStyle = { parent: { marginBottom: 20 } }; + const VictoryZoomVoronoiContainer = createContainer("zoom", "voronoi"); export default class Demo extends Component { @@ -138,6 +184,17 @@ export default class Demo extends Component { {"Native"} {"Demo\n"} + + + {line} diff --git a/lib/components/victory-legend.js b/lib/components/victory-legend.js new file mode 100644 index 00000000..7d4b50d8 --- /dev/null +++ b/lib/components/victory-legend.js @@ -0,0 +1,36 @@ +import React from "react"; +import { G } from "react-native-svg"; +import { VictoryLegend } from "victory-core/src"; +import { Dimensions } from "react-native"; +import VictoryLabel from "./victory-label"; +import VictoryContainer from "./victory-container"; +import { Point, NativeHelpers } from "../index"; + +export default class extends VictoryLegend { + static defaultProps = { + ...VictoryLegend.defaultProps, + containerComponent: , + dataComponent: , + groupComponent: , + labelComponent: , + width: Dimensions.get("window").width + }; + + renderGroup(props, children) { + const { groupComponent, height, parentStyles, standalone, width, x, y } = props; + let groupProps = { role: "presentation" }; + const styles = NativeHelpers.getStyle(parentStyles); + + if (!standalone) { + groupProps = { + height, + width, + translateX: x, + translateY: y, + ...styles, + ...groupProps + }; + } + return React.cloneElement(groupComponent, groupProps, children); + } +} diff --git a/lib/index.js b/lib/index.js index dcd63e71..1e1dd075 100644 --- a/lib/index.js +++ b/lib/index.js @@ -42,6 +42,7 @@ export { voronoiContainerMixin } from "./components/victory-voronoi-container"; export { selectionContainerMixin } from "./components/victory-selection-container"; export { brushContainerMixin } from "./components/victory-brush-container"; export { default as VictoryLabel } from "./components/victory-label"; +export { default as VictoryLegend } from "./components/victory-legend"; export { default as NativeHelpers } from "./helpers/native-helpers"; export { default as NativeZoomHelpers } from "./helpers/native-zoom-helpers";