Skip to content

Commit 6e56218

Browse files
author
Lan Le
committed
feat WIP: handle display tic spectra
1 parent d48c361 commit 6e56218

File tree

6 files changed

+349
-16
lines changed

6 files changed

+349
-16
lines changed

src/__tests__/units/helpers/calc.test.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { almostEqual, calcSlope } from '../../../helpers/calc';
1+
import { almostEqual, calcSlope, findClosest } from '../../../helpers/calc';
22

33
describe('Test calculation helpers', () => {
44
describe('Test almostEqual function', () => {
@@ -39,4 +39,20 @@ describe('Test calculation helpers', () => {
3939
expect(output).toEqual(3);
4040
});
4141
});
42+
43+
describe('Test findClosest function', () => {
44+
it('Get closest number from array of interger', () => {
45+
const arr = [ 1, 2, 4, 5, 6, 6, 8, 9 ];
46+
const target = 2.7;
47+
const output = findClosest(arr, target)
48+
expect(output).toEqual(2);
49+
});
50+
51+
it('Get closest number from array of float', () => {
52+
const arr = [ 1.0, 1.5, 1.9 ];
53+
const target = 1.2;
54+
const output = findClosest(arr, target)
55+
expect(output).toEqual(1.0);
56+
});
57+
});
4258
});

src/components/d3_line_rect/index.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import {
1010
import { resetAll } from '../../actions/manager';
1111
import { selectUiSweep, scrollUiWheel, clickUiTarget } from '../../actions/ui';
1212
// import RectFocus from './rect_focus';
13-
import LineFocus from './line_focus';
13+
// import LineFocus from './line_focus';
1414
import RectFocus from './rect_focus';
15+
import MultiFocus from './multi_focus';
16+
import { extractParams } from '../../helpers/extractParams';
17+
import { findClosest } from '../../helpers/calc';
1518
import {
1619
drawMain, drawLabel, drawDisplay, drawDestroy,
1720
} from '../common/draw';
@@ -24,10 +27,15 @@ class ViewerLineRect extends React.Component {
2427
constructor(props) {
2528
super(props);
2629

27-
const { clickUiTargetAct, selectUiSweepAct, scrollUiWheelAct } = props;
30+
const {
31+
clickUiTargetAct, selectUiSweepAct, scrollUiWheelAct, entities,
32+
} = props;
2833
this.rootKlassLine = '.d3Line';
29-
this.lineFocus = new LineFocus({
30-
W, H, clickUiTargetAct, selectUiSweepAct, scrollUiWheelAct,
34+
// this.lineFocus = new LineFocus({
35+
// W, H, clickUiTargetAct, selectUiSweepAct, scrollUiWheelAct,
36+
// });
37+
this.lineFocus = new MultiFocus({
38+
W, H, entities, clickUiTargetAct, selectUiSweepAct, scrollUiWheelAct,
3139
});
3240

3341
this.rootKlassRect = '.d3Rect';
@@ -41,7 +49,7 @@ class ViewerLineRect extends React.Component {
4149

4250
componentDidMount() {
4351
const {
44-
seed, cLabel, xLabel, yLabel, feature,
52+
entities, curveSt, seed, cLabel, xLabel, yLabel, feature,
4553
tTrEndPts, layoutSt,
4654
sweepExtentSt, isUiAddIntgSt, isUiNoBrushSt,
4755
isHidden, sweepExtentSubViewSt,
@@ -54,6 +62,8 @@ class ViewerLineRect extends React.Component {
5462

5563
drawMain(this.rootKlassLine, W, H);
5664
this.lineFocus.create({
65+
entities,
66+
curveSt,
5767
filterSeed,
5868
tTrEndPts,
5969
layoutSt,
@@ -78,7 +88,7 @@ class ViewerLineRect extends React.Component {
7888

7989
componentDidUpdate(prevProps) {
8090
const {
81-
seed, cLabel, xLabel, yLabel,
91+
entities, curveSt, seed, cLabel, xLabel, yLabel,
8292
tTrEndPts, layoutSt,
8393
sweepExtentSt, isUiAddIntgSt, isUiNoBrushSt,
8494
isHidden, sweepExtentSubViewSt,
@@ -88,6 +98,8 @@ class ViewerLineRect extends React.Component {
8898
const filterSeed = seed;
8999

90100
this.lineFocus.update({
101+
entities,
102+
curveSt,
91103
filterSeed,
92104
tTrEndPts,
93105
layoutSt,
@@ -132,13 +144,19 @@ class ViewerLineRect extends React.Component {
132144
}
133145

134146
extractSubView() {
135-
const { uiSt, features } = this.props;
147+
const { uiSt, subEntities } = this.props;
136148
const { subViewerAt } = uiSt;
137149
let selectFeature = null;
150+
138151
if (subViewerAt && subViewerAt.x) {
152+
const {
153+
features,
154+
} = extractParams(subEntities[0], 0, 1);
155+
const arrPageValues = features.map((fe) => fe.pageValue);
156+
const closestPage = findClosest(arrPageValues, subViewerAt.x);
139157
const filteredFeatures = features.filter((fe) => {
140158
const { pageValue } = fe;
141-
return pageValue === subViewerAt.x;
159+
return pageValue === closestPage;
142160
});
143161
[selectFeature] = filteredFeatures;
144162
}
@@ -161,6 +179,7 @@ class ViewerLineRect extends React.Component {
161179

162180
const mapStateToProps = (state, props) => (
163181
{
182+
curveSt: state.curve,
164183
seed: Topic2Seed(state, props),
165184
tTrEndPts: ToThresEndPts(state, props),
166185
sweepExtentSt: state.ui.sweepExtent,
@@ -181,13 +200,16 @@ const mapDispatchToProps = (dispatch) => (
181200
);
182201

183202
ViewerLineRect.propTypes = {
203+
uiSt: PropTypes.object.isRequired,
204+
curveSt: PropTypes.object.isRequired,
205+
entities: PropTypes.array.isRequired,
206+
subEntities: PropTypes.array.isRequired,
184207
seed: PropTypes.array.isRequired,
185208
cLabel: PropTypes.string.isRequired,
186209
xLabel: PropTypes.string.isRequired,
187210
yLabel: PropTypes.string.isRequired,
188211
layoutSt: PropTypes.string.isRequired,
189212
feature: PropTypes.object.isRequired,
190-
features: PropTypes.array.isRequired,
191213
tTrEndPts: PropTypes.array.isRequired,
192214
sweepExtentSt: PropTypes.object.isRequired,
193215
sweepExtentSubViewSt: PropTypes.object.isRequired,
@@ -198,7 +220,6 @@ ViewerLineRect.propTypes = {
198220
selectUiSweepAct: PropTypes.func.isRequired,
199221
scrollUiWheelAct: PropTypes.func.isRequired,
200222
isHidden: PropTypes.bool.isRequired,
201-
uiSt: PropTypes.object.isRequired,
202223
};
203224

204225
export default connect(mapStateToProps, mapDispatchToProps)(ViewerLineRect);

0 commit comments

Comments
 (0)