mdt-charts 1.12.20 → 1.13.0

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.
@@ -71,6 +71,7 @@ export interface MdtChartsCardsOptions extends BasicOptions {
71
71
  title: string;
72
72
  description?: string;
73
73
  icon?: MdtChartsIconElement;
74
+ color?: MdtChartsColorRangeItem[];
74
75
  value: MdtChartsCardValue;
75
76
  change?: MdtChartsCardsChange;
76
77
  }
@@ -18,6 +18,7 @@ export declare class CardChart {
18
18
  updateData(options: CardsOptionsModel, data: MdtChartsDataSource): void;
19
19
  private renderCardWrapper;
20
20
  private renderContentBlock;
21
+ private setContentColor;
21
22
  private setContentFontSize;
22
23
  private renderHeaderBlock;
23
24
  private appendTitle;
@@ -13,7 +13,7 @@ export class CardChart {
13
13
  const parent = block.html.getBlock();
14
14
  const dataRow = data[options.data.dataSource][0];
15
15
  const wrapper = this.renderCardWrapper(parent);
16
- this.renderContentBlock(wrapper);
16
+ this.renderContentBlock(wrapper, options.color);
17
17
  this.setContentFontSize(this.cardContentElement, canvasOptions);
18
18
  this.renderHeaderBlock(this.cardContentElement, {
19
19
  title: options.title,
@@ -32,15 +32,20 @@ export class CardChart {
32
32
  const dataRow = data[options.data.dataSource][0];
33
33
  this.setValueContent(CardService.getValueContentFromDataSource(Object.assign(Object.assign({}, options.value), { dataSetName: options.data.dataSource }), data));
34
34
  this.updateValueBlockStyle();
35
+ this.setContentColor(options.color);
35
36
  (_a = this.changeBlock) === null || _a === void 0 ? void 0 : _a.update(options.change, dataRow);
36
37
  }
37
38
  renderCardWrapper(parent) {
38
39
  return parent.append("div")
39
40
  .classed(this.cardContentBlockCssClass, true);
40
41
  }
41
- renderContentBlock(wrapper) {
42
+ renderContentBlock(wrapper, color) {
42
43
  this.cardContentElement = wrapper.append("div")
43
44
  .classed(NamesHelper.getClassName("card-content"), true);
45
+ this.setContentColor(color);
46
+ }
47
+ setContentColor(color) {
48
+ this.cardContentElement.style("color", color);
44
49
  }
45
50
  setContentFontSize(contentBlock, canvasOptions) {
46
51
  const fontSize = Math.floor(Math.min(canvasOptions.cardSize.height, canvasOptions.cardSize.width) / 10);
@@ -49,14 +54,15 @@ export class CardChart {
49
54
  renderHeaderBlock(contentBlock, options) {
50
55
  const header = contentBlock.append("div")
51
56
  .classed(NamesHelper.getClassName("card-header"), true);
52
- this.appendTitle(header, options.title);
53
57
  if (options.icon)
54
58
  this.appendIcon(header, options.icon);
59
+ this.appendTitle(header, options.title);
55
60
  }
56
61
  appendTitle(headerBlock, textContent) {
57
62
  headerBlock.append("h3")
58
63
  .classed(NamesHelper.getClassName("card-title"), true)
59
- .text(textContent);
64
+ .text(textContent)
65
+ .attr("title", textContent);
60
66
  }
61
67
  appendIcon(headerBlock, icon) {
62
68
  const iconEl = icon();
@@ -70,7 +76,8 @@ export class CardChart {
70
76
  .classed(NamesHelper.getClassName("card-description-wrapper"), true);
71
77
  wrapper.append("p")
72
78
  .classed(NamesHelper.getClassName("card-description"), true)
73
- .text(textContent);
79
+ .text(textContent)
80
+ .attr("title", textContent);
74
81
  }
75
82
  renderValueBlock(contentBlock, value) {
76
83
  const wrapper = contentBlock.append("div")
@@ -36,11 +36,14 @@ export class CardChange {
36
36
  this.renderIcon(this.renderContentItem(contentBlock), options.icon);
37
37
  this.renderValue(this.renderContentItem(contentBlock), CardService.getValueContentFromRow(options.value, dataRow));
38
38
  if (options.description)
39
- this.renderDescription(this.renderContentItem(contentBlock), options.description);
39
+ this.renderDescription(this.renderContentItem(contentBlock, NamesHelper.getClassName("card-change-description-item")), options.description);
40
40
  }
41
- renderContentItem(contentBlock) {
42
- return contentBlock.append("div")
41
+ renderContentItem(contentBlock, cssClass) {
42
+ const item = contentBlock.append("div")
43
43
  .classed(NamesHelper.getClassName("card-change-content-item"), true);
44
+ if (cssClass)
45
+ item.classed(cssClass, true);
46
+ return item;
44
47
  }
45
48
  renderIcon(parentBlock, icon) {
46
49
  this.iconBlock = parentBlock.append("div")
@@ -64,7 +67,8 @@ export class CardChange {
64
67
  .classed(NamesHelper.getClassName("card-change-description-wrapper"), true)
65
68
  .append("span")
66
69
  .classed(NamesHelper.getClassName("card-change-description"), true)
67
- .text(textContent);
70
+ .text(textContent)
71
+ .attr("title", textContent);
68
72
  }
69
73
  setValueContent(textContent) {
70
74
  this.valueContentBlock.text(textContent);
@@ -71,6 +71,7 @@ export interface CardsOptionsModel extends BasicOptionsModel {
71
71
  description?: string;
72
72
  icon?: MdtChartsIconElement;
73
73
  value: MdtChartsCardValue;
74
+ color: MdtChartsColorName;
74
75
  change?: CardsChangeModel;
75
76
  }
76
77
  export interface ILegendModel {
@@ -1,7 +1,5 @@
1
- import { MdtChartsCardOptionByValue, MdtChartsCardsChange, MdtChartsColorName, MdtChartsColorRangeItem, MdtChartsDataRow } from "../../../config/config";
1
+ import { MdtChartsCardsChange, MdtChartsDataRow } from "../../../config/config";
2
2
  import { CardsChangeModel } from "../../model";
3
- export declare const DEFAULT_CARD_CHANGE_COLOR: MdtChartsCardOptionByValue<MdtChartsColorName>;
4
- export declare const DEFAULT_CARD_CHANGE_RANGE: MdtChartsColorRangeItem[];
5
3
  export declare class CardsChangeService {
6
4
  getChangeModel(dataRow: MdtChartsDataRow, changeOptions: MdtChartsCardsChange): CardsChangeModel;
7
5
  private getColor;
@@ -1,22 +1,5 @@
1
1
  import { ColorRangeManager } from "../../chartStyleModel/colorRange";
2
- export const DEFAULT_CARD_CHANGE_COLOR = {
3
- aboveZero: "#20b078",
4
- equalZero: "#000",
5
- belowZero: "#ff3131"
6
- };
7
- export const DEFAULT_CARD_CHANGE_RANGE = [
8
- {
9
- color: DEFAULT_CARD_CHANGE_COLOR.belowZero
10
- },
11
- {
12
- color: DEFAULT_CARD_CHANGE_COLOR.equalZero,
13
- value: 0
14
- },
15
- {
16
- color: DEFAULT_CARD_CHANGE_COLOR.aboveZero,
17
- value: 0
18
- }
19
- ];
2
+ import { DEFAULT_CARD_CHANGE_RANGE } from "./cardsModelService";
20
3
  export class CardsChangeService {
21
4
  getChangeModel(dataRow, changeOptions) {
22
5
  var _a;
@@ -11,6 +11,7 @@ export class CardsModel {
11
11
  data: options.data,
12
12
  tooltip: options.tooltip,
13
13
  icon: options.icon,
14
+ color: this.service.getCardColor(options, modelInstance),
14
15
  value: Object.assign({}, options.value),
15
16
  change: this.service.getCardsChangeModel(options, modelInstance)
16
17
  };
@@ -1,6 +1,11 @@
1
- import { MdtChartsCardsOptions } from "../../../config/config";
1
+ import { MdtChartsCardOptionByValue, MdtChartsCardsOptions, MdtChartsColorName, MdtChartsColorRangeItem } from "../../../config/config";
2
2
  import { ModelInstance } from "../../modelInstance/modelInstance";
3
+ export declare const DEFAULT_CARD_COLOR: MdtChartsColorName;
4
+ export declare const DEFAULT_CARD_CHANGE_COLOR: MdtChartsCardOptionByValue<MdtChartsColorName>;
5
+ export declare const DEFAULT_CARD_CHANGE_RANGE: MdtChartsColorRangeItem[];
3
6
  export declare class CardsModelService {
4
7
  private changeService;
8
+ getCardColor(options: MdtChartsCardsOptions, modelInstance: ModelInstance): MdtChartsColorName;
5
9
  getCardsChangeModel(options: MdtChartsCardsOptions, modelInstance: ModelInstance): import("../../model").CardsChangeModel;
6
10
  }
11
+ export declare function getCardColor(value: number | string, colorRange: MdtChartsColorRangeItem[]): string;
@@ -1,10 +1,41 @@
1
+ import { ColorRangeManager } from "../../chartStyleModel/colorRange";
1
2
  import { CardsChangeService } from "./cardsChangeService";
3
+ export const DEFAULT_CARD_COLOR = "#000";
4
+ export const DEFAULT_CARD_CHANGE_COLOR = {
5
+ aboveZero: "#20b078",
6
+ equalZero: DEFAULT_CARD_COLOR,
7
+ belowZero: "#ff3131"
8
+ };
9
+ export const DEFAULT_CARD_CHANGE_RANGE = [
10
+ {
11
+ color: DEFAULT_CARD_CHANGE_COLOR.belowZero
12
+ },
13
+ {
14
+ color: DEFAULT_CARD_CHANGE_COLOR.equalZero,
15
+ value: 0
16
+ },
17
+ {
18
+ color: DEFAULT_CARD_CHANGE_COLOR.aboveZero,
19
+ value: 0
20
+ }
21
+ ];
2
22
  export class CardsModelService {
3
23
  constructor() {
4
24
  this.changeService = new CardsChangeService();
5
25
  }
26
+ getCardColor(options, modelInstance) {
27
+ const data = modelInstance.dataModel.repository.getFirstRow();
28
+ const value = data[options.value.field];
29
+ return getCardColor(value, options.color);
30
+ }
6
31
  getCardsChangeModel(options, modelInstance) {
7
32
  const data = modelInstance.dataModel.repository.getFirstRow();
8
33
  return this.changeService.getChangeModel(data, options.change);
9
34
  }
10
35
  }
36
+ export function getCardColor(value, colorRange) {
37
+ if (typeof value === "string" || !(colorRange === null || colorRange === void 0 ? void 0 : colorRange.length))
38
+ return DEFAULT_CARD_COLOR;
39
+ const rangeManager = new ColorRangeManager(colorRange);
40
+ return rangeManager.getColorByValue(value);
41
+ }
@@ -290,11 +290,14 @@
290
290
 
291
291
  .mdt-charts-card-header {
292
292
  display: flex;
293
- justify-content: space-between;
294
293
  flex: 1;
295
294
  font-size: 1.3em;
296
295
  }
297
296
 
297
+ .mdt-charts-card-icon {
298
+ margin-right: 0.3em;
299
+ }
300
+
298
301
  .mdt-charts-card-title {
299
302
  margin: 0;
300
303
  white-space: nowrap;
@@ -333,4 +336,14 @@
333
336
  white-space: nowrap;
334
337
  overflow: hidden;
335
338
  text-overflow: ellipsis;
339
+ }
340
+
341
+ .mdt-charts-card-change-description-item {
342
+ overflow: hidden;
343
+ }
344
+
345
+ .mdt-charts-card-change-description {
346
+ display: block;
347
+ overflow: hidden;
348
+ text-overflow: ellipsis;
336
349
  }
@@ -290,11 +290,14 @@
290
290
 
291
291
  .mdt-charts-card-header {
292
292
  display: flex;
293
- justify-content: space-between;
294
293
  flex: 1;
295
294
  font-size: 1.3em;
296
295
  }
297
296
 
297
+ .mdt-charts-card-icon {
298
+ margin-right: 0.3em;
299
+ }
300
+
298
301
  .mdt-charts-card-title {
299
302
  margin: 0;
300
303
  white-space: nowrap;
@@ -333,4 +336,14 @@
333
336
  white-space: nowrap;
334
337
  overflow: hidden;
335
338
  text-overflow: ellipsis;
339
+ }
340
+
341
+ .mdt-charts-card-change-description-item {
342
+ overflow: hidden;
343
+ }
344
+
345
+ .mdt-charts-card-change-description {
346
+ display: block;
347
+ overflow: hidden;
348
+ text-overflow: ellipsis;
336
349
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdt-charts",
3
- "version": "1.12.20",
3
+ "version": "1.13.0",
4
4
  "description": "",
5
5
  "main": "lib/main.js",
6
6
  "scripts": {