Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export abstract class AbstractChart {
readonly title: TitleDesign;
abstract readonly type: ChartType;
protected readonly getters: CoreGetters;
readonly humanize: boolean;
readonly humanize: boolean | undefined;

constructor(definition: ChartDefinition, sheetId: UID, getters: CoreGetters) {
this.title = definition.title;
this.sheetId = sheetId;
this.getters = getters;
this.humanize = definition.humanize ?? true;
this.humanize = definition.humanize;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { _t } from "../../../translation";
import {
ChartAxisFormats,
ChartWithDataSetDefinition,
CustomizedDataSet,
ChartWithRangeDataSetDefinition,
DataSet,
DatasetValues,
ExcelChartDataset,
ExcelChartTrendConfiguration,
GenericDefinition,
RangeChartDataSet,
} from "../../../types/chart";
import { CommandResult } from "../../../types/commands";
import { CoreGetters } from "../../../types/core_getters";
Expand Down Expand Up @@ -159,7 +160,7 @@ export function adaptChartRange(
*/
export function createDataSets(
getters: CoreGetters,
customizedDataSets: CustomizedDataSet[],
customizedDataSets: RangeChartDataSet[],
sheetId: UID,
dataSetsHaveTitle: boolean
): DataSet[] {
Expand Down Expand Up @@ -323,11 +324,9 @@ export function toExcelLabelRange(
* Transform a chart definition which supports dataSets (dataSets and LabelRange)
* with an executed command
*/
export function transformChartDefinitionWithDataSetsWithZone<T extends ChartWithDataSetDefinition>(
chartSheetId: UID,
definition: T,
applyChange: RangeAdapter
): T {
export function transformChartDefinitionWithDataSetsWithZone<
T extends ChartWithRangeDataSetDefinition
>(chartSheetId: UID, definition: T, applyChange: RangeAdapter): T {
let labelRange: string | undefined;
if (definition.labelRange) {
const adaptedRange = adaptStringRange(chartSheetId, definition.labelRange, applyChange);
Expand All @@ -336,7 +335,7 @@ export function transformChartDefinitionWithDataSetsWithZone<T extends ChartWith
}
}

const dataSets: CustomizedDataSet[] = [];
const dataSets: RangeChartDataSet[] = [];
for (const dataSet of definition.dataSets) {
const newDataSet = { ...dataSet };
const adaptedRange = adaptStringRange(chartSheetId, dataSet.dataRange, applyChange);
Expand Down Expand Up @@ -372,7 +371,7 @@ export function chartMutedFontColor(backgroundColor: Color | undefined): Color {
return relativeLuminance(backgroundColor) < 0.3 ? "#C8C8C8" : "#666666";
}

export function checkDataset(definition: ChartWithDataSetDefinition): CommandResult {
export function checkDataset(definition: ChartWithRangeDataSetDefinition): CommandResult {
if (definition.dataSets) {
const invalidRanges =
definition.dataSets.find((range) => !rangeReference.test(range.dataRange)) !== undefined;
Expand All @@ -387,7 +386,7 @@ export function checkDataset(definition: ChartWithDataSetDefinition): CommandRes
return CommandResult.Success;
}

export function checkLabelRange(definition: ChartWithDataSetDefinition): CommandResult {
export function checkLabelRange(definition: ChartWithRangeDataSetDefinition): CommandResult {
if (definition.labelRange) {
const invalidLabels = !rangeReference.test(definition.labelRange || "");
if (invalidLabels) {
Expand Down
16 changes: 14 additions & 2 deletions packages/o-spreadsheet-engine/src/migrations/migration_steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getMaxObjectId } from "../helpers/pivot/pivot_helpers";
import { DEFAULT_TABLE_CONFIG } from "../helpers/table_presets";
import { overlap, toZone, zoneToXc } from "../helpers/zones";
import { Registry } from "../registry";
import { CustomizedDataSet } from "../types/chart";
import { RangeChartDataSet } from "../types/chart";
import { Format } from "../types/format";
import { DEFAULT_LOCALE } from "../types/locale";
import { Zone } from "../types/misc";
Expand Down Expand Up @@ -297,7 +297,7 @@ migrationStepRegistry
continue;
}
const { dataSets, ...newData } = sheet.figures[f].data;
const newDataSets: CustomizedDataSet = dataSets.map((dataRange) => ({ dataRange }));
const newDataSets: RangeChartDataSet = dataSets.map((dataRange) => ({ dataRange }));
newData.dataSets = newDataSets;
sheet.figures[f].data = newData;
}
Expand Down Expand Up @@ -553,6 +553,18 @@ migrationStepRegistry
}
return data;
},
})
.add("19.1.0", {
migrate(data: WorkbookData): any {
for (const sheet of data.sheets || []) {
for (const figure of sheet.figures || []) {
if (figure.tag === "chart" && !("humanize" in figure.data)) {
figure.data.humanize = true;
}
}
}
return data;
},
});

function fixOverlappingFilters(data: any): any {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { range } from "../../helpers/misc";
import { CellPosition, Dimension, HeaderIndex, UID } from "../../types/misc";
import { ExcelWorkbookData } from "../../types/workbook_data";
import { UIPlugin } from "../ui_plugin";
Expand Down Expand Up @@ -78,10 +77,12 @@ export class HeaderVisibilityUIPlugin extends UIPlugin {
dimension: Dimension,
{ last, first }: { first: HeaderIndex; last: HeaderIndex }
): HeaderIndex {
const lastVisibleIndex = range(last, first, -1).find(
(index) => !this.isHeaderHidden(sheetId, dimension, index)
);
return lastVisibleIndex || first;
for (let header = last; header >= first; header--) {
if (!this.isHeaderHidden(sheetId, dimension, header)) {
return header;
}
}
return first;
}

findFirstVisibleColRowIndex(sheetId: UID, dimension: Dimension) {
Expand Down
4 changes: 2 additions & 2 deletions packages/o-spreadsheet-engine/src/types/chart/bar_chart.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ChartConfiguration } from "chart.js";
import { Color } from "../misc";
import { CommonChartDefinition } from "./index";
import { ChartRangeDefinition } from "./index";

export interface BarChartDefinition extends CommonChartDefinition {
export interface BarChartDefinition extends ChartRangeDefinition {
readonly type: "bar";
readonly stacked: boolean;
readonly horizontal?: boolean;
Expand Down
16 changes: 12 additions & 4 deletions packages/o-spreadsheet-engine/src/types/chart/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export type ChartWithDataSetDefinition = Extract<
{ dataSets: CustomizedDataSet[]; labelRange?: string; humanize?: boolean }
>;

export type ChartWithRangeDataSetDefinition = Extract<
ChartDefinition,
{ dataSets: RangeChartDataSet[] }
>;

export type ChartWithAxisDefinition = Extract<
ChartWithDataSetDefinition,
{ axesDesign?: AxesDesign }
Expand Down Expand Up @@ -136,11 +141,14 @@ export interface TrendConfiguration {
window?: number;
}

export type CustomizedDataSet = {
readonly dataRange: string;
type CustomizedDataSet = {
readonly trend?: TrendConfiguration;
} & DatasetDesign;

export type RangeChartDataSet = CustomizedDataSet & {
readonly dataRange: string;
};

export type AxisType = "category" | "linear" | "time";

export type ChartDatasetOrientation = "rows" | "columns";
Expand Down Expand Up @@ -194,8 +202,8 @@ export interface ExcelChartDefinition {
}

export interface ChartCreationContext {
readonly range?: CustomizedDataSet[];
readonly hierarchicalRanges?: CustomizedDataSet[];
readonly range?: RangeChartDataSet[];
readonly hierarchicalRanges?: RangeChartDataSet[];
readonly title?: TitleDesign;
readonly background?: Color;
readonly auxiliaryRange?: string;
Expand Down
8 changes: 4 additions & 4 deletions packages/o-spreadsheet-engine/src/types/chart/combo_chart.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { ChartConfiguration } from "chart.js";
import { Color } from "../misc";
import { CustomizedDataSet } from "./chart";
import { CommonChartDefinition } from "./common_chart";
import { RangeChartDataSet } from "./chart";
import { ChartRangeDefinition } from "./common_chart";

export interface ComboChartDefinition extends CommonChartDefinition {
export interface ComboChartDefinition extends ChartRangeDefinition {
readonly dataSets: ComboChartDataSet[];
readonly type: "combo";
readonly hideDataMarkers?: boolean;
readonly zoomable?: boolean;
}

export type ComboChartDataSet = CustomizedDataSet & { type?: "bar" | "line" };
export type ComboChartDataSet = RangeChartDataSet & { type?: "bar" | "line" };

export type ComboChartRuntime = {
chartJsConfig: ChartConfiguration;
Expand Down
11 changes: 7 additions & 4 deletions packages/o-spreadsheet-engine/src/types/chart/common_chart.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { Color } from "../misc";
import { AxesDesign, CustomizedDataSet, TitleDesign } from "./chart";
import { AxesDesign, RangeChartDataSet, TitleDesign } from "./chart";

export type VerticalAxisPosition = "left" | "right";
export type LegendPosition = "top" | "bottom" | "left" | "right" | "none";

export interface CommonChartDefinition {
readonly dataSets: CustomizedDataSet[];
readonly dataSetsHaveTitle: boolean;
readonly labelRange?: string;
readonly title: TitleDesign;
readonly background?: Color;
readonly legendPosition: LegendPosition;
Expand All @@ -16,3 +13,9 @@ export interface CommonChartDefinition {
readonly showValues?: boolean;
readonly humanize?: boolean;
}

export interface ChartRangeDefinition extends CommonChartDefinition {
readonly dataSetsHaveTitle: boolean;
readonly labelRange?: string;
readonly dataSets: RangeChartDataSet[];
}
4 changes: 2 additions & 2 deletions packages/o-spreadsheet-engine/src/types/chart/funnel_chart.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ChartConfiguration } from "chart.js";
import { Color } from "../misc";
import { AxesDesign, CustomizedDataSet, TitleDesign } from "./chart";
import { AxesDesign, RangeChartDataSet, TitleDesign } from "./chart";
import { LegendPosition } from "./common_chart";

export interface FunnelChartDefinition {
readonly type: "funnel";
readonly dataSets: CustomizedDataSet[];
readonly dataSets: RangeChartDataSet[];
readonly dataSetsHaveTitle: boolean;
readonly labelRange?: string;
readonly title: TitleDesign;
Expand Down
4 changes: 2 additions & 2 deletions packages/o-spreadsheet-engine/src/types/chart/geo_chart.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ChartConfiguration } from "chart.js";
import { Color } from "../misc";
import { ChartRuntimeGenerationArgs, CustomizedDataSet, TitleDesign } from "./chart";
import { ChartRuntimeGenerationArgs, RangeChartDataSet, TitleDesign } from "./chart";
import { LegendPosition } from "./common_chart";

export interface GeoChartDefinition {
readonly type: "geo";
readonly dataSets: CustomizedDataSet[];
readonly dataSets: RangeChartDataSet[];
readonly dataSetsHaveTitle: boolean;
readonly labelRange?: string;
readonly title: TitleDesign;
Expand Down
4 changes: 2 additions & 2 deletions packages/o-spreadsheet-engine/src/types/chart/line_chart.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ChartConfiguration } from "chart.js";
import { Color } from "../misc";
import { CommonChartDefinition } from "./common_chart";
import { ChartRangeDefinition } from "./common_chart";

export interface LineChartDefinition extends CommonChartDefinition {
export interface LineChartDefinition extends ChartRangeDefinition {
readonly type: "line";
readonly labelsAsText: boolean;
readonly stacked: boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/o-spreadsheet-engine/src/types/chart/pie_chart.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ChartConfiguration } from "chart.js";
import { Color } from "../misc";
import { CommonChartDefinition } from "./common_chart";
import { ChartRangeDefinition } from "./common_chart";

export interface PieChartDefinition extends CommonChartDefinition {
export interface PieChartDefinition extends ChartRangeDefinition {
readonly type: "pie";
readonly aggregated?: boolean;
readonly isDoughnut?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/o-spreadsheet-engine/src/types/chart/radar_chart.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ChartConfiguration } from "chart.js";
import { Color } from "../misc";
import { CommonChartDefinition } from "./common_chart";
import { ChartRangeDefinition } from "./common_chart";

export interface RadarChartDefinition extends CommonChartDefinition {
export interface RadarChartDefinition extends ChartRangeDefinition {
readonly type: "radar";
readonly aggregated?: boolean;
readonly stacked: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { ChartConfiguration, ChartDataset } from "chart.js";
import { Color } from "../misc";
import { ChartStyle, CustomizedDataSet, TitleDesign } from "./chart";
import { ChartStyle, RangeChartDataSet, TitleDesign } from "./chart";
import { LegendPosition } from "./common_chart";

export interface SunburstChartDefinition {
readonly type: "sunburst";
readonly dataSets: CustomizedDataSet[];
readonly dataSets: RangeChartDataSet[];
readonly dataSetsHaveTitle: boolean;
readonly labelRange?: string;
readonly title: TitleDesign;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ChartConfiguration } from "chart.js";
import { Color } from "../misc";
import { CustomizedDataSet, TitleDesign } from "./chart";
import { RangeChartDataSet, TitleDesign } from "./chart";
import { TreemapDataPoint } from "./chartjs_tree_map_type";
import { LegendPosition } from "./common_chart";

export interface TreeMapChartDefinition {
readonly type: "treemap";
readonly dataSets: CustomizedDataSet[];
readonly dataSets: RangeChartDataSet[];
readonly dataSetsHaveTitle: boolean;
readonly labelRange?: string;
readonly title: TitleDesign;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ChartConfiguration } from "chart.js";
import { Color } from "../misc";
import { CommonChartDefinition, VerticalAxisPosition } from "./common_chart";
import { ChartRangeDefinition, VerticalAxisPosition } from "./common_chart";

export interface WaterfallChartDefinition extends CommonChartDefinition {
export interface WaterfallChartDefinition extends ChartRangeDefinition {
readonly type: "waterfall";
readonly verticalAxisPosition: VerticalAxisPosition;
readonly aggregated?: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { _t } from "@odoo/o-spreadsheet-engine/translation";
import { SpreadsheetChildEnv } from "@odoo/o-spreadsheet-engine/types/spreadsheet_env";
import { Component } from "@odoo/owl";
import { ChartDatasetOrientation, Color, CustomizedDataSet } from "../../../../../types";
import { ChartDatasetOrientation, Color, RangeChartDataSet } from "../../../../../types";
import { SelectionInput } from "../../../../selection_input/selection_input";
import { Section } from "../../../components/section/section";

interface Props {
ranges: CustomizedDataSet[];
ranges: RangeChartDataSet[];
hasSingleRange?: boolean;
onSelectionChanged: (ranges: string[]) => void;
onSelectionReordered?: (indexes: number[]) => void;
Expand Down
Loading