diff --git a/.changeset/few-rings-approve.md b/.changeset/few-rings-approve.md new file mode 100644 index 000000000..f39f6b245 --- /dev/null +++ b/.changeset/few-rings-approve.md @@ -0,0 +1,9 @@ +--- +"victory-core": minor +"victory-group": minor +"victory-legend": minor +"victory-pie": minor +"victory-stack": minor +--- + +Minor updates for clean theme diff --git a/.github/workflows/chromatic.yml b/.github/workflows/chromatic.yml index f7506f53c..45f7663e1 100644 --- a/.github/workflows/chromatic.yml +++ b/.github/workflows/chromatic.yml @@ -11,8 +11,8 @@ on: branches: - main paths: - - 'stories/**' - - 'packages/**' + - "stories/**" + - "packages/**" jobs: chromatic: diff --git a/demo/ts/components/animation-demo.tsx b/demo/ts/components/animation-demo.tsx index 0d84b7753..5cbd9ce73 100644 --- a/demo/ts/components/animation-demo.tsx +++ b/demo/ts/components/animation-demo.tsx @@ -89,7 +89,14 @@ export default class App extends React.Component { } getStyles() { - const colors = ["red", "orange", "gold", "tomato", "magenta", "purple"]; + const colors = VictoryTheme.clean.bar?.colorScale ?? [ + "red", + "orange", + "gold", + "tomato", + "magenta", + "purple", + ]; return { fill: colors[random(0, 5)], }; @@ -122,12 +129,7 @@ export default class App extends React.Component { - + {this.state.multiTransitionData.map((data, index) => { return ( @@ -135,8 +137,8 @@ export default class App extends React.Component { })} - - + + {this.state.multiTransitionData.map((data, index) => { return ( @@ -145,7 +147,7 @@ export default class App extends React.Component { - + { /> - + { }; const getStyles = () => { - const colors = ["red", "orange", "gold", "tomato", "magenta", "purple"]; + const colors = VictoryTheme.clean.palette?.qualitative ?? [ + "red", + "orange", + "gold", + "tomato", + "magenta", + "purple", + ]; return { - fill: colors[random(0, 5)], + fill: colors[random(0, colors.length - 1)], }; }; @@ -280,7 +287,11 @@ const CanvasDemo = () => { return (
- + {populationData.map(({ country, values }) => { const data = values.map(({ year, value }) => ({ x: year, @@ -298,14 +309,14 @@ const CanvasDemo = () => { v} /> - + } dataComponent={} data={getRandomData(1000)} /> - + } dataComponent={} diff --git a/demo/ts/components/events-demo.tsx b/demo/ts/components/events-demo.tsx index f4c04a792..0295b9069 100644 --- a/demo/ts/components/events-demo.tsx +++ b/demo/ts/components/events-demo.tsx @@ -5,7 +5,7 @@ import { VictoryStack } from "victory-stack"; import { VictoryArea } from "victory-area"; import { VictoryBar, VictoryBarTTargetType } from "victory-bar"; import { VictoryLine } from "victory-line"; -import { VictoryTheme, VictoryLabel } from "victory-core"; +import { VictoryTheme, VictoryLabel, VictoryThemePalette } from "victory-core"; class EventsDemo extends React.Component { render() { @@ -21,6 +21,8 @@ class EventsDemo extends React.Component { parent: { border: "1px solid #ccc", margin: "2%", maxWidth: "40%" }, }; const barTarget: VictoryBarTTargetType = "data"; + const themeColors: VictoryThemePalette = + VictoryTheme.clean.palette?.colors || {}; return (
@@ -29,8 +31,6 @@ class EventsDemo extends React.Component { theme={VictoryTheme.clean} style={{ parent: chartStyle.parent, - data: { fill: "blue", width: 20 }, - labels: { fontSize: 20 }, }} labels={["a", "b", "c", "d", "e"]} data={[ @@ -49,15 +49,17 @@ class EventsDemo extends React.Component { evt.stopPropagation(); return [ { - mutation: () => { - return { style: { fill: "orange", width: 20 } }; + mutation: (props) => { + return { + style: { ...props.style, fill: themeColors.teal }, + }; }, }, { target: "labels", eventKey: 3, - mutation: () => { - return { text: "now click me" }; + mutation: (props) => { + return { ...props.style, text: "now click me" }; }, }, ]; @@ -71,8 +73,13 @@ class EventsDemo extends React.Component { return [ { target: "data", - mutation: () => { - return { style: { fill: "tomato", width: 10 } }; + mutation: (props) => { + return { + style: { + ...props.style, + fill: themeColors.pink, + }, + }; }, }, ]; @@ -83,6 +90,7 @@ class EventsDemo extends React.Component { /> { return { - style: Object.assign({}, props.style, { stroke: "lime" }), + style: { ...props.style, stroke: themeColors.teal }, }; }, }, @@ -114,7 +122,7 @@ class EventsDemo extends React.Component { target: "labels", mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "green" }), + style: { ...props.style, fill: themeColors.purple }, text: "waddup", }; }, @@ -128,7 +136,6 @@ class EventsDemo extends React.Component { null} - style={{ data: { width: 15, fill: "green" } }} data={[ { x: 1, y: 1 }, { x: 2, y: 2 }, @@ -148,13 +155,14 @@ class EventsDemo extends React.Component { 0.5} - style={{ data: { stroke: "blue", strokeWidth: 5 } }} + style={{ data: { stroke: themeColors.purple } }} /> { - return { style: { fill: "orange" } }; + mutation: (props) => { + return { + style: { ...props.style, fill: themeColors.yellow }, + }; }, }, ]; @@ -190,13 +200,18 @@ class EventsDemo extends React.Component { }, ]} > - + null} /> { const fill = props.style && props.style.fill; - return fill === "gold" + return fill === themeColors.yellow ? null - : { style: { fill: "gold" } }; + : { + style: { + ...props.style, + fill: themeColors.yellow, + }, + }; }, }, ]; diff --git a/demo/ts/components/external-events-demo.tsx b/demo/ts/components/external-events-demo.tsx index b578d64c0..81ad3e14e 100644 --- a/demo/ts/components/external-events-demo.tsx +++ b/demo/ts/components/external-events-demo.tsx @@ -9,8 +9,10 @@ import { VictoryLine } from "victory-line"; import { VictoryZoomContainer } from "victory-zoom-container"; import { VictoryVoronoiContainer } from "victory-voronoi-container"; import { range } from "lodash"; -import { VictoryTheme } from "victory-core/lib"; +import { VictoryTheme, VictoryThemePalette } from "victory-core"; +const themeColors: VictoryThemePalette = + VictoryTheme.clean.palette?.colors || {}; class App extends React.Component { constructor(props) { super(props); @@ -53,9 +55,13 @@ class App extends React.Component { eventKey: "all", mutation: (props) => { const fill = props.style && props.style.fill; - return fill === "blue" - ? { style: Object.assign({}, props.style, { fill: "red" }) } - : { style: Object.assign({}, props.style, { fill: "blue" }) }; + return fill === themeColors.green + ? { + style: { ...props.style, fill: themeColors.red }, + } + : { + style: { ...props.style, fill: themeColors.green }, + }; }, callback, }, @@ -108,7 +114,7 @@ class App extends React.Component { { onClick: () => { return [ { - mutation: () => { - return { style: { fill: "orange" } }; + mutation: (props) => { + return { + style: { ...props.style, fill: themeColors.orange }, + }; }, }, { @@ -141,11 +149,11 @@ class App extends React.Component { name="data" labels={() => null} data={this.state.data} - // style={{ data: { fill: "cyan" } }} /> { onClick: () => { return [ { - mutation: () => { - return { style: { fill: "orange" } }; + mutation: (props) => { + return { + style: { ...props.style, fill: themeColors.orange }, + }; }, }, { @@ -176,6 +186,8 @@ class App extends React.Component { ]} /> { onClick: () => { return [ { - mutation: () => { - return { style: { fill: "orange" } }; + mutation: (props) => { + return { + style: { + ...props.style, + fill: + props.style.fill === themeColors.green + ? themeColors.teal + : themeColors.green, + }, + }; }, }, { @@ -239,13 +259,11 @@ class App extends React.Component { name="data" style={{ data: { - fill: "tomato", + fill: themeColors.yellow, stroke: ({ active }) => (active ? "black" : "none"), - strokeWidth: 2, }, }} - cornerRadius={{ top: 1, bottom: 1 }} - barWidth={({ active }) => (active ? 7 : 4)} + barWidth={({ active }) => (active ? 22 : 20)} data={[ { x: 1, y: -5 }, { x: 2, y: 4 }, @@ -259,13 +277,11 @@ class App extends React.Component { (active ? "black" : "none"), - strokeWidth: 2, }, }} - cornerRadius={{ top: 1, bottom: 1 }} - barWidth={({ active }) => (active ? 7 : 4)} + barWidth={({ active }) => (active ? 22 : 20)} data={[ { x: 1, y: -3 }, { x: 2, y: 5 }, @@ -278,13 +294,13 @@ class App extends React.Component { /> } externalEventMutations={this.state.externalMutation} > diff --git a/demo/ts/components/group-demo.tsx b/demo/ts/components/group-demo.tsx index 2299fb60f..bb7894f97 100644 --- a/demo/ts/components/group-demo.tsx +++ b/demo/ts/components/group-demo.tsx @@ -13,6 +13,7 @@ import { VictoryBoxPlot } from "victory-box-plot"; import { range, random } from "lodash"; import { VictoryTheme } from "victory-core/lib"; +const themeColors = VictoryTheme.clean.palette?.colors || {}; class App extends React.Component { getGroupData() { return range(5).map(() => { @@ -67,18 +68,14 @@ class App extends React.Component { style={{ data: { strokeDasharray: "10, 5" }, }} - colorScale="qualitative" > @@ -89,9 +86,7 @@ class App extends React.Component { { x: 2, y: 5 }, { x: 3, y: 1 }, ]} - style={{ - data: { width: 20, opacity: 0.8 }, - }} + colorScale="green" > @@ -102,26 +97,23 @@ class App extends React.Component { { x: 2, y: 2 }, { x: 3, y: 5 }, ]} - style={{ - data: { width: 10, opacity: 1 }, - }} + colorScale="blue" > - + - - - + + +
); diff --git a/demo/ts/components/horizontal-demo.tsx b/demo/ts/components/horizontal-demo.tsx index e4e30086f..c30112e76 100644 --- a/demo/ts/components/horizontal-demo.tsx +++ b/demo/ts/components/horizontal-demo.tsx @@ -14,7 +14,7 @@ import { VictoryBoxPlot } from "victory-box-plot"; import { VictoryAxis } from "victory-axis"; import { VictoryBrushContainer } from "victory-brush-container"; import { range, random } from "lodash"; -import { VictoryTheme } from "victory-core/lib"; +import { VictoryTheme } from "victory-core"; const errorData = [ { x: 1, y: 10, errorX: [1, 0.5], errorY: 1 }, @@ -24,6 +24,8 @@ const errorData = [ { x: 5, y: 10, errorX: [1, 0.5], errorY: 2 }, ]; +const themeColors = VictoryTheme.clean.palette?.colors || {}; + class App extends React.Component { getBarData() { return range(5).map(() => { @@ -49,9 +51,19 @@ class App extends React.Component { }; return (
- + - + - + "hi"} /> - - - + - + - - + + {this.getBarData().map((data, index) => { return ; @@ -153,7 +200,12 @@ class App extends React.Component { - + - + "yo"} data={[ @@ -257,12 +311,13 @@ class App extends React.Component { { x: new Date(2015, 1, 1), y: 470 }, ]} /> - + "yo"} data={[ { x: new Date(1982, 1, 1), y: 125 }, { x: new Date(1987, 1, 1), y: 257 }, @@ -276,8 +331,12 @@ class App extends React.Component { /> "yo"} data={[ { x: new Date(1982, 1, 1), y: 125 }, @@ -290,7 +349,7 @@ class App extends React.Component { { x: new Date(2015, 1, 1), y: 470 }, ]} /> - + - - - - - - - - + "yo"} data={[ @@ -428,25 +453,32 @@ class App extends React.Component { /> - + "yo"} /> - + Math.sin(2 * Math.PI * d.x)} samples={25} + style={{ + data: { + stroke: themeColors.green, + }, + }} /> - + "yo"} data={[ { x: new Date(1982, 1, 1), y: 125 }, @@ -464,8 +496,12 @@ class App extends React.Component { style={chartStyle} horizontal categories={{ y: ["E", "F", "G", "H"] }} + theme={VictoryTheme.clean} > - + } > - - - new Date(x).getFullYear()} - /> - -
); } diff --git a/demo/ts/components/immutable-demo.tsx b/demo/ts/components/immutable-demo.tsx index 82357a8e4..58b53b457 100644 --- a/demo/ts/components/immutable-demo.tsx +++ b/demo/ts/components/immutable-demo.tsx @@ -29,6 +29,13 @@ import { VictoryTheme, } from "victory-core"; +const themeColors = VictoryTheme.clean.palette?.colors || {}; +const scatterFillStyle: VictoryStyleInterface = { + data: { + fill: ({ active }) => + active ? themeColors.pink || "pink" : themeColors.blue || "blue", + }, +}; interface WrapperProps { children?: React.ReactElement | React.ReactElement[]; } @@ -211,7 +218,11 @@ export default class ImmutableDemo extends React.Component<

with immutable.js data

- + } data={this.state.scatterData} @@ -237,7 +248,7 @@ export default class ImmutableDemo extends React.Component< { return { - style: Object.assign({}, props.style, { fill: "gold" }), + style: Object.assign({}, props.style, { + fill: "gold", + }), }; }, }, @@ -259,7 +272,9 @@ export default class ImmutableDemo extends React.Component< target: "data", mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "orange" }), + style: Object.assign({}, props.style, { + fill: "orange", + }), }; }, }, @@ -268,7 +283,9 @@ export default class ImmutableDemo extends React.Component< target: "data", mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "red" }), + style: Object.assign({}, props.style, { + fill: "red", + }), }; }, }, @@ -325,7 +342,7 @@ export default class ImmutableDemo extends React.Component< - + { return { - style: Object.assign({}, props.style.labels, { - fill: "orange", - }), + style: { + ...props.style, + stroke: themeColors.orange, + }, }; }, }, @@ -469,7 +488,10 @@ export default class ImmutableDemo extends React.Component< { mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "blue" }), + style: { + ...props.style, + stroke: themeColors.blue, + }, }; }, }, @@ -483,6 +505,7 @@ export default class ImmutableDemo extends React.Component< { return { - style: Object.assign({}, props.style, { stroke: "lime" }), + style: { + ...props.style, + stroke: themeColors.yellow, + }, }; }, }, @@ -514,7 +540,10 @@ export default class ImmutableDemo extends React.Component< target: "labels", mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "green" }), + style: { + ...props.style, + stroke: themeColors.green, + }, text: "waddup", }; }, @@ -527,7 +556,6 @@ export default class ImmutableDemo extends React.Component< > - 0.5} - style={{ data: { stroke: "blue", strokeWidth: 5 } }} - /> + 0.5} /> - + @@ -578,30 +603,25 @@ export default class ImmutableDemo extends React.Component< { x: 2, y: 5 }, { x: 3, y: 1 }, ])} - style={{ - data: { width: 20, opacity: 0.8 }, - }} + colorScale="blue" > @@ -639,6 +659,7 @@ export default class ImmutableDemo extends React.Component< /> } labels={({ datum }) => `hello #${datum.x}`} @@ -653,10 +674,8 @@ export default class ImmutableDemo extends React.Component< } - theme={VictoryTheme.material} + theme={VictoryTheme.clean} events={[ { childName: "area-1", @@ -668,7 +687,10 @@ export default class ImmutableDemo extends React.Component< target: "data", mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "gold" }), + style: { + ...props.style, + fill: themeColors.yellow, + }, }; }, }, @@ -677,7 +699,10 @@ export default class ImmutableDemo extends React.Component< target: "data", mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "orange" }), + style: { + ...props.style, + fill: themeColors.orange, + }, }; }, }, @@ -686,7 +711,10 @@ export default class ImmutableDemo extends React.Component< target: "data", mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "red" }), + style: { + ...props.style, + fill: themeColors.red, + }, }; }, }, @@ -695,20 +723,6 @@ export default class ImmutableDemo extends React.Component< }, ]} > - (active ? 4 : 2), + stroke: themeColors.red, + strokeWidth: ({ active }) => (active ? 2 : 1), }, - labels: { fill: "tomato" }, + labels: { fill: themeColors.red }, }} /> (active ? 4 : 2), + stroke: themeColors.blue, + strokeWidth: ({ active }) => (active ? 2 : 1), }, - labels: { fill: "blue" }, + labels: { fill: themeColors.blue }, }} /> (active ? 4 : 2), + stroke: themeColors.green, + strokeWidth: ({ active }) => (active ? 2 : 1), }, - labels: { fill: "black" }, + labels: { fill: themeColors.green }, }} /> @@ -831,20 +843,6 @@ export default class ImmutableDemo extends React.Component< /> } > - ({ x, y: x + 10 * Math.random() })), @@ -854,6 +852,7 @@ export default class ImmutableDemo extends React.Component<
new Date(x).getFullYear()} />
- + {this.state.multiTransitionAreaData.map((data, index) => { return ( @@ -949,6 +939,7 @@ export default class ImmutableDemo extends React.Component< } > @@ -959,11 +950,9 @@ export default class ImmutableDemo extends React.Component< { x: 3, y: -2 }, ])} > - + (active ? "tomato" : "gray") }, - }} + style={scatterFillStyle} labels={({ datum }) => datum.y} labelComponent={} /> @@ -975,11 +964,9 @@ export default class ImmutableDemo extends React.Component< { x: 3, y: 3 }, ])} > - + (active ? "blue" : "gray") }, - }} + style={scatterFillStyle} labels={({ datum }) => datum.y} labelComponent={} /> @@ -991,11 +978,9 @@ export default class ImmutableDemo extends React.Component< { x: 3, y: -2 }, ])} > - + (active ? "black" : "gray") }, - }} + style={scatterFillStyle} labels={({ datum }) => datum.y} labelComponent={} /> @@ -1013,9 +998,6 @@ export default class ImmutableDemo extends React.Component< } diff --git a/demo/ts/components/victory-area-demo.tsx b/demo/ts/components/victory-area-demo.tsx index f2700f47d..1c79dc1d8 100644 --- a/demo/ts/components/victory-area-demo.tsx +++ b/demo/ts/components/victory-area-demo.tsx @@ -133,311 +133,215 @@ export default class VictoryAreaDemo extends React.Component< justifyContent: "center", }; + const dataStyle = { strokeWidth: 2, fillOpacity: 0.4 }; + return (
- + + + + + Math.round(datum.y)} + style={{ + data: { + fill: VictoryTheme.clean.palette?.colors?.purple, + }, + }} data={[ - { x: 1, y: 0.2 }, - { x: 2, y: 3 }, - { x: 3, y: 50 }, - { x: 4, y: 400 }, - { x: 5, y: 70 }, + { x: new Date(1982, 1, 1), y: 125 }, + { x: new Date(1987, 1, 1), y: 257 }, + { x: new Date(1993, 1, 1), y: 345 }, + { x: new Date(1997, 1, 1), y: 515 }, + { x: new Date(2001, 1, 1), y: 132 }, + { x: new Date(2005, 1, 1), y: 305 }, + { x: new Date(2011, 1, 1), y: 270 }, + { x: new Date(2015, 1, 1), y: 470 }, ]} /> - + datum.y} /> - + - } + data={this.state.data} + style={{ + data: { + fill: VictoryTheme.clean.palette?.colors?.pink, + }, + }} /> - - - - } - > - {this.state.multiTransitionData.map((data, index) => { - return ( - - ); - })} - + - + + + + + + + + - + + + + + + - + Math.sin(d)} /> - - - - + - + - datum.y} /> - - - - {this.state.groupedData.map((data, index) => ( - - ))} - - - Math.sin(d)} - /> - - { - return [ - { - target: "data", - mutation: (props) => { - return { - style: Object.assign({}, props.style, { fill: "orange" }), - }; - }, - }, - { - target: "labels", - eventKey: 0, - mutation: () => { - return { text: "hey" }; - }, - }, - ]; - }, - }, - }, - ]} - labels={() => null} - data={this.state.arrayData} - x={0} - y={1} - /> - - - - + - - Math.sin(data.x)} - standalone={false} - style={{ data: { opacity: 0.4 } }} - /> - Math.cos(data.x)} - standalone={false} - style={{ data: { opacity: 0.4 } }} - /> - + + + Math.sin(data.x)} + standalone={false} + style={{ data: { opacity: 0.4 } }} + /> + Math.cos(data.x)} + standalone={false} + style={{ data: { opacity: 0.4 } }} + /> + + - - + + } - /> - - - - } - > - {this.state.multiTransitionData.map((data, index) => { - return ( - - ); - })} - - - - - - - - - - - + > + {this.state.multiTransitionData.map((data, index) => { + return ( + + ); + })} +
); diff --git a/demo/ts/components/victory-axis-demo.tsx b/demo/ts/components/victory-axis-demo.tsx index b2b9c686a..36cbe2684 100644 --- a/demo/ts/components/victory-axis-demo.tsx +++ b/demo/ts/components/victory-axis-demo.tsx @@ -3,7 +3,6 @@ import { random, range } from "lodash"; import { DomainPropType } from "victory-core"; import { VictoryAxis, VictoryAxisProps } from "victory-axis"; import { VictoryLabel, VictoryContainer, VictoryTheme } from "victory-core"; -import XYTheme from "../theme/victory-axis-differential-styling-theme"; interface VictoryAxisDemoState { tickValues: number[]; @@ -54,22 +53,15 @@ export default class VictoryAxisDemo extends React.Component< parent: { border: "1px solid #ccc", margin: "2%", maxWidth: "40%" }, }; + const blue = VictoryTheme.clean.palette?.colors?.blue || "blue"; + const styleOverrides: VictoryAxisProps["style"] = { parent: { border: "1px solid #ccc", margin: "2%", maxWidth: "40%" }, - axis: { - stroke: "black", - }, - axisLabel: { - padding: 60, - fontWeight: "bold", - fontSize: 16, - }, grid: { - strokeWidth: 2, - stroke: ({ tick }: any) => (tick === "Mariners\nSEA" ? "red" : "grey"), + stroke: ({ tick }: any) => (tick === "Mariners\nSEA" ? blue : "grey"), }, ticks: { - stroke: ({ tick }: any) => (tick === "Mariners\nSEA" ? "red" : "grey"), + stroke: ({ tick }: any) => (tick === "Mariners\nSEA" ? blue : "grey"), }, tickLabels: { fontWeight: ({ tick }: any) => @@ -91,13 +83,10 @@ export default class VictoryAxisDemo extends React.Component< } tickValues={this.state.tickValues} - theme={VictoryTheme.material} + theme={VictoryTheme.clean} tickFormat={["first", "second", "third", "fourth", "fifth"]} animate={{ duration: 2000 }} containerComponent={ @@ -107,15 +96,13 @@ export default class VictoryAxisDemo extends React.Component< /> } /> - @@ -157,14 +144,13 @@ export default class VictoryAxisDemo extends React.Component< ]} tickFormat={(x) => x.getFullYear()} /> - @@ -174,7 +160,7 @@ export default class VictoryAxisDemo extends React.Component< width={500} height={400} domain={this.state.domain} - theme={VictoryTheme.material} + theme={VictoryTheme.clean} offsetX={250} standalone={false} /> @@ -182,20 +168,27 @@ export default class VictoryAxisDemo extends React.Component< - - - - + datum.y} data={[ @@ -199,6 +209,10 @@ export default class VictoryBarDemo extends React.Component< datum.y} data={[ @@ -212,6 +226,10 @@ export default class VictoryBarDemo extends React.Component< datum.y} data={[ { x: 1, y: 20 }, @@ -222,7 +240,24 @@ export default class VictoryBarDemo extends React.Component< /> - + + + + + "HELLO"} labelComponent={ @@ -280,7 +323,9 @@ export default class VictoryBarDemo extends React.Component< { mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "orange" }), + style: Object.assign({}, props.style, { + fill: "orange", + }), }; }, }, @@ -302,6 +347,8 @@ export default class VictoryBarDemo extends React.Component< {this.state.multiTransitionData.map((data, index) => { return ( @@ -333,6 +380,7 @@ export default class VictoryBarDemo extends React.Component< @@ -391,16 +442,11 @@ export default class VictoryBarDemo extends React.Component< })}
- - - - - + { return { - style: Object.assign({}, props.style, { fill: "orange" }), + style: Object.assign({}, props.style, { + fill: "orange", + }), }; }, }, @@ -443,7 +491,9 @@ export default class VictoryBarDemo extends React.Component< { mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "blue" }), + style: Object.assign({}, props.style, { + fill: "blue", + }), }; }, }, @@ -455,10 +505,12 @@ export default class VictoryBarDemo extends React.Component< /> - + - + { static defaultProps = { height: 250, width: 350, + theme: VictoryTheme.clean, }; // renders both a standalone chart, and a version wrapped in VictoryChart, // to test both cases at once @@ -557,7 +624,9 @@ class ChartWrap extends React.Component { return (
{React.cloneElement(this.props.children)} - {this.props.children} + + {this.props.children} +
); } diff --git a/demo/ts/components/victory-box-plot-demo.tsx b/demo/ts/components/victory-box-plot-demo.tsx index d6b5ee22e..0ec7fef8e 100644 --- a/demo/ts/components/victory-box-plot-demo.tsx +++ b/demo/ts/components/victory-box-plot-demo.tsx @@ -78,9 +78,10 @@ export default class VictoryBoxPlotDemo extends React.Component< ]} />
- - + @@ -146,18 +144,18 @@ export default class VictoryBoxPlotDemo extends React.Component< }, ]} style={{ - min: { stroke: "black", strokeWidth: 2 }, - max: { stroke: "black", strokeWidth: 2 }, - q1: { fill: "#FF530D", fillOpacity: 0.5 }, - q3: { fill: "#2bbee0", fillOpacity: 0.5 }, - median: { stroke: "#fff", strokeWidth: 2 }, - minLabels: { fill: "green", padding: 10 }, - maxLabels: { fill: "orange", padding: 10 }, + q1: { fill: VictoryTheme.clean.palette?.colors?.yellow }, + q3: { fill: VictoryTheme.clean.palette?.colors?.pink }, }} /> - + - + - + - + - - + + { - setStateInterval?: number = undefined; - - constructor(props: any) { - super(props); - this.state = { - data: props.data, - }; - } - - componentDidMount() { - /* eslint-disable react/no-did-mount-set-state */ - this.setStateInterval = window.setInterval(() => { - this.setState({ - data: getData(), - }); - }, 2000); - } - - componentWillUnmount() { - window.clearInterval(this.setStateInterval); - } - render() { return (
- - `x: ${datum.x.getDate()}`} - labelOrientation={{ low: "bottom", high: "top" }} - openLabels={({ datum }) => datum.open} - closeLabels={({ datum }) => datum.close} - lowLabels={({ datum }) => datum.low} - highLabels={({ datum }) => datum.high} - data={data} - size={8} - standalone={false} - events={[ - { - target: "highLabels", - eventHandlers: { - onClick: () => { - return [ - { - mutation: (props) => { - return { - style: Object.assign({}, props.style.labels, { - fill: "orange", - }), - }; - }, + `x: ${datum.x.getDate()}`} + labelOrientation={{ low: "bottom", high: "top" }} + openLabels={({ datum }) => datum.open} + closeLabels={({ datum }) => datum.close} + lowLabels={({ datum }) => datum.low} + highLabels={({ datum }) => datum.high} + data={data} + size={8} + events={[ + { + target: "highLabels", + eventHandlers: { + onClick: () => { + return [ + { + mutation: (props) => { + return { + style: Object.assign({}, props.style.labels, { + fill: "orange", + }), + }; }, - ]; - }, + }, + ]; }, }, - { - target: "data", - eventHandlers: { - onClick: () => { - return [ - { - mutation: (props) => { - return { - style: Object.assign({}, props.style, { - fill: "blue", - }), - }; - }, + }, + { + target: "data", + eventHandlers: { + onClick: () => { + return [ + { + mutation: (props) => { + return { + style: Object.assign({}, props.style, { + fill: "blue", + }), + }; }, - ]; - }, + }, + ]; }, }, - ]} - /> - + }, + ]} + /> - datum.fill, - opacity: ({ datum }) => datum.opacity, - }, - parent: style.parent, - }} - /> - - - - - - +
); } diff --git a/demo/ts/components/victory-chart-demo.tsx b/demo/ts/components/victory-chart-demo.tsx index 17299feab..b415a39c6 100644 --- a/demo/ts/components/victory-chart-demo.tsx +++ b/demo/ts/components/victory-chart-demo.tsx @@ -13,6 +13,7 @@ import { VictoryTheme, VictoryClipContainer, VictoryThemeDefinition, + VictoryThemePalette, } from "victory-core"; const UPDATE_INTERVAL = 3000; @@ -201,10 +202,16 @@ class VictoryChartDemo extends React.Component { } getStyles(): React.CSSProperties { - const colors = ["red", "orange", "cyan", "green", "blue", "purple"]; + const colors = VictoryTheme.clean.palette?.qualitative || [ + "red", + "orange", + "cyan", + "green", + "blue", + "purple", + ]; return { - stroke: colors[random(0, 5)], - strokeWidth: random(1, 3), + stroke: colors[random(0, colors.length - 1)], }; } @@ -221,16 +228,8 @@ class VictoryChartDemo extends React.Component { parent: { border: "1px solid #ccc", margin: "2%", maxWidth: "40%" }, }; - const axisStyle: { [key: string]: React.CSSProperties } = { - grid: { stroke: "grey", strokeWidth: 1 }, - axis: { stroke: "transparent" }, - ticks: { stroke: "transparent" }, - tickLabels: { fill: "none" }, - }; - - const bgStyle: { [key: string]: React.CSSProperties } = { - background: { fill: "#e6e6ff" }, - }; + const themeColors: VictoryThemePalette = + VictoryTheme.clean.palette?.colors || {}; return (
@@ -247,10 +246,12 @@ class VictoryChartDemo extends React.Component { { /> - - + + - - + + { /> - + `${t}s ${i} ${ts[0]}`} /> } - style={{ data: { fill: "tomato" } }} data={[ { x: "one", y: 1 }, { x: "two", y: 2 }, @@ -298,12 +299,12 @@ class VictoryChartDemo extends React.Component { /> - + { - - + + { - - + + { /> - + { - + - + - + {this.state.multiBarTransitionData.map((data, index) => { return ; @@ -426,21 +447,22 @@ class VictoryChartDemo extends React.Component { - + - + - + { - - - - + Math.sin(2 * Math.PI * data.x)} /> Math.cos(2 * Math.PI * data.x)} /> - - + + { scale={{ x: "time", }} + theme={VictoryTheme.clean} > { tickFormat={(x) => new Date(x).getFullYear()} /> { /> - + } data={this.state.scatterData} @@ -574,23 +591,18 @@ class VictoryChartDemo extends React.Component { /> - + - 0.5 * d.x + 0.5} - style={{ data: { stroke: "red" } }} - /> - d.x * d.x} - style={{ data: { stroke: "red" } }} - /> + 0.5 * d.x + 0.5} /> + d.x * d.x} /> @@ -605,6 +617,7 @@ class VictoryChartDemo extends React.Component { { eventKey: "all", mutation: (props) => { return { - style: Object.assign({}, props.style, { stroke: "lime" }), + style: Object.assign({}, props.style, { + stroke: "lime", + }), }; }, }, @@ -635,7 +650,9 @@ class VictoryChartDemo extends React.Component { eventKey: "all", mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "green" }), + style: Object.assign({}, props.style, { + fill: "green", + }), text: "waddup", }; }, @@ -648,7 +665,7 @@ class VictoryChartDemo extends React.Component { > null} data={[ { x: 1, y: 1 }, @@ -669,13 +686,14 @@ class VictoryChartDemo extends React.Component { 0.5} - style={{ data: { stroke: "blue", strokeWidth: 5 } }} + style={{ data: { stroke: themeColors.purple, strokeWidth: 2 } }} /> @@ -697,7 +715,7 @@ class VictoryChartDemo extends React.Component { { target: "data", mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "gold" }), + style: Object.assign({}, props.style, { + fill: "gold", + }), }; }, }, @@ -720,7 +740,9 @@ class VictoryChartDemo extends React.Component { target: "data", mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "orange" }), + style: Object.assign({}, props.style, { + fill: "orange", + }), }; }, }, @@ -729,7 +751,9 @@ class VictoryChartDemo extends React.Component { target: "data", mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "red" }), + style: Object.assign({}, props.style, { + fill: "red", + }), }; }, }, diff --git a/demo/ts/components/victory-demo.tsx b/demo/ts/components/victory-demo.tsx index 2e855cec3..8aa090694 100644 --- a/demo/ts/components/victory-demo.tsx +++ b/demo/ts/components/victory-demo.tsx @@ -36,80 +36,13 @@ export default class App extends React.Component { data.x * data.x} /> +

VictoryChart

+

Custom axes and tickformats; Bar + line chart

{ - return [ - { - target: "labels", - mutation: () => { - return { text: "o shit" }; - }, - }, - { - childName: "line", - eventKey: "all", - target: "data", - mutation: () => { - return { style: { stroke: "lime" } }; - }, - }, - { - childName: "line", - eventKey: 0, - target: "labels", - mutation: () => { - return { - style: { fill: "green" }, - text: "waddup", - }; - }, - }, - ]; - }, - }, - }, - ]} > - - 0.5} - style={{ data: { stroke: "blue", strokeWidth: 5 } }} - labels={["LINE"]} - /> - - -

VictoryChart

-

Custom axes and tickformats; Bar + line chart

- `${x}\ntick`} @@ -130,7 +63,11 @@ export default class App extends React.Component { }} /> { } getStyles() { - const colors = [ + const colors = VictoryTheme.clean.palette?.qualitative ?? [ "palevioletred", "orange", "cyan", @@ -207,8 +206,7 @@ export default class App extends React.Component<{}, VictoryBarDemoState> { "purple", ]; return { - stroke: colors[random(0, 5)], - strokeWidth: random(1, 5), + fill: colors[random(0, colors.length - 1)], }; } @@ -229,6 +227,7 @@ export default class App extends React.Component<{}, VictoryBarDemoState> { return (
{ { mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "pink" }), - }; - }, - }, - ], - onMouseOut: () => [ - { - mutation: (props) => { - return { - style: Object.assign({}, props.style, { fill: "yellow" }), + style: { + ...props.style, + fill: VictoryTheme.clean.palette?.colors?.orange, + }, }; }, }, ], + onMouseOut: () => ({ + mutation: () => null, + }), }, }, ]} - binSpacing={0} /> { horizontal style={{ parent: parentStyle, - // data: { stroke: "#1f4068", strokeWidth: 4, fill: "#e43f5a" }, + data: { + fill: VictoryTheme.clean.palette?.colors?.purple, + }, }} data={this.data.map(({ x }) => ({ value: x }))} x="value" /> - - { /> - - { { mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "pink" }), + style: Object.assign({}, props.style, { + fill: VictoryTheme.clean.palette?.colors?.purple, + }), }; }, }, @@ -370,20 +361,22 @@ export default class App extends React.Component<{}, VictoryBarDemoState> { /> `${datum.x0} - ${datum.x1}`} /> `${datum.x0} - ${datum.x1}`} @@ -391,10 +384,11 @@ export default class App extends React.Component<{}, VictoryBarDemoState> { /> @@ -404,6 +398,7 @@ export default class App extends React.Component<{}, VictoryBarDemoState> { /> { { { > { - - + + { /> - + @@ -519,17 +517,20 @@ export default class App extends React.Component<{}, VictoryBarDemoState> { { @@ -555,22 +557,27 @@ export default class App extends React.Component<{}, VictoryBarDemoState> { { { { /> - + { /> - + { /> - + { return ( Math.sin(2 * Math.PI * d.x)} samples={25} + theme={VictoryTheme.clean} /> { return { - style: Object.assign({}, props.style, { stroke: "orange" }), + style: Object.assign({}, props.style, { + stroke: "orange", + }), }; }, }, @@ -193,13 +202,18 @@ export default class VictoryLineDemo extends React.Component< /> Math.round(d.y)} data={[ @@ -215,7 +229,11 @@ export default class VictoryLineDemo extends React.Component< /> @@ -238,21 +257,22 @@ export default class VictoryLineDemo extends React.Component< - - ({ t }))} - sortKey={"t"} - x={({ t }) => Math.sin(3 * t + 2 * Math.PI)} - y={({ t }) => Math.sin(2 * t)} - />
); } diff --git a/demo/ts/components/victory-pie-demo.tsx b/demo/ts/components/victory-pie-demo.tsx index 43813a634..0a4941fb9 100644 --- a/demo/ts/components/victory-pie-demo.tsx +++ b/demo/ts/components/victory-pie-demo.tsx @@ -2,7 +2,7 @@ import React from "react"; import { random, range } from "lodash"; import { VictoryPie } from "victory-pie"; import { VictoryTooltip } from "victory-tooltip"; -import { VictoryTheme, LineSegment } from "victory-core"; +import { VictoryTheme, LineSegment, Helpers } from "victory-core"; interface VictoryPieDemoState { data: { @@ -21,6 +21,7 @@ interface VictoryPieDemoState { style: { [key: string]: React.CSSProperties; }; + padding: number; } export default class VictoryPieDemo extends React.Component< @@ -52,6 +53,7 @@ export default class VictoryPieDemo extends React.Component< maxWidth: "40%", }, }, + padding: 0, }; } @@ -103,7 +105,6 @@ export default class VictoryPieDemo extends React.Component< }; const parentStyle: React.CSSProperties = { - backgroundColor: "#f7f7f7", border: "1px solid #ccc", margin: "2%", maxWidth: "40%", @@ -120,81 +121,68 @@ export default class VictoryPieDemo extends React.Component< theme={VictoryTheme.clean} style={{ parent: parentStyle, - data: { stroke: "#f7f7f7" }, // stroke to "disappear" into background - labels: { fill: "white", fontSize: 10 }, }} - labelRadius={60} - padding={{ bottom: 50, left: 50, right: 10 }} - width={400} - height={200} /> datum.radius - 12} - padding={{ bottom: 50, left: 50, right: 10 }} + labelRadius={({ datum }) => datum.radius - 20} width={400} height={200} radius={({ datum }) => datum.radius} data={[ - { x: 1, y: 1, radius: 40 }, - { x: 2, y: 3, radius: 50 }, - { x: 3, y: 5, radius: 70 }, - { x: 4, y: 2, radius: 80 }, - { x: 5, y: 3, radius: 60 }, + { x: 1, y: 1, radius: 50 }, + { x: 2, y: 3, radius: 60 }, + { x: 3, y: 5, radius: 80 }, + { x: 4, y: 2, radius: 90 }, + { x: 5, y: 3, radius: 70 }, ]} /> - - ({ mutation: (props) => ({ - radius: 135, - sliceStartAngle: props.slice.startAngle + 0.05, - sliceEndAngle: props.slice.endAngle - 0.05, + radius: 110, + sliceStartAngle: Helpers.radiansToDegrees( + props.slice.startAngle + 0.05, + ), + sliceEndAngle: Helpers.radiansToDegrees( + props.slice.endAngle - 0.05, + ), }), }), onMouseOut: () => ({ @@ -207,7 +195,7 @@ export default class VictoryPieDemo extends React.Component< } + theme={VictoryTheme.clean} + colorScale="grayscale" style={{ parent: parentStyle, - labels: { fontSize: 10, padding: 10 }, }} - labelComponent={} - colorScale="grayscale" - /> - - - - [i, Math.random()])} x={0} y={1} animate={{ duration: 2000 }} style={{ ...this.state.style, - data: { stroke: "#252525", strokeWidth: 2 }, }} colorScale="warm" /> [i, Math.random()])} x={0} y={1} - theme={VictoryTheme.material} - style={{ parent: { maxWidth: "40%" } }} + style={{ parent: parentStyle }} animate={{ duration: 2000 }} /> [i, Math.random()])} x={0} y={1} - colorScale={["tomato", "orange"]} labels={[]} cornerRadius={20} startAngle={-6} @@ -310,8 +305,9 @@ export default class VictoryPieDemo extends React.Component< innerRadius={140} /> `${datum.l}\ndegrees`} @@ -327,7 +323,8 @@ export default class VictoryPieDemo extends React.Component< ]} /> - - } + labelIndicator + colorScale="heatmap" /> - } + labelIndicator labelIndicatorInnerOffset={45} - labelIndicatorOuterOffset={15} + labelIndicatorOuterOffset={10} + colorScale="red" />
diff --git a/demo/ts/components/victory-polar-axis-demo.tsx b/demo/ts/components/victory-polar-axis-demo.tsx index 4c7792acd..4380ac09f 100644 --- a/demo/ts/components/victory-polar-axis-demo.tsx +++ b/demo/ts/components/victory-polar-axis-demo.tsx @@ -13,7 +13,7 @@ import { VictoryGroup } from "victory-group"; import { VictoryTooltip } from "victory-tooltip"; import { VictoryStack } from "victory-stack"; import { random, range, keys } from "lodash"; -import { VictoryTheme, VictoryLabel } from "victory-core"; +import { VictoryTheme, VictoryLabel, VictoryThemePalette } from "victory-core"; type multiAxisDataListType = { strength?: number; @@ -121,6 +121,9 @@ class App extends React.Component { justifyContent: "center", }; + const themeColors: VictoryThemePalette = + VictoryTheme.clean.palette?.colors || {}; + const chartStyle: { [key: string]: React.CSSProperties } = { parent: { border: "1px solid #ccc", margin: "2%", maxWidth: "40%" }, }; @@ -130,7 +133,7 @@ class App extends React.Component {
@@ -139,9 +142,6 @@ class App extends React.Component { } @@ -164,13 +164,12 @@ class App extends React.Component { } > { { x: 5, y: 4 }, ]} > - + (active ? "tomato" : "gray") }, - }} labels={({ datum }) => datum.y} labelComponent={} /> { { x: 5, y: 1 }, ]} > - + (active ? "blue" : "gray") }, - }} labels={({ datum }) => `y: ${datum.y}`} labelComponent={} /> { { x: 5, y: 2 }, ]} > - + (active ? "black" : "gray") }, - }} labels={({ datum }) => datum.y} labelComponent={} /> - + - { } > @@ -281,10 +269,10 @@ class App extends React.Component { (active ? "blue" : "tomato"), - fillOpacity: 0.6, - stroke: ({ active }) => (active ? "blue" : "tomato"), - strokeWidth: 2, + fill: ({ active }) => + active + ? themeColors.blue || "blue" + : themeColors.red || "red", }, }} labelComponent={} @@ -298,7 +286,7 @@ class App extends React.Component { /> - + { { { mutation: () => { return { style: Object.assign({}, props.style, { - fill: "cyan", + fill: themeColors.cyan, }), }; }, @@ -355,7 +339,7 @@ class App extends React.Component { mutation: () => { return { style: Object.assign({}, props.style, { - fill: "blue", + fill: themeColors.blue, }), }; }, @@ -389,7 +373,9 @@ class App extends React.Component { { /> { /> { { mutation: () => { return { style: Object.assign({}, props.style, { - fill: "cyan", - stroke: "cyan", + fill: themeColors.cyan, }), }; }, @@ -480,10 +470,7 @@ class App extends React.Component { interpolation="cardinal" style={{ data: { - fill: "tomato", - stroke: "tomato", - fillOpacity: 0.5, - strokeWidth: 2, + fill: themeColors.red, }, }} data={[ @@ -500,10 +487,7 @@ class App extends React.Component { interpolation="cardinal" style={{ data: { - fill: "orange", - stroke: "orange", - fillOpacity: 0.5, - strokeWidth: 2, + fill: themeColors.orange, }, }} data={[ @@ -520,10 +504,7 @@ class App extends React.Component { interpolation="cardinal" style={{ data: { - fill: "gold", - stroke: "gold", - fillOpacity: 0.5, - strokeWidth: 2, + fill: themeColors.yellow, }, }} data={[ @@ -541,38 +522,30 @@ class App extends React.Component { ""} /> - + } > ""} /> @@ -580,9 +553,6 @@ class App extends React.Component { labelComponent={} labels={({ datum }: any) => `y: ${Math.round(datum.y)}`} interpolation="linear" - style={{ - data: { stroke: "tomato", strokeWidth: 2 }, - }} data={this.state.data} /> @@ -590,7 +560,7 @@ class App extends React.Component { { { { { } @@ -661,12 +624,14 @@ class App extends React.Component { datum.fill, opacity: 0.5 }, + data: { + fill: ({ datum }) => themeColors[datum.fill], + }, }} data={[ { x: 45, y: 20, label: 1, fill: "red" }, { x: 90, y: 30, label: 2, fill: "orange" }, - { x: 135, y: 65, label: 3, fill: "gold" }, + { x: 135, y: 65, label: 3, fill: "yellow" }, { x: 250, y: 50, label: 4, fill: "blue" }, { x: 270, y: 40, label: 5, fill: "cyan" }, { x: 295, y: 30, label: 6, fill: "green" }, @@ -685,16 +650,22 @@ class App extends React.Component { /> - + + + datum.fill, opacity: 0.5 }, + data: { fill: ({ datum }) => themeColors[datum.fill] }, }} data={[ { x: 15, y: 20, label: 1, fill: "red" }, { x: 25, y: 30, label: 2, fill: "orange" }, - { x: 35, y: 65, label: 3, fill: "gold" }, + { x: 35, y: 65, label: 3, fill: "yellow" }, { x: 40, y: 50, label: 4, fill: "blue" }, { x: 45, y: 40, label: 5, fill: "cyan" }, { x: 50, y: 30, label: 6, fill: "green" }, @@ -713,13 +684,21 @@ class App extends React.Component { /> - + + + datum.fill, width: 10 } }} + style={{ data: { fill: ({ datum }) => themeColors[datum.fill] } }} data={[ { x: 1, y: 2, label: 1, fill: "red" }, { x: 2, y: 3, label: 2, fill: "orange" }, - { x: 3, y: 6, label: 3, fill: "gold" }, + { x: 3, y: 6, label: 3, fill: "yellow" }, { x: 4, y: 5, label: 4, fill: "blue" }, { x: 5, y: 4, label: 5, fill: "cyan" }, { x: 6, y: 3, label: 6, fill: "green" }, @@ -738,7 +717,7 @@ class App extends React.Component { /> - + { labelPlacement="parallel" tickValues={[0, 45, 90, 135, 180, 225, 315]} /> - { { x: 270, y: 40 }, ]} /> - { { x: 270, y: 40 }, ]} /> + - + { "charisma", ]} /> - { { x: 5, y: 50 }, ]} /> - { { { { { { dependentAxis standalone={false} axisAngle={200} - theme={VictoryTheme.material} + theme={VictoryTheme.clean} style={chartStyle} tickValues={[2, 4, 6, 8, 10]} /> diff --git a/demo/ts/components/victory-scatter-demo.tsx b/demo/ts/components/victory-scatter-demo.tsx index afdcd22d5..8a9f03ac8 100644 --- a/demo/ts/components/victory-scatter-demo.tsx +++ b/demo/ts/components/victory-scatter-demo.tsx @@ -40,7 +40,7 @@ interface CatPointInterface { } const getData = () => { - const colors = [ + const colors = VictoryTheme.clean.palette?.qualitative ?? [ "violet", "cornflowerblue", "gold", @@ -58,7 +58,6 @@ const getData = () => { "diamond", "plus", ]; - // symbol: symbols[scaledIndex], return range(100).map((index) => { const scaledIndex = Math.floor(index % 7); return { @@ -206,9 +205,8 @@ export default class VictoryScatterDemo extends React.Component< return (
} /> datum.opacity, }, }} - width={500} - height={500} domain={[0, 600]} animate={{ duration: 2000 }} data={this.state.data} /> (datum.y > 0 ? "red" : "blue") }, + data: { + fill: ({ datum }) => + datum.y > 0 + ? VictoryTheme.clean.palette?.colors?.red ?? "red" + : VictoryTheme.clean.palette?.colors?.blue ?? "blue", + }, }} - width={500} - height={500} symbol={({ datum }) => (datum.y > 0 ? "triangleUp" : "triangleDown")} y={(d) => Math.sin(2 * Math.PI * d.x)} samples={25} /> } + theme={VictoryTheme.clean} + style={{ + parent: style.parent, + }} + labelComponent={} data={symbolData} /> - - + + ""} data={[ @@ -296,7 +307,9 @@ export default class VictoryScatterDemo extends React.Component< { mutation: (props) => { return { - style: Object.assign({}, props.style, { fill: "orange" }), + style: Object.assign({}, props.style, { + fill: "orange", + }), symbol: "circle", }; }, @@ -319,8 +332,6 @@ export default class VictoryScatterDemo extends React.Component< { return { a: { b: [{ y: i * Math.sin(i * 0.3) }], x: Math.cos(i * 0.3) }, diff --git a/demo/ts/components/victory-stack-demo.tsx b/demo/ts/components/victory-stack-demo.tsx index 8935912c9..f12689f5c 100644 --- a/demo/ts/components/victory-stack-demo.tsx +++ b/demo/ts/components/victory-stack-demo.tsx @@ -1,7 +1,7 @@ import React from "react"; import { VictoryStack } from "victory-stack"; import { VictoryArea } from "victory-area"; -import { VictoryTheme } from "victory-core/lib"; +import { VictoryTheme } from "victory-core"; class App extends React.Component { render() { @@ -22,7 +22,11 @@ class App extends React.Component {

Standalone Stack

- + - + = { + grayscale, + qualitative, + heatmap, + warm, + cool, + red, + blue, + green, }; - return name ? scales[name] : scales.grayscale; + + const selectedScale = + name && scales[name]?.length ? scales[name] : scales.grayscale; + + return selectedScale; } diff --git a/packages/victory-core/src/victory-util/wrapper.tsx b/packages/victory-core/src/victory-util/wrapper.tsx index f0f3bea8a..790af7abe 100644 --- a/packages/victory-core/src/victory-util/wrapper.tsx +++ b/packages/victory-core/src/victory-util/wrapper.tsx @@ -298,7 +298,8 @@ export function getAllEvents(props) { return events || []; } -export function getColor(calculatedProps, child, index) { +// eslint-disable-next-line max-params +export function getColor(calculatedProps, child, index, theme) { // check for styles first const { style } = calculatedProps; let { colorScale, color } = calculatedProps; @@ -313,7 +314,7 @@ export function getColor(calculatedProps, child, index) { } const colors = Array.isArray(colorScale) ? colorScale - : Style.getColorScale(colorScale); + : Style.getColorScale(colorScale, theme); return color || colors[index % colors.length]; } @@ -323,7 +324,8 @@ export function getStyle(theme, style, role) { return Helpers.getStyles(style, defaultStyle); } -export function getChildStyle(child, index, calculatedProps) { +// eslint-disable-next-line max-params +export function getChildStyle(child, index, calculatedProps, theme) { const { style, role } = calculatedProps; const childStyle = child.props.style || {}; if (Array.isArray(childStyle)) { @@ -331,7 +333,9 @@ export function getChildStyle(child, index, calculatedProps) { } const childRole = child.type && child.type.role; const defaultFill = - childRole === "stack" ? undefined : getColor(calculatedProps, child, index); + childRole === "stack" + ? undefined + : getColor(calculatedProps, child, index, theme); const defaultColor = childRole === "line" ? { fill: "none", stroke: defaultFill } diff --git a/packages/victory-group/src/helper-methods.tsx b/packages/victory-group/src/helper-methods.tsx index dac620485..5cb97b3c1 100644 --- a/packages/victory-group/src/helper-methods.tsx +++ b/packages/victory-group/src/helper-methods.tsx @@ -193,7 +193,7 @@ export function getChildren(initialProps, childComponents?, calculatedProps?) { const newCalculatedProps = calculatedProps || getCalculatedProps(props, children); const { datasets } = newCalculatedProps; - const { labelComponent, polar } = props; + const { labelComponent, polar, theme } = props; const childProps = getChildProps(props, newCalculatedProps); const parentName = props.name || "group"; return children.map((child, index) => { @@ -204,7 +204,7 @@ export function getChildren(initialProps, childComponents?, calculatedProps?) { const style = role === "voronoi" || role === "tooltip" || role === "label" ? child.props.style - : Wrapper.getChildStyle(child, index, newCalculatedProps); + : Wrapper.getChildStyle(child, index, newCalculatedProps, theme); const labels = props.labels ? getLabels(props, datasets, index) : child.props.labels; diff --git a/packages/victory-legend/src/helper-methods.ts b/packages/victory-legend/src/helper-methods.ts index f149f7f59..e8b7995df 100644 --- a/packages/victory-legend/src/helper-methods.ts +++ b/packages/victory-legend/src/helper-methods.ts @@ -3,9 +3,9 @@ import { Helpers, Style, TextSize } from "victory-core"; import { VictoryLegendProps } from "./victory-legend"; const getColorScale = (props) => { - const { colorScale } = props; + const { colorScale, theme } = props; return typeof colorScale === "string" - ? Style.getColorScale(colorScale) + ? Style.getColorScale(colorScale, theme) : colorScale || []; }; diff --git a/packages/victory-pie/src/helper-methods.ts b/packages/victory-pie/src/helper-methods.ts index e44667e01..143ee3cd5 100644 --- a/packages/victory-pie/src/helper-methods.ts +++ b/packages/victory-pie/src/helper-methods.ts @@ -60,12 +60,12 @@ const getSlices = (props, data) => { }; const getCalculatedValues = (props) => { - const { colorScale } = props; + const { colorScale, theme } = props; const styleObject = Helpers.getDefaultStyles(props, "pie"); const style = Helpers.getStyles(props.style, styleObject); const colors = Array.isArray(colorScale) ? colorScale - : Style.getColorScale(colorScale); + : Style.getColorScale(colorScale, theme); const padding = Helpers.getPadding(props); const defaultRadius = getRadius(props, padding); const origin = getOrigin(props, padding); diff --git a/packages/victory-stack/src/helper-methods.tsx b/packages/victory-stack/src/helper-methods.tsx index bfa3730c3..acf76e96b 100644 --- a/packages/victory-stack/src/helper-methods.tsx +++ b/packages/victory-stack/src/helper-methods.tsx @@ -242,10 +242,16 @@ export function getChildren(initialProps, childComponents, calculatedProps) { const { datasets } = newCalculatedProps; const childProps = getChildProps(props, newCalculatedProps); const parentName = props.name || "stack"; + const { theme } = props; return children.map((child, index) => { const role = child.type && child.type.role; const data = datasets[index]; - const style = Wrapper.getChildStyle(child, index, newCalculatedProps); + const style = Wrapper.getChildStyle( + child, + index, + newCalculatedProps, + theme, + ); const labels = props.labels ? getLabels(props, datasets, index) : child.props.labels;