Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b90e4f0
feat(partial): stacked column chart for the vue package
IlyesBenAmara Oct 26, 2022
9d7b0ac
fix(partial): bug investigation
IlyesBenAmara Oct 27, 2022
145c7d0
feat(partial): stacked column chart for the vue package
IlyesBenAmara Oct 26, 2022
461ae2a
fix(partial): bug investigation
IlyesBenAmara Oct 27, 2022
a00142b
feat(partial): stacked column chart (vue)
IlyesBenAmara Oct 28, 2022
9383089
Merge branch 'feat/StackedColumnChart-vue' of github.com-IlyesBenAmar…
IlyesBenAmara Oct 28, 2022
740daab
feat(partial): stacked column chart (vue)
IlyesBenAmara Oct 28, 2022
167fe6f
feat(partial): stacked column chart for the vue package
IlyesBenAmara Oct 26, 2022
d747867
fix(partial): bug investigation
IlyesBenAmara Oct 27, 2022
fee3a25
feat(partial): stacked column chart (vue)
IlyesBenAmara Oct 28, 2022
9750fff
fix(partial): bug investigation
IlyesBenAmara Oct 27, 2022
06b4310
feat(partial): stacked column chart (vue)
IlyesBenAmara Oct 28, 2022
ed38635
Merge branch 'feat/StackedColumnChart-vue' of github.com-IlyesBenAmar…
IlyesBenAmara Oct 31, 2022
f7029bc
feat(partial): stacked column chart for the vue package
IlyesBenAmara Oct 26, 2022
b677c08
fix(partial): bug investigation
IlyesBenAmara Oct 27, 2022
8251b65
feat(partial): stacked column chart (vue)
IlyesBenAmara Oct 28, 2022
0a3a09b
fix(partial): bug investigation
IlyesBenAmara Oct 27, 2022
ff022d2
feat(partial): stacked column chart (vue)
IlyesBenAmara Oct 28, 2022
2188d23
fix(partial): bug investigation
IlyesBenAmara Oct 27, 2022
5045074
feat(partial): stacked column chart (vue)
IlyesBenAmara Oct 28, 2022
f685e03
fix(partial): bug investigation
IlyesBenAmara Oct 27, 2022
7773d6f
feat(partial): stacked column chart (vue)
IlyesBenAmara Oct 28, 2022
3aaca2e
Merge branch 'feat/StackedColumnChart-vue' of github.com-IlyesBenAmar…
IlyesBenAmara Oct 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/ez-vue/src/components/Bars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,22 @@ export default class Bars extends Vue {
}

render() {
const { shapeData } = this;
const {
shapeData, chart, $scopedSlots, cartesianScale, colorScale,
} = this;
const { dimensions } = chart;

return (
<g class="ez-bars">
{shapeData.map((rectDatum) => (
<Bar shapeDatum={rectDatum} key={rectDatum.id} />
))}
{$scopedSlots.default
? $scopedSlots.default({
shapeData,
scales: { ...cartesianScale, colorScale },
dimensions,
})
: shapeData.map((rectDatum) => (
<Bar shapeDatum={rectDatum} key={rectDatum.id} />
))}
</g>
);
}
Expand Down
114 changes: 114 additions & 0 deletions packages/ez-vue/src/components/StackedBars.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import Vue, { PropType } from 'vue';
import Component from 'vue-class-component';
import {
ChartContext,
Direction,
RectangleDatum,
ScaleLinearOrBand,
} from 'eazychart-core/src/types';
import { InjectReactive, Prop } from 'vue-property-decorator';
import { ScaleOrdinal, scaleRectangleData } from 'eazychart-core/src';
import Bar from '@/components/shapes/Bar';

@Component({ components: { Bar } })
export default class StackedBars extends Vue {
@InjectReactive('chart')
private chart!: ChartContext;

@InjectReactive('cartesianScale')
private cartesianScale!: {
xScale: ScaleLinearOrBand;
yScale: ScaleLinearOrBand;
};

@Prop({
type: String,
required: true,
})
private readonly singleDomainKey!: string;

@Prop({
type: Array,
required: true,
})
private readonly stackDomainKeys!: string[];

@Prop({
type: String as PropType<Direction>,
required: true,
})
private readonly direction: Direction = Direction.VERTICAL;

get colorScale() {
return this.chart.getScale('colorScale') as ScaleOrdinal;
}

get scaledDataDict() {
return this.stackDomainKeys.reduce(
(acc: { [key: string]: RectangleDatum[] }, yDomainKey) => {
acc[yDomainKey] = scaleRectangleData(
this.chart.data,
this.singleDomainKey,
yDomainKey,
this.cartesianScale.xScale,
this.cartesianScale.yScale,
this.colorScale,
this.chart.dimensions,
this.chart.isRTL,
);
return acc;
},
{},
);
}

render() {
const {
scaledDataDict, chart, stackDomainKeys, colorScale, direction,
} = this;

return (
<g class="ez-stacked-bars">
{chart.data.map((_datum, idx) => (
// The Domain keys still needs to be sorted.
// We create a bar for every data row
// Each bar is a stack bar where every element is a domain key.
<g class="ez-stacked-bar">
{stackDomainKeys.map((yDomainKey, domainIdx) => {
const color = colorScale.scale(yDomainKey);
const scaledData = scaledDataDict[yDomainKey][idx];
// The first domain key will not be affected.
const previousRectWidth = domainIdx !== 0
? scaledDataDict[stackDomainKeys[domainIdx - 1]][idx].width
: 0;
const previousRectHeight = domainIdx !== 0
? scaledDataDict[stackDomainKeys[domainIdx - 1]][idx].height
: 0;
// The height or the width of the current bar will be computed depending
// to the orientaion
// the height will be currentDKHeight - previousDKHeight (same for the width)
const shapeDatum = {
...scaledData,
width:
direction === Direction.HORIZONTAL
? scaledData.width - previousRectWidth
: scaledData.width,
height:
direction === Direction.VERTICAL
? scaledData.height - previousRectHeight
: scaledData.height,
};

return (
<Bar
key={`${yDomainKey}${idx}`}
shapeDatum={{ ...shapeDatum, color }}
/>
);
})}
</g>
))}
</g>
);
}
}
2 changes: 1 addition & 1 deletion packages/ez-vue/src/components/scales/ColorScale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class ColorScale extends Vue {
})
private readonly definition!: ScaleOrdinalDefinition;

mounted() {
created() {
this.colorScale = this.defineScale();
this.chart.registerScale('colorScale', this.colorScale);
}
Expand Down
25 changes: 25 additions & 0 deletions packages/ez-vue/src/recipes/column/ColumnChart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from 'eazychart-dev/storybook/data';
import ColumnChart from './ColumnChart';
import LineColumnChart from './LineColumnChart';
import StackedColumnChart from './StackedColumnChart';

const meta: Meta = {
title: 'Vue/Column Chart',
Expand Down Expand Up @@ -38,6 +39,17 @@ const LineColumnTemplate: Story = (_args, { argTypes }) => ({
`,
});

const StackedColumnTemplate: Story = (_args, { argTypes }) => ({
title: 'StackedColumn',
components: { StackedColumnChart, ChartWrapper },
props: Object.keys(argTypes),
template: `
<ChartWrapper>
<StackedColumnChart v-bind="$props" />
</ChartWrapper>
`,
});

// By passing using the Args format for exported stories,
// you can control the props for a component for reuse in a test
// https://storybook.js.org/docs/vue/workflows/unit-testing
Expand Down Expand Up @@ -84,3 +96,16 @@ const lineColumnArguments = {
};

LineColumn.args = lineColumnArguments;

export const StackedColumn = StackedColumnTemplate.bind({});

const StackedColumnArguments = {
...defaultArguments,
yAxis: {
domainKeys: ['value', 'value1', 'value2'],
title: 'Temperature',
tickFormat: (d: number) => `${d}°`,
},
};

StackedColumn.args = StackedColumnArguments;
Loading