Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed layout of counter widget #2804

Merged
merged 3 commits into from
Apr 10, 2018
Merged
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
2 changes: 1 addition & 1 deletion web/client/components/layout/BorderLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = ({id, children, header, footer, columns, height, className}) =>
display: "flex",
flex: 1,
overflowY: "auto"
}}>
}}>
<main className="ms2-border-layout-content" style={{flex: 1}}>
{height ? <div style={{height}}>{children}</div> : children}
</main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ const enhancePreview = compose(
);

const sampleProps = {
width: 430,
height: 200
style: {
width: 450,
height: 100
}
};

const Wizard = wizardHandlers(require('../../../misc/wizard/WizardContainer'));
Expand Down
27 changes: 18 additions & 9 deletions web/client/components/widgets/widget/CounterView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@ const enhanceCounter = compose(
emptyChartState
);
const React = require('react');
module.exports = enhanceCounter(({ width = "100%", height="100%", series = [], data = [], options={}, style} = {}) => {
const renderCounter = ({ dataKey } = {}, i) => (<Counter
key={dataKey}
uom={get(options, `seriesOptions[${i}].uom`)}
value={data[0][dataKey]}
style={{ width, height, textAlign: "center", ...style }}
/>);
return series.length === 1 ? renderCounter(series[0], 0) : <div className="counter">{series.map(renderCounter)}</div>;
});
module.exports = enhanceCounter(({ series = [], data = [], options = {}, style = {
width: "100%",
height: "100%",
transform: "translate(-50%, -50%)",
position: "absolute",
display: "inline",
padding: "1%",
top: "50%",
left: "50%"
}} ) => {
const renderCounter = ({ dataKey } = {}, i) => (<Counter
key={dataKey}
uom={get(options, `seriesOptions[${i}].uom`)}
value={data[0][dataKey]}
style={{ textAlign: "center", ...style }}
/>);
return (<div className="counter-widget-view">{series.map(renderCounter)}</div>);
});
6 changes: 3 additions & 3 deletions web/client/components/widgets/widget/CounterWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
const React = require('react');
const Message = require('../../I18N/Message');

const CounterView = require('./CounterView');
const InfoPopover = require('./InfoPopover');
const WidgetContainer = require('./WidgetContainer');
Expand All @@ -33,8 +34,6 @@ module.exports = ({
series = [],
loading,
showTable,
width,
height,
confirmDelete= false,
headerStyle,
toggleTableView= () => {},
Expand All @@ -43,6 +42,7 @@ module.exports = ({
onDelete=() => {},
...props}) =>
(<WidgetContainer
className="counter-widget"
id={`widget-chart-${id}`}
title={title}
topLeftItems={renderHeaderLeftTopItem({loading, title, description, showTable, toggleTableView})}
Expand All @@ -57,5 +57,5 @@ module.exports = ({
<MenuItem onClick={() => toggleDeleteConfirm(true)} eventKey="2"><Glyphicon glyph="trash"/>&nbsp;<Message msgId="widgets.widget.menu.delete" /></MenuItem>
</DropdownButton>
</ButtonToolbar>}>
<CounterView id={id} style={{ width: "80%", height: "80%", margin: "0 auto"}} containerSize={{ width, height }} isAnimationActive={!loading} loading={loading} data={data} series={series} iconFit {...props} />
<CounterView id={id} isAnimationActive={!loading} loading={loading} data={data} series={series} iconFit {...props} />
</WidgetContainer>);
3 changes: 2 additions & 1 deletion web/client/components/widgets/widget/WidgetContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = ({
id,
title,
confirmDelete= false,
className,
handle = "draggableHandle",
toggleDeleteConfirm = () => {},
onDelete=() => {},
Expand All @@ -23,7 +24,7 @@ module.exports = ({
children
}) =>
(<div className="mapstore-widget-card" id={id}>
<BorderLayout header={(<div style={headerStyle} className={`mapstore-widget-info ${handle ? handle : ""}`}>
<BorderLayout className={className} header={(<div style={headerStyle} className={`mapstore-widget-info ${handle ? handle : ""}`}>
<div className="mapstore-widget-header">
{topLeftItems}
<span className="widget-title">{title}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,19 @@ describe('CounterView component', () => {
const container = document.getElementById('container');
expect(container.querySelector('.glyphicon-warning-sign')).toExist();
});
it('CounterView rendering style', () => {
ReactDOM.render(<CounterView data={[{ dataKey: 1 }]} series={[{ dataKey: "dataKey" }]} />, document.getElementById("container"));
const container = document.getElementById('container');
const el = container.querySelector('.counter-widget-view');
expect(el).toExist();
const content = el.querySelector('div');
expect(content.style.width).toBe("100%");
expect(content.style.height).toBe("100%");
expect(content.style.transform).toExist();
expect(content.style.top).toBe('50%');
expect(content.style.left).toBe('50%');
ReactDOM.render(<CounterView data={[{ dataKey: 1 }]} style={{top: "10px"}} series={[{ dataKey: "dataKey" }]} />, document.getElementById("container"));
const content2 = container.querySelector('.counter-widget-view div');
expect(content2.style.top).toBe('10px');
});
});
11 changes: 11 additions & 0 deletions web/client/themes/default/less/widget.less
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@
overflow-x: hidden;
overflow-y: auto;
}

.counter-widget-view > div > div {
transform: translate(-50%, -50%);
position: absolute;
top: 38%;
left: 50%;
}
.counter-widget .ms2-border-layout-body {
position: relative;
}

}
}

Expand Down