mdt-charts 1.20.1 → 1.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -195,6 +195,7 @@ interface Tooltip {
195
195
  interface MdtChartsLineLikeChart {
196
196
  markers: MarkersOptions;
197
197
  lineStyles?: MdtChartsLineLikeChartStyles;
198
+ areaStyles?: MdtChartsLineLikeChartAreaStyles;
198
199
  }
199
200
  export interface MdtChartsLineLikeChartStyles {
200
201
  dash?: MdtChartsLineLikeChartDashedStyles;
@@ -204,6 +205,16 @@ export interface MdtChartsLineLikeChartDashedStyles {
204
205
  dashSize?: number;
205
206
  gapSize?: number;
206
207
  }
208
+ export interface MdtChartsLineLikeChartAreaStyles {
209
+ gradient?: AreaStylesGradient;
210
+ borderLine?: AreaStylesBorderLine;
211
+ }
212
+ export interface AreaStylesGradient {
213
+ on: boolean;
214
+ }
215
+ export interface AreaStylesBorderLine {
216
+ on: boolean;
217
+ }
207
218
  interface MdtChartsBarLikeChart {
208
219
  barStyles?: MdtChartsBarLikeChartStyles;
209
220
  }
@@ -0,0 +1,6 @@
1
+ import { Selection } from "d3-selection";
2
+ import { GradientDef } from "../../../model/model";
3
+ export declare class LinearGradientDef {
4
+ render(defs: Selection<SVGDefsElement, unknown, HTMLElement, any>, gradients: GradientDef[]): void;
5
+ updateColors(defs: Selection<SVGDefsElement, unknown, HTMLElement, any>, gradients: GradientDef[]): void;
6
+ }
@@ -0,0 +1,28 @@
1
+ export class LinearGradientDef {
2
+ render(defs, gradients) {
3
+ gradients.forEach(gradient => {
4
+ const linearGradient = defs.append("linearGradient")
5
+ .attr("id", gradient.id)
6
+ .attr("x1", gradient.position.x1)
7
+ .attr("y1", gradient.position.y1)
8
+ .attr("x2", gradient.position.x2)
9
+ .attr("y2", gradient.position.y2);
10
+ gradient.items.forEach(item => {
11
+ linearGradient.append("stop")
12
+ .attr("id", item.id)
13
+ .attr("offset", item.offset)
14
+ .attr("stop-opacity", item.opacity)
15
+ .attr("stop-color", item.color);
16
+ });
17
+ });
18
+ }
19
+ updateColors(defs, gradients) {
20
+ gradients.forEach(gradient => {
21
+ const linearGradient = defs.select(`#${gradient.id}`);
22
+ gradient.items.forEach(item => {
23
+ linearGradient.select(`#${item.id}`)
24
+ .attr("stop-color", item.color);
25
+ });
26
+ });
27
+ }
28
+ }
@@ -25,6 +25,7 @@ export declare class DomHelper {
25
25
  * @returns Выборка по ключам
26
26
  */
27
27
  static getChartElementsByKeys<T extends BaseType>(initialSelection: Selection<T, MdtChartsDataRow, BaseType, unknown>, dataWrapped: boolean, keyFieldName: string, keyValues: string[], condition?: SelectionCondition): Selection<T, any, BaseType, unknown>;
28
+ static setChartGradientStyle(element: Selection<BaseType, unknown, BaseType, unknown>, chartIndex: number, valueIndex: number): void;
28
29
  private static setChartOpacity;
29
30
  }
30
31
  export {};
@@ -1,5 +1,6 @@
1
1
  import { MarkDot } from "../features/markDots/markDot";
2
2
  import { Bar } from "../twoDimensionalNotation/bar/bar";
3
+ import { getGradientId } from "../../model/notations/twoDimensional/styles";
3
4
  export var SelectionCondition;
4
5
  (function (SelectionCondition) {
5
6
  SelectionCondition[SelectionCondition["Include"] = 0] = "Include";
@@ -62,6 +63,9 @@ export class DomHelper {
62
63
  return condition === SelectionCondition.Exclude ? i === -1 : i !== -1;
63
64
  });
64
65
  }
66
+ static setChartGradientStyle(element, chartIndex, valueIndex) {
67
+ element.style('fill', `url(#${getGradientId(chartIndex, valueIndex)})`);
68
+ }
65
69
  static setChartOpacity(elements, opacity) {
66
70
  elements.attr('opacity', opacity);
67
71
  }
@@ -8,6 +8,7 @@ interface AreaOptions {
8
8
  export declare class Area {
9
9
  private readonly options;
10
10
  static readonly areaChartClass = "area";
11
+ static readonly areaBorderLineClass = "area-border-line";
11
12
  static get(options: AreaOptions): Area;
12
13
  constructor(options: AreaOptions);
13
14
  render(block: Block, scales: Scales, data: MdtChartsDataRow[], keyField: Field, margin: BlockMargin, keyAxisOrient: Orient, chart: TwoDimensionalChartModel, blockSize: Size): void;
@@ -20,5 +21,12 @@ export declare class Area {
20
21
  private updateGroupedPath;
21
22
  private updateSegmentedPath;
22
23
  private setSegmentColor;
24
+ private setChartFillStyle;
25
+ private createAreaGeneratorFactory;
26
+ private createLineGeneratorFactory;
27
+ private renderArea;
28
+ private renderBorderLine;
29
+ private updateArea;
30
+ private updateBorderLine;
23
31
  }
24
32
  export {};
@@ -4,6 +4,8 @@ import { AreaGeneratorFactory } from './areaHelper';
4
4
  import { DomHelper } from '../../helpers/domHelper';
5
5
  import { Helper } from '../../helpers/helper';
6
6
  import { getStackedDataWithOwn } from '../bar/stackedData/dataStacker';
7
+ import { LineGeneratorFactory } from "../../../engine/twoDimensionalNotation/line/lineHelper";
8
+ import { Line } from "../../../engine/twoDimensionalNotation/line/line";
7
9
  export class Area {
8
10
  constructor(options) {
9
11
  this.options = options;
@@ -29,31 +31,33 @@ export class Area {
29
31
  }
30
32
  updateColors(block, chart) {
31
33
  chart.data.valueFields.forEach((_vf, valueIndex) => {
32
- const path = block.svg.getChartGroup(chart.index)
34
+ const chartGroup = block.svg.getChartGroup(chart.index);
35
+ const areaPath = chartGroup
33
36
  .select(`.${Area.areaChartClass}${Helper.getCssClassesLine(chart.cssClasses)}.chart-element-${valueIndex}`);
34
- DomHelper.setChartStyle(path, chart.style, valueIndex, 'fill');
37
+ this.setChartFillStyle(chart, areaPath, valueIndex);
38
+ if (chart.areaViewOptions.borderLine.on) {
39
+ const borderLinePath = chartGroup
40
+ .select(`.${Area.areaBorderLineClass}${Helper.getCssClassesLine(chart.cssClasses)}.chart-element-${valueIndex}`);
41
+ DomHelper.setChartElementColor(borderLinePath, chart.style.elementColors, valueIndex, 'stroke');
42
+ }
35
43
  MarkDot.updateColors(block, chart, valueIndex);
36
44
  });
37
45
  }
38
46
  renderGrouped(block, scales, data, keyField, margin, keyAxisOrient, chart) {
39
- const generatorFactory = new AreaGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, shouldRender: chart.lineLikeViewOptions.renderForKey, curve: this.options.staticSettings.shape.curve.type });
47
+ const areaGeneratorFactory = this.createAreaGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
48
+ const lineGeneratorFactory = chart.areaViewOptions.borderLine.on
49
+ && this.createLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
40
50
  chart.data.valueFields.forEach((field, valueIndex) => {
41
- const area = generatorFactory.getAreaGenerator(field.name);
42
- const path = block.svg.getChartGroup(chart.index)
43
- .append('path')
44
- .attr('d', area(data))
45
- .attr('class', Area.areaChartClass)
46
- .style('clip-path', `url(#${block.svg.getClipPathId()})`)
47
- .style('pointer-events', 'none');
48
- DomHelper.setCssClasses(path, Helper.getCssClassesWithElementIndex(chart.cssClasses, valueIndex));
49
- DomHelper.setChartStyle(path, chart.style, valueIndex, 'fill');
51
+ this.renderArea(areaGeneratorFactory, block, chart, data, field, valueIndex);
52
+ if (lineGeneratorFactory)
53
+ this.renderBorderLine(lineGeneratorFactory, block, chart, data, field, valueIndex);
50
54
  MarkDot.render(block, data, keyAxisOrient, scales, margin, keyField.name, valueIndex, field.name, chart);
51
55
  });
52
56
  }
53
57
  renderSegmented(block, scales, data, keyField, margin, keyAxisOrient, chart) {
54
58
  const stackedData = getStackedDataWithOwn(data, chart.data.valueFields.map(field => field.name));
55
- const generatorFactory = new AreaGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, shouldRender: chart.lineLikeViewOptions.renderForKey, curve: this.options.staticSettings.shape.curve.type });
56
- const areaGenerator = generatorFactory.getSegmentedAreaGenerator();
59
+ const areaGeneratorFactory = this.createAreaGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
60
+ const areaGenerator = areaGeneratorFactory.getSegmentedAreaGenerator();
57
61
  const areas = block.svg.getChartGroup(chart.index)
58
62
  .selectAll(`.${Area.areaChartClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
59
63
  .data(stackedData)
@@ -73,20 +77,24 @@ export class Area {
73
77
  }
74
78
  updateGrouped(block, scales, newData, keyField, margin, chart, keyAxisOrient, blockSize) {
75
79
  const promises = [];
76
- const generatorFactory = new AreaGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, shouldRender: chart.lineLikeViewOptions.renderForKey, curve: this.options.staticSettings.shape.curve.type });
80
+ const areaGeneratorFactory = this.createAreaGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
81
+ const lineGeneratorFactory = chart.areaViewOptions.borderLine.on
82
+ && this.createLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
77
83
  chart.data.valueFields.forEach((field, valueIndex) => {
78
- const areaGenerator = generatorFactory.getAreaGenerator(field.name);
79
- const areaObject = block.svg.getChartGroup(chart.index)
80
- .select(`.${Area.areaChartClass}${Helper.getCssClassesLine(chart.cssClasses)}.chart-element-${valueIndex}`);
81
- const prom = this.updateGroupedPath(block, areaObject, areaGenerator, newData);
82
- promises.push(prom);
84
+ const chartGroup = block.svg.getChartGroup(chart.index);
85
+ const areaProm = this.updateArea(areaGeneratorFactory, chartGroup, block, field, chart, newData, valueIndex);
86
+ promises.push(areaProm);
87
+ if (lineGeneratorFactory) {
88
+ const lineProm = this.updateBorderLine(lineGeneratorFactory, chartGroup, block, field, chart, newData, valueIndex);
89
+ promises.push(lineProm);
90
+ }
83
91
  MarkDot.update(block, newData, keyAxisOrient, scales, margin, keyField.name, valueIndex, field.name, chart);
84
92
  });
85
93
  return promises;
86
94
  }
87
95
  updateSegmented(block, scales, newData, keyField, margin, chart, keyAxisOrient) {
88
96
  const stackedData = getStackedDataWithOwn(newData, chart.data.valueFields.map(field => field.name));
89
- const generatorFactory = new AreaGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, shouldRender: chart.lineLikeViewOptions.renderForKey, curve: this.options.staticSettings.shape.curve.type });
97
+ const generatorFactory = this.createAreaGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField);
90
98
  const areaGenerator = generatorFactory.getSegmentedAreaGenerator();
91
99
  const areas = block.svg.getChartGroup(chart.index)
92
100
  .selectAll(`path.${Area.areaChartClass}${Helper.getCssClassesLine(chart.cssClasses)}`)
@@ -137,5 +145,53 @@ export class Area {
137
145
  setSegmentColor(segments, colorPalette) {
138
146
  segments.style('fill', (d, i) => colorPalette[i % colorPalette.length]);
139
147
  }
148
+ setChartFillStyle(chart, path, valueIndex) {
149
+ if (chart.areaViewOptions.fill.type === 'gradient')
150
+ DomHelper.setChartGradientStyle(path, chart.index, valueIndex);
151
+ else
152
+ DomHelper.setChartStyle(path, chart.style, valueIndex, 'fill');
153
+ }
154
+ createAreaGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField) {
155
+ return new AreaGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, shouldRender: chart.lineLikeViewOptions.renderForKey, curve: this.options.staticSettings.shape.curve.type });
156
+ }
157
+ createLineGeneratorFactory(chart, scales, margin, keyAxisOrient, keyField) {
158
+ return new LineGeneratorFactory({ keyAxisOrient, scales, keyFieldName: keyField.name, margin, shouldRender: chart.lineLikeViewOptions.renderForKey, curve: this.options.staticSettings.shape.curve.type });
159
+ }
160
+ renderArea(areaGeneratorFactory, block, chart, data, field, valueIndex) {
161
+ const area = areaGeneratorFactory.getAreaGenerator(field.name);
162
+ const path = block.svg.getChartGroup(chart.index)
163
+ .append('path')
164
+ .attr('d', area(data))
165
+ .attr('class', Area.areaChartClass)
166
+ .style('clip-path', `url(#${block.svg.getClipPathId()})`)
167
+ .style('pointer-events', 'none');
168
+ DomHelper.setCssClasses(path, Helper.getCssClassesWithElementIndex(chart.cssClasses, valueIndex));
169
+ this.setChartFillStyle(chart, path, valueIndex);
170
+ }
171
+ renderBorderLine(lineGeneratorFactory, block, chart, data, field, valueIndex) {
172
+ const lineGenerator = lineGeneratorFactory.getLineGenerator(field.name);
173
+ const linePath = block.svg.getChartGroup(chart.index)
174
+ .append('path')
175
+ .attr('d', lineGenerator(data))
176
+ .attr('class', `${Area.areaBorderLineClass}`)
177
+ .style('fill', 'none')
178
+ .style('clip-path', `url(#${block.svg.getClipPathId()})`)
179
+ .style('pointer-events', 'none');
180
+ DomHelper.setCssClasses(linePath, Helper.getCssClassesWithElementIndex(chart.cssClasses, valueIndex));
181
+ DomHelper.setChartStyle(linePath, chart.areaViewOptions.borderLine.colorStyle, valueIndex, 'stroke');
182
+ }
183
+ updateArea(areaGeneratorFactory, chartGroup, block, field, chart, newData, valueIndex) {
184
+ const areaGenerator = areaGeneratorFactory.getAreaGenerator(field.name);
185
+ const areaObject = chartGroup
186
+ .select(`.${Area.areaChartClass}${Helper.getCssClassesLine(chart.cssClasses)}.chart-element-${valueIndex}`);
187
+ return this.updateGroupedPath(block, areaObject, areaGenerator, newData);
188
+ }
189
+ updateBorderLine(lineGeneratorFactory, chartGroup, block, field, chart, newData, valueIndex) {
190
+ const borderLineGenerator = lineGeneratorFactory.getLineGenerator(field.name);
191
+ const borderLineObject = chartGroup
192
+ .select(`.${Area.areaBorderLineClass}${Helper.getCssClassesLine(chart.cssClasses)}.chart-element-${valueIndex}`);
193
+ return Line.updateGroupedPath(block, borderLineObject, borderLineGenerator, newData);
194
+ }
140
195
  }
141
196
  Area.areaChartClass = 'area';
197
+ Area.areaBorderLineClass = 'area-border-line';
@@ -1,3 +1,4 @@
1
+ import { Line as ILine } from 'd3-shape';
1
2
  import { BaseType, Selection } from 'd3-selection';
2
3
  import { BlockMargin, Field, LineLikeChartSettings, Orient, TwoDimensionalChartModel } from "../../../model/model";
3
4
  import { Scales } from "../../features/scale/scale";
@@ -21,7 +22,7 @@ export declare class Line {
21
22
  private renderSegmented;
22
23
  private updateGrouped;
23
24
  private updateSegmented;
24
- private updateGroupedPath;
25
+ static updateGroupedPath(block: Block, lineObject: Selection<BaseType, any, BaseType, any>, lineGenerator: ILine<MdtChartsDataRow>, newData: MdtChartsDataRow[]): Promise<any>;
25
26
  private updateSegmentedPath;
26
27
  private setSegmentColor;
27
28
  }
@@ -85,7 +85,7 @@ export class Line {
85
85
  const lineGenerator = generatorFactory.getLineGenerator(valueField.name);
86
86
  const lineObject = block.svg.getChartGroup(chart.index)
87
87
  .select(`.${this.lineChartClass}${Helper.getCssClassesLine(chart.cssClasses)}.chart-element-${valueFieldIndex}`);
88
- const prom = this.updateGroupedPath(block, lineObject, lineGenerator, newData);
88
+ const prom = Line.updateGroupedPath(block, lineObject, lineGenerator, newData);
89
89
  promises.push(prom);
90
90
  MarkDot.update(block, newData, keyAxisOrient, scales, margin, keyField.name, valueFieldIndex, valueField.name, chart);
91
91
  });
@@ -104,7 +104,7 @@ export class Line {
104
104
  });
105
105
  return [prom];
106
106
  }
107
- updateGroupedPath(block, lineObject, lineGenerator, newData) {
107
+ static updateGroupedPath(block, lineObject, lineGenerator, newData) {
108
108
  return new Promise(resolve => {
109
109
  if (lineObject.size() === 0) {
110
110
  resolve('');
@@ -5,6 +5,7 @@ import { ChartContentManager } from "../contentManager/contentManagerFactory";
5
5
  import { Engine } from "../engine";
6
6
  export declare class TwoDimensionalManager implements ChartContentManager {
7
7
  private canvasValueLabels?;
8
+ private linearGradientDef?;
8
9
  render(engine: Engine, model: Model<TwoDimensionalOptionsModel>): void;
9
10
  updateData(block: Block, model: Model<TwoDimensionalOptionsModel>, data: MdtChartsDataSource): void;
10
11
  updateColors(block: Block, model: Model<TwoDimensionalOptionsModel>): void;
@@ -14,6 +14,7 @@ import { BarHelper } from "./bar/barHelper";
14
14
  import { TwoDimRecordOverflowAlert } from "./extenders/twoDimRecordOverflowAlert";
15
15
  import { Line } from "./line/line";
16
16
  import { CanvasValueLabels } from "../../engine/features/valueLabels/valueLabels";
17
+ import { LinearGradientDef } from "../../engine/block/defs/LinearGradientDef";
17
18
  export class TwoDimensionalManager {
18
19
  render(engine, model) {
19
20
  const options = model.options;
@@ -52,6 +53,10 @@ export class TwoDimensionalManager {
52
53
  }
53
54
  });
54
55
  this.canvasValueLabels.render(scales, options.charts, engine.data, options.data);
56
+ if (options.defs) {
57
+ this.linearGradientDef = new LinearGradientDef();
58
+ this.linearGradientDef.render(engine.block.svg.ensureDefsRendered(), options.defs.gradients);
59
+ }
55
60
  }
56
61
  updateData(block, model, data) {
57
62
  block.transitionManager.interruptTransitions();
@@ -81,7 +86,9 @@ export class TwoDimensionalManager {
81
86
  this.canvasValueLabels.update(scales, options.charts, data, model.options.data);
82
87
  }
83
88
  updateColors(block, model) {
89
+ var _a;
84
90
  Legend.get().updateColors(block, model.options);
91
+ (_a = this.linearGradientDef) === null || _a === void 0 ? void 0 : _a.updateColors(block.svg.ensureDefsRendered(), model.options.defs.gradients);
85
92
  model.options.charts.forEach(chart => {
86
93
  if (chart.type === 'bar')
87
94
  Bar.get().updateColors(block, chart);
@@ -8,10 +8,14 @@ export class TwoDimensionalChartStyleModel {
8
8
  this.service = new TwoDimensionalChartStyleService();
9
9
  }
10
10
  getChartStyle(chart, chartIndex) {
11
+ var _a, _b;
11
12
  const fieldsAmounts = this.getChartsValueFieldsAmounts();
13
+ const opacity = chart.type === 'area' && ((_b = (_a = chart.areaStyles) === null || _a === void 0 ? void 0 : _a.gradient) === null || _b === void 0 ? void 0 : _b.on)
14
+ ? 1
15
+ : this.service.getChartOpacity(this.charts.length, chart.type, fieldsAmounts[chartIndex], chart.isSegmented);
12
16
  return {
13
17
  elementColors: this.service.getChartColors(chart, this.chartStyleConfig, fieldsAmounts, chartIndex),
14
- opacity: this.service.getChartOpacity(this.charts.length, chart.type, fieldsAmounts[chartIndex], chart.isSegmented)
18
+ opacity,
15
19
  };
16
20
  }
17
21
  getChartsValueFieldsAmounts() {
@@ -1,5 +1,8 @@
1
- import { MdtChartsDataRow, MdtChartsTwoDimensionalChart } from "../../config/config";
2
- import { MarkDotDatumItem } from "../model";
1
+ import { ChartOrientation, MdtChartsDataRow, MdtChartsTwoDimensionalChart } from "../../config/config";
2
+ import { GradientDef, MarkDotDatumItem, Orient, TwoDimensionalChartModel } from "../model";
3
3
  export declare class TwoDimensionalModelHelper {
4
4
  static shouldMarkerShow(chart: MdtChartsTwoDimensionalChart, dataRows: MdtChartsDataRow[], valueFieldName: string, currentRow: MarkDotDatumItem, keyFieldName: string): boolean;
5
+ static getGradientDefs(charts: TwoDimensionalChartModel[], keyAxisOrient: Orient, chartOrient: ChartOrientation): GradientDef[];
6
+ private static getGradientItems;
7
+ private static calculateOpacityItem;
5
8
  }
@@ -1,3 +1,4 @@
1
+ import { getGradientId } from "../../model/notations/twoDimensional/styles";
1
2
  export class TwoDimensionalModelHelper {
2
3
  static shouldMarkerShow(chart, dataRows, valueFieldName, currentRow, keyFieldName) {
3
4
  if (chart.markers.show || dataRows.length === 1)
@@ -13,4 +14,43 @@ export class TwoDimensionalModelHelper {
13
14
  (previousRow === null || previousRow === void 0 ? void 0 : previousRow[valueFieldName]) === null && (nextRow === null || nextRow === void 0 ? void 0 : nextRow[valueFieldName]) === null;
14
15
  return (isFirst && (nextRow === null || nextRow === void 0 ? void 0 : nextRow[valueFieldName]) === null) || (isLast && (previousRow === null || previousRow === void 0 ? void 0 : previousRow[valueFieldName]) === null) || hasNullNeighborsRows;
15
16
  }
17
+ static getGradientDefs(charts, keyAxisOrient, chartOrient) {
18
+ let gradients = [];
19
+ charts.forEach((chart) => {
20
+ var _a;
21
+ if (chart.type === 'area' && chart.areaViewOptions.fill.type === 'gradient') {
22
+ (_a = chart.style.elementColors) === null || _a === void 0 ? void 0 : _a.forEach((elementColor, subIndex) => {
23
+ const gradientId = getGradientId(chart.index, subIndex);
24
+ gradients.push({
25
+ id: gradientId,
26
+ position: {
27
+ x1: 0,
28
+ y1: 0,
29
+ x2: chartOrient === 'horizontal' ? 1 : 0,
30
+ y2: chartOrient === 'horizontal' ? 0 : 1,
31
+ },
32
+ items: this.getGradientItems(gradientId, elementColor, keyAxisOrient),
33
+ });
34
+ });
35
+ }
36
+ });
37
+ return gradients;
38
+ }
39
+ static getGradientItems(gradientId, elementColor, keyAxisOrient) {
40
+ return [0, 1].map(indexItem => ({
41
+ id: gradientId + `-item-${indexItem}`,
42
+ color: elementColor,
43
+ offset: indexItem,
44
+ opacity: this.calculateOpacityItem(indexItem, keyAxisOrient)
45
+ }));
46
+ }
47
+ static calculateOpacityItem(indexItem, orientation) {
48
+ const maxOpacity = 0.3;
49
+ const minOpacity = 0;
50
+ if (orientation === 'bottom' || orientation === 'right')
51
+ return indexItem === 0 ? maxOpacity : minOpacity;
52
+ else
53
+ return indexItem === 0 ? minOpacity : maxOpacity;
54
+ }
55
+ ;
16
56
  }
@@ -12,6 +12,7 @@ export declare type DataOptions = {
12
12
  export declare type UnitsFromConfig = "%" | "px";
13
13
  export declare type ValueLabelAnchor = "start" | "middle" | "end";
14
14
  export declare type ValueLabelDominantBaseline = "hanging" | "middle" | "auto";
15
+ export declare type GradientId = string;
15
16
  export declare type OptionsModel = TwoDimensionalOptionsModel | PolarOptionsModel | IntervalOptionsModel;
16
17
  export interface Model<O = OptionsModel> {
17
18
  blockCanvas: BlockCanvas;
@@ -42,6 +43,7 @@ interface GraphicNotationOptionsModel extends BasicOptionsModel {
42
43
  data: OptionsModelData;
43
44
  title: string;
44
45
  selectable: boolean;
46
+ defs: OptionsModelGradients;
45
47
  }
46
48
  export interface TwoDimensionalOptionsModel extends GraphicNotationOptionsModel {
47
49
  type: "2d";
@@ -80,6 +82,24 @@ export interface Field {
80
82
  name: string;
81
83
  format: DataType;
82
84
  }
85
+ export interface OptionsModelGradients {
86
+ gradients: GradientDef[];
87
+ }
88
+ export interface GradientDef {
89
+ id: GradientId;
90
+ position: {
91
+ x1: number;
92
+ x2: number;
93
+ y1: number;
94
+ y2: number;
95
+ };
96
+ items: {
97
+ id: string;
98
+ color: string;
99
+ offset: number;
100
+ opacity: number;
101
+ }[];
102
+ }
83
103
  export interface IScaleModel {
84
104
  key: ScaleKeyModel;
85
105
  value: ScaleValueModel;
@@ -235,7 +255,24 @@ interface TwoDimensionalBarLikeChartModel {
235
255
  interface TwoDimensionalBarLikeChartViewModel {
236
256
  hatch: BarLikeChartHatchOptions;
237
257
  }
238
- export interface TwoDimensionalChartModel extends ChartModel, TwoDimensionalLineLikeChartModel, TwoDimensionalBarLikeChartModel {
258
+ interface TwoDimensionalAreaChartModel {
259
+ areaViewOptions: AreaChartViewOptions;
260
+ }
261
+ export interface AreaChartViewOptions {
262
+ fill: AreaViewFill;
263
+ borderLine: AreaViewBorderLine;
264
+ }
265
+ export declare type AreaViewFill = {
266
+ type: "paletteColor";
267
+ } | {
268
+ type: "gradient";
269
+ ids: GradientId[];
270
+ };
271
+ export interface AreaViewBorderLine {
272
+ on: boolean;
273
+ colorStyle: ChartStyle;
274
+ }
275
+ export interface TwoDimensionalChartModel extends ChartModel, TwoDimensionalLineLikeChartModel, TwoDimensionalBarLikeChartModel, TwoDimensionalAreaChartModel {
239
276
  type: TwoDimensionalChartType;
240
277
  data: TwoDimensionalChartDataModel;
241
278
  index: number;
@@ -14,7 +14,8 @@ export class PolarModel {
14
14
  charts: this.getChartsModel(options.chart, modelInstance.dataModel.repository.getScopedRows().length, designerConfig.chartStyle),
15
15
  legend: modelInstance.canvasModel.legendCanvas.getModel(),
16
16
  tooltip: options.tooltip,
17
- chartCanvas: this.getDonutSettings(designerConfig.canvas.chartOptions.donut, options.chart, modelInstance.dataModel.repository.getRawRows())
17
+ chartCanvas: this.getDonutSettings(designerConfig.canvas.chartOptions.donut, options.chart, modelInstance.dataModel.repository.getRawRows()),
18
+ defs: { gradients: [] },
18
19
  };
19
20
  }
20
21
  //TODO: type for returned value
@@ -1,7 +1,9 @@
1
- import { ChartLegendModel, LineLikeChartDashOptions, LineLikeChartShapeOptions } from "../../model";
1
+ import { AreaChartViewOptions, ChartLegendModel, ChartStyle, GradientId, LineLikeChartDashOptions, LineLikeChartShapeOptions } from "../../model";
2
2
  import { ChartOrientation, MdtChartsLineLikeChartDashedStyles, MdtChartsTwoDimensionalChart, TwoDimensionalChartType } from "../../../config/config";
3
3
  import { MdtChartsLineLikeChartShape } from "../../../designer/designerConfig";
4
4
  export declare function parseShape(chartOrientation: ChartOrientation, configOptions?: MdtChartsLineLikeChartShape): LineLikeChartShapeOptions;
5
5
  export declare function parseDashStyles(configOptions?: MdtChartsLineLikeChartDashedStyles): LineLikeChartDashOptions;
6
6
  export declare function getLegendMarkerOptions(chart: MdtChartsTwoDimensionalChart): ChartLegendModel;
7
7
  export declare function getWidthOfLegendMarkerByType(chartType: TwoDimensionalChartType): number;
8
+ export declare function getAreaViewOptions(chart: MdtChartsTwoDimensionalChart, chartIndex: number, style: ChartStyle): AreaChartViewOptions;
9
+ export declare function getGradientId(chartIndex: number, subIndex: number): GradientId;
@@ -48,3 +48,23 @@ export function getWidthOfLegendMarkerByType(chartType) {
48
48
  if (chartType === "area")
49
49
  return styledElementValues.defaultLegendMarkerSizes.widthPx;
50
50
  }
51
+ export function getAreaViewOptions(chart, chartIndex, style) {
52
+ var _a, _b, _c, _d, _e;
53
+ let gradientIds = [];
54
+ for (let index = 0; index < style.elementColors.length; index++) {
55
+ gradientIds.push(getGradientId(chartIndex, index));
56
+ }
57
+ const fill = ((_b = (_a = chart.areaStyles) === null || _a === void 0 ? void 0 : _a.gradient) === null || _b === void 0 ? void 0 : _b.on) ? { type: "gradient", ids: gradientIds }
58
+ : { type: "paletteColor" };
59
+ const borderLine = {
60
+ on: (_e = (_d = (_c = chart.areaStyles) === null || _c === void 0 ? void 0 : _c.borderLine) === null || _d === void 0 ? void 0 : _d.on) !== null && _e !== void 0 ? _e : false,
61
+ colorStyle: {
62
+ elementColors: style.elementColors,
63
+ opacity: 1
64
+ }
65
+ };
66
+ return { fill, borderLine };
67
+ }
68
+ export function getGradientId(chartIndex, subIndex) {
69
+ return `gradient-chart-${chartIndex}-sub-${subIndex}`;
70
+ }
@@ -3,7 +3,7 @@ import { TwoDimensionalChartStyleModel } from "../chartStyleModel/twoDimensional
3
3
  import { AxisModel } from "../featuresModel/axisModel";
4
4
  import { ScaleAxisRecalcer } from "../featuresModel/scaleModel/scaleAxisRecalcer";
5
5
  import { ScaleModel } from "../featuresModel/scaleModel/scaleModel";
6
- import { getLegendMarkerOptions, parseDashStyles, parseShape } from "./twoDimensional/styles";
6
+ import { getAreaViewOptions, getLegendMarkerOptions, parseDashStyles, parseShape } from "./twoDimensional/styles";
7
7
  import { getResolvedTitle } from "../../model/featuresModel/titleModel";
8
8
  import { calculateValueLabelAlignment, getValueLabelX, getValueLabelY } from "../../model/featuresModel/valueLabelsModel/valueLabelsModel";
9
9
  import { TwoDimensionalModelHelper } from "../helpers/twoDimensionalModelHelper";
@@ -23,6 +23,7 @@ export class TwoDimensionalModel {
23
23
  secondaryScaleValueInfo = secondaryScaleMarginRecalcer.getScaleValue();
24
24
  }
25
25
  const keyAxis = AxisModel.getKeyAxis(options, modelInstance.dataModel.repository.getScopedFullSource(), designerConfig.canvas.axisLabel, canvasModel, designerConfig.elementsOptions.tooltip, () => scaleValueInfo.scaleFn(0));
26
+ const charts = this.getChartsModel(options.charts, configReader, options.orientation, designerConfig, modelInstance.dataModel.repository, keyAxis.orient, canvasModel, options.data.keyField.name);
26
27
  return {
27
28
  legend: canvasModel.legendCanvas.getModel(),
28
29
  title: getResolvedTitle(options.title, modelInstance.dataModel.repository.getRawRows()),
@@ -32,11 +33,14 @@ export class TwoDimensionalModel {
32
33
  axis: Object.assign({ key: keyAxis, value: AxisModel.getMainValueAxis(options.orientation, options.axis.value.position, options.axis.value, designerConfig.canvas.axisLabel, canvasModel) }, (configReader.containsSecondaryAxis() && { valueSecondary: AxisModel.getSecondaryValueAxis(options.orientation, options.axis.value.position, options.axis.valueSecondary, designerConfig.canvas.axisLabel, canvasModel) })),
33
34
  type: options.type,
34
35
  data: Object.assign({}, options.data),
35
- charts: this.getChartsModel(options.charts, configReader, options.orientation, designerConfig, modelInstance.dataModel.repository, keyAxis.orient, canvasModel, options.data.keyField.name),
36
+ charts,
36
37
  additionalElements: this.getAdditionalElements(options),
37
38
  tooltip: options.tooltip,
38
39
  chartSettings: this.getChartsSettings(designerConfig.canvas.chartOptions, options.orientation),
39
- valueLabels: (_a = options.valueLabels) !== null && _a !== void 0 ? _a : { collision: { mode: "none" } }
40
+ valueLabels: (_a = options.valueLabels) !== null && _a !== void 0 ? _a : { collision: { mode: "none" } },
41
+ defs: {
42
+ gradients: TwoDimensionalModelHelper.getGradientDefs(charts, keyAxis.orient, options.orientation)
43
+ }
40
44
  };
41
45
  }
42
46
  static getChartsEmbeddedLabelsFlag(charts, chartOrientation) {
@@ -67,7 +71,8 @@ export class TwoDimensionalModel {
67
71
  const chartsModel = [];
68
72
  charts.forEach((chart, index) => {
69
73
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
70
- chartsModel.push(Object.assign({ type: chart.type, isSegmented: chart.isSegmented, data: Object.assign({}, chart.data), tooltip: chart.tooltip, cssClasses: ChartStyleModelService.getCssClasses(index), style: styleModel.getChartStyle(chart, index), embeddedLabels: this.getEmbeddedLabelType(chart, chartOrientation), markersOptions: {
74
+ const style = styleModel.getChartStyle(chart, index);
75
+ chartsModel.push(Object.assign(Object.assign({ type: chart.type, isSegmented: chart.isSegmented, data: Object.assign({}, chart.data), tooltip: chart.tooltip, cssClasses: ChartStyleModelService.getCssClasses(index), style, embeddedLabels: this.getEmbeddedLabelType(chart, chartOrientation), markersOptions: {
71
76
  show: ({ row, valueFieldName }) => TwoDimensionalModelHelper.shouldMarkerShow(chart, dataModelRep.getRawRows(), valueFieldName, row, keyFieldName),
72
77
  styles: {
73
78
  highlighted: {
@@ -92,7 +97,7 @@ export class TwoDimensionalModel {
92
97
  dominantBaseline: calculateValueLabelAlignment(keyAxisOrient).dominantBaseline,
93
98
  format: configReader.getValueLabelFormatterForChart(index),
94
99
  }
95
- })));
100
+ })), { areaViewOptions: getAreaViewOptions(chart, index, style) }));
96
101
  });
97
102
  return chartsModel;
98
103
  }
@@ -1,4 +1,6 @@
1
- @import './css-vars.css';
1
+ :root {
2
+ --chart-base-font-size: 13px;
3
+ }
2
4
 
3
5
  .wrapper {
4
6
  margin: 0 auto;
@@ -11,6 +13,12 @@
11
13
  fill: none;
12
14
  stroke-width: 4;
13
15
  }
16
+
17
+ .area-border-line {
18
+ fill: none;
19
+ stroke-width: 2;
20
+ }
21
+
14
22
  .donut-block * {
15
23
  transition: filter 0.15s;
16
24
  }
@@ -157,7 +165,7 @@
157
165
  border-radius: 50%;
158
166
  }
159
167
  .tooltip-text-item {
160
- font-family: "Roboto" sans-serif;
168
+ font-family: "Roboto", sans-serif;
161
169
  font-style: normal;
162
170
  width: 100%;
163
171
  flex: 1;
@@ -276,3 +284,10 @@
276
284
  width: 100%;
277
285
  height: 100%;
278
286
  }
287
+
288
+ /* Value Labels */
289
+ .mdt-charts-value-label {
290
+ opacity: 0.5;
291
+ font-size: 10px;
292
+ letter-spacing: -0.4px;
293
+ }
@@ -1,4 +1,6 @@
1
- @import (inline) './css-vars.css';
1
+ :root {
2
+ --chart-base-font-size: 13px;
3
+ }
2
4
 
3
5
  .wrapper {
4
6
  margin: 0 auto;
@@ -11,6 +13,12 @@
11
13
  fill: none;
12
14
  stroke-width: 4;
13
15
  }
16
+
17
+ .area-border-line {
18
+ fill: none;
19
+ stroke-width: 2;
20
+ }
21
+
14
22
  .donut-block * {
15
23
  transition: filter 0.15s;
16
24
  }
@@ -157,7 +165,7 @@
157
165
  border-radius: 50%;
158
166
  }
159
167
  .tooltip-text-item {
160
- font-family: "Roboto" sans-serif;
168
+ font-family: "Roboto", sans-serif;
161
169
  font-style: normal;
162
170
  width: 100%;
163
171
  flex: 1;
@@ -276,3 +284,10 @@
276
284
  width: 100%;
277
285
  height: 100%;
278
286
  }
287
+
288
+ /* Value Labels */
289
+ .mdt-charts-value-label {
290
+ opacity: 0.5;
291
+ font-size: 10px;
292
+ letter-spacing: -0.4px;
293
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.20.1",
3
+ "version": "1.21.1",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {
@@ -10,7 +10,7 @@
10
10
  "test": "jest",
11
11
  "build-lib": "shx rm -rf lib && npm run build-ts && npm run build-style",
12
12
  "build-ts": "npx tsc -p tsconfig.production.json",
13
- "build-style": "shx mkdir lib/style && shx cp src/style/css-vars.css lib/style && shx cp src/style/charts-main.css lib/style && shx cp src/style/charts-main.less lib/style"
13
+ "build-style": "shx mkdir lib/style && shx cp src/style/charts-main.css lib/style && shx cp src/style/charts-main.css lib/style/charts-main.less"
14
14
  },
15
15
  "homepage": "https://github.com/VishulaKnow/charts",
16
16
  "author": "",
@@ -1,3 +0,0 @@
1
- :root {
2
- --chart-base-font-size: 13px;
3
- }