sea-chart 0.0.13 → 0.0.14

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.
@@ -0,0 +1,64 @@
1
+ .sea-chart-color-picker .color-select-container {
2
+ display: block;
3
+ width: 100%;
4
+ height: 2.375rem;
5
+ color: #495057;
6
+ background-color: #fff;
7
+ background-clip: padding-box;
8
+ border: 1px solid rgba(0, 40, 100, 0.12);
9
+ border-radius: 3px;
10
+ transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
11
+ }
12
+
13
+ .sea-chart-color-picker .color-picker-container {
14
+ display: block;
15
+ width: 100%;
16
+ height: 2.375rem;
17
+ line-height: 2.375rem;
18
+ color: #495057;
19
+ background-color: #fff;
20
+ background-clip: padding-box;
21
+ border: 1px solid rgba(0, 40, 100, 0.12);
22
+ border-radius: 3px;
23
+ transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
24
+ position: relative;
25
+ }
26
+
27
+ .sea-chart-color-picker .color-picker-container .picker-control {
28
+ height: 100%;
29
+ display: flex;
30
+ align-items: center;
31
+ }
32
+
33
+ .sea-chart-color-picker .picker-control .color-control {
34
+ width: 24px;
35
+ height: 24px;
36
+ margin-left: 10px;
37
+ border-radius: 4px;
38
+ cursor: pointer;
39
+ }
40
+
41
+ .sea-chart-color-picker .color-picker-container .picker-control.readOnly,
42
+ .sea-chart-color-picker .color-picker-container .picker-control.readOnly .text-control {
43
+ background-color: #f7f7f7;
44
+ }
45
+
46
+ .sea-chart-color-picker .picker-control .color-control {
47
+ cursor: default;
48
+ }
49
+
50
+ .sea-chart-color-picker .picker-control .color-control.white-color {
51
+ border: 3px #eee solid;
52
+ }
53
+
54
+ .sea-chart-color-picker .picker-control .text-control {
55
+ height: 100%;
56
+ border: none;
57
+ outline: none;
58
+ padding-left: 10px;
59
+ font-size: 14px;
60
+ }
61
+
62
+ .sea-chart-color-picker .color-picker-container .picker-control.readOnly .text-control {
63
+ cursor: default;
64
+ }
@@ -0,0 +1,109 @@
1
+ import React from 'react';
2
+ import { ChromePicker } from 'react-color';
3
+ import './index.css';
4
+ const COVER = {
5
+ top: '0px',
6
+ right: '0px',
7
+ bottom: '0px',
8
+ left: '0px'
9
+ };
10
+ class ColorPicker extends React.PureComponent {
11
+ constructor(props) {
12
+ super(props);
13
+ this.onInputChanged = event => {
14
+ const value = event.target.value;
15
+ if (value === this.state.activeColor) return;
16
+ this.updateColor(value);
17
+ this.setState({
18
+ activeColor: value
19
+ });
20
+ };
21
+ this.onPickColorToggle = () => {
22
+ this.setState({
23
+ isShowColorPicker: !this.state.isShowColorPicker
24
+ });
25
+ };
26
+ this.onPickChanged = color => {
27
+ if (color.hex === this.state.activeColor) return;
28
+ this.updateColor(color.hex);
29
+ this.setState({
30
+ activeColor: color.hex
31
+ });
32
+ };
33
+ this.updateColor = color => {
34
+ this.props.onColorChanged(color);
35
+ };
36
+ this.getPopoverStyle = () => {
37
+ if (!this.colorPickerContainerRef) return {};
38
+ const {
39
+ top,
40
+ height
41
+ } = this.colorPickerContainerRef.getBoundingClientRect();
42
+ const {
43
+ clientHeight
44
+ } = document.body;
45
+ const selectTop = top + height;
46
+ if (clientHeight - selectTop < 247) {
47
+ // 247: ChromePicker's height
48
+ return {
49
+ position: 'absolute',
50
+ left: 0,
51
+ bottom: '2.375rem',
52
+ zIndex: '2'
53
+ };
54
+ }
55
+ return {
56
+ position: 'absolute',
57
+ left: 0,
58
+ zIndex: '2'
59
+ };
60
+ };
61
+ this.state = {
62
+ isShowColorPicker: false,
63
+ activeColor: props.activeColor
64
+ };
65
+ this.colorPickerContainerRef = null;
66
+ }
67
+ UNSAFE_componentWillReceiveProps(nextProps) {
68
+ this.setState({
69
+ activeColor: nextProps.activeColor
70
+ });
71
+ }
72
+ render() {
73
+ const {
74
+ activeColor
75
+ } = this.state;
76
+ const isWhiteColor = activeColor && activeColor.toUpperCase() === '#FFFFFF';
77
+ return /*#__PURE__*/React.createElement("div", {
78
+ className: "color-picker-container",
79
+ ref: ref => this.colorPickerContainerRef = ref
80
+ }, /*#__PURE__*/React.createElement("div", {
81
+ className: "picker-control"
82
+ }, /*#__PURE__*/React.createElement("div", {
83
+ className: "color-control ".concat(isWhiteColor ? 'white-color' : ''),
84
+ onClick: this.onPickColorToggle,
85
+ style: {
86
+ background: activeColor
87
+ }
88
+ }), /*#__PURE__*/React.createElement("input", {
89
+ className: "text-control",
90
+ type: "text",
91
+ value: activeColor,
92
+ onChange: this.onInputChanged
93
+ })), this.state.isShowColorPicker && /*#__PURE__*/React.createElement("div", {
94
+ style: this.getPopoverStyle()
95
+ }, /*#__PURE__*/React.createElement("div", {
96
+ className: "position-fixed",
97
+ style: COVER,
98
+ onClick: this.onPickColorToggle
99
+ }), /*#__PURE__*/React.createElement(ChromePicker, {
100
+ disableAlpha: true,
101
+ color: activeColor,
102
+ onChange: this.onPickChanged
103
+ })));
104
+ }
105
+ }
106
+ ColorPicker.defaultProps = {
107
+ activeColor: '#000000'
108
+ };
109
+ export default ColorPicker;
@@ -184,6 +184,7 @@ export const MIRROR_COLUMN_LIST = [CellType.TEXT, CellType.NUMBER, CellType.CTIM
184
184
  export const CHART_SUPPORT_FONT_WEIGHTS = [400, 700];
185
185
  export const DEFAULT_CHART_FONT_WEIGHT = CHART_SUPPORT_FONT_WEIGHTS[1];
186
186
  export const DEFAULT_CHART_TITLE_FONT_SIZE = 24;
187
+ export const DEFAULT_CHART_TITLE_FONT_COLOR = '#212529';
187
188
  export const CHART_SETTINGS_TYPE = {
188
189
  DATA: 'data',
189
190
  CHART_STYLE: 'style',
@@ -90,6 +90,7 @@ const en = {
90
90
  '1 Filter': '1 filter',
91
91
  'Filters': 'filters',
92
92
  'Font_size': 'Font size',
93
+ 'Font_color': 'Font color',
93
94
  'Font_weight': 'Font weight',
94
95
  'Chart_type': 'Chart type',
95
96
  "Histogram": "Histogram",
@@ -90,6 +90,7 @@ const zh_CN = {
90
90
  "1 Filter": "1 个过滤条件",
91
91
  "Filters": "个过滤条件",
92
92
  "Font_size": "字体大小",
93
+ 'Font_color': '字体颜色',
93
94
  "Font_weight": "字体粗细",
94
95
  'Chart_type': '图表类型',
95
96
  "Histogram": "柱状图",
@@ -0,0 +1,27 @@
1
+ import React, { useMemo } from 'react';
2
+ import classnames from 'classnames';
3
+ import { FormGroup, Label } from 'reactstrap';
4
+ import ColorPicker from '../../../components/color-picker';
5
+ import intl from '../../../intl';
6
+ const FontColorSettings = _ref => {
7
+ let {
8
+ fontColor,
9
+ defaultFontColor,
10
+ modifyFontColor,
11
+ className,
12
+ title
13
+ } = _ref;
14
+ const initialFontColor = useMemo(() => {
15
+ if (fontColor) return fontColor;
16
+ return defaultFontColor;
17
+ }, [defaultFontColor, fontColor]);
18
+ return /*#__PURE__*/React.createElement(FormGroup, {
19
+ className: classnames('sea-chart-setting-item', className)
20
+ }, /*#__PURE__*/React.createElement(Label, null, title || intl.get('Font_color')), /*#__PURE__*/React.createElement("div", {
21
+ className: "sea-chart-color-picker"
22
+ }, /*#__PURE__*/React.createElement(ColorPicker, {
23
+ activeColor: initialFontColor,
24
+ onColorChanged: modifyFontColor
25
+ })));
26
+ };
27
+ export default FontColorSettings;
@@ -1,3 +1,4 @@
1
1
  import FontSizeSettings from './font-size-settings';
2
2
  import FontWeightSettings from './font-weight-settings';
3
- export { FontSizeSettings, FontWeightSettings };
3
+ import FontColorSettings from './font-color-settings';
4
+ export { FontSizeSettings, FontWeightSettings, FontColorSettings };
@@ -1,8 +1,8 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import TitleText from './title-text';
3
- import { FontSizeSettings, FontWeightSettings } from '../font-settings';
3
+ import { FontSizeSettings, FontWeightSettings, FontColorSettings } from '../font-settings';
4
4
  import TextHorizontalSettings from '../text-horizontal-settings';
5
- import { DEFAULT_CHART_FONT_WEIGHT, DEFAULT_CHART_TITLE_FONT_SIZE, CHART_SUPPORT_FONT_WEIGHTS, HORIZONTAL_ALIGN } from '../../../constants';
5
+ import { DEFAULT_CHART_FONT_WEIGHT, DEFAULT_CHART_TITLE_FONT_SIZE, CHART_SUPPORT_FONT_WEIGHTS, HORIZONTAL_ALIGN, DEFAULT_CHART_TITLE_FONT_COLOR } from '../../../constants';
6
6
  const TitleSetting = props => {
7
7
  const initialTitle = useMemo(() => {
8
8
  return props.title || {};
@@ -40,6 +40,11 @@ const TitleSetting = props => {
40
40
  font_weight: updatedFontWeight
41
41
  });
42
42
  };
43
+ const modifyFontColor = updatedFontColor => {
44
+ modifyTitle({
45
+ font_color: updatedFontColor
46
+ });
47
+ };
43
48
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TitleText, {
44
49
  text: initialTitle.text,
45
50
  modifyText: modifyText
@@ -51,6 +56,10 @@ const TitleSetting = props => {
51
56
  fontWeight: initialTitle.font_weight || DEFAULT_CHART_FONT_WEIGHT,
52
57
  supportFontWeights: CHART_SUPPORT_FONT_WEIGHTS,
53
58
  modifyFontWeight: modifyFontWeight
59
+ }), /*#__PURE__*/React.createElement(FontColorSettings, {
60
+ fontColor: initialTitle.font_color,
61
+ defaultFontColor: DEFAULT_CHART_TITLE_FONT_COLOR,
62
+ modifyFontColor: modifyFontColor
54
63
  }), /*#__PURE__*/React.createElement(TextHorizontalSettings, {
55
64
  value: initialTitle.horizontal_align,
56
65
  defaultValue: HORIZONTAL_ALIGN.LEFT,
@@ -19,6 +19,7 @@ const Title = _ref => {
19
19
  const {
20
20
  font_size,
21
21
  font_weight,
22
+ font_color,
22
23
  horizontal_align
23
24
  } = chart.style_config.title;
24
25
  if (isNumber(font_size)) {
@@ -27,6 +28,9 @@ const Title = _ref => {
27
28
  if (CHART_SUPPORT_FONT_WEIGHTS.includes(font_weight)) {
28
29
  style.fontWeight = font_weight;
29
30
  }
31
+ if (font_color) {
32
+ style.color = font_color;
33
+ }
30
34
  style.textAlign = horizontal_align && HORIZONTAL_ALIGNS.includes(horizontal_align) ? horizontal_align : HORIZONTAL_ALIGN.LEFT;
31
35
  return style;
32
36
  }, [chart]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",