@readr-media/react-election-widgets
Version:
1,156 lines (970 loc) • 36.5 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ReferendumDataManager = exports.RecallDataManager = exports.PresidentDataManager = exports.LegislatorPartyDataManager = exports.LegislatorIndigenousDataManager = exports.LegislatorDataManager = exports.DataManager = exports.CountyMayorDataManager = exports.CouncilMemberDataManager = void 0;
exports.dataManagerFactory = dataManagerFactory;
var _react = _interopRequireWildcard(require("react"));
var _breakpoint = _interopRequireDefault(require("./breakpoint"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _icons = require("./icons");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
/**
* @typedef {import('./typedef').Election} Election
* @typedef {import('./typedef').CouncilMemberElection} CouncilMemberElection
* @typedef {import('./typedef').ReferendumElection} ReferendumElection
* @typedef {import('./typedef').LegislatorPartyElection} LegislatorPartyElection
* @typedef {import('./typedef').LegislatorIndigenousElection} LegislatorIndigenousElection
* @typedef {import('./typedef').PresidentElection} PresidentElection
* @typedef {import('./typedef').Proposition} Proposition
* @typedef {import('./typedef').Candidate} Candidate
* @typedef {import('./typedef').Entity} Entity
* @typedef {import('./typedef').District} District
* @typedef {import('./typedef').LegislatorParty} LegislatorParty
* @typedef {import('./typedef').PresidentCandidate} PresidentCandidate
*/
/**
* @typedef {string} Head
*
* @typedef {Object} CellEntity
* @property {string} [label]
* @property {string} [href]
* @property {React.ReactElement} [imgJsx]
* @property {boolean} [multiLines=false]
*
* @typedef {CellEntity[]} Cell - Table cell. A cell contains multiple entities
*
* @typedef {Object} Row
* @property {string} id
* @property {Cell[]} cells
* @property {string} [group]
*/
const ImgBlock = _styledComponents.default.div.withConfig({
displayName: "manager__ImgBlock",
componentId: "sc-qjzdbt-0"
})(["margin-right:8px;display:flex;align-items:center;justify-content:center;img,svg{width:32px;height:32px;object-fit:cover;border-radius:50%;overflow:hidden;}", ""], props => {
var _props$theme;
switch ((_props$theme = props.theme) === null || _props$theme === void 0 ? void 0 : _props$theme.device) {
case 'mobile':
{
return `
${_breakpoint.default.devices.laptop} {
img, svg {
width: 32px;
height: 32px;
}
}
`;
}
case 'rwd':
default:
{
return `
${_breakpoint.default.devices.laptop} {
img, svg {
width: 40px;
height: 40px;
}
}
`;
}
}
});
let DataManager = /*#__PURE__*/function () {
/**
* @param {Object} data
*/
function DataManager(data) {
_classCallCheck(this, DataManager);
this.data = data;
this.rows = [];
this.head = [];
}
/**
* @return {Object} data
*/
_createClass(DataManager, [{
key: "getData",
value: function getData() {
return this.data;
}
/**
* @returns {Head[]}
*/
}, {
key: "buildListHead",
value: function buildListHead() {
console.warn('Method `buildListHead` needs to be implemented.');
return this.head;
}
/**
* @returns {Row[]}
*/
}, {
key: "buildListRows",
value: function buildListRows() {
console.warn('Method `buildListRows` needs to be implemented.');
return this.rows;
}
/**
* @param {Entity[]} entities
* @returns {CellEntity[]}
*/
}, {
key: "buildNameCell",
value: function buildNameCell(entities) {
return entities === null || entities === void 0 ? void 0 : entities.map(entity => {
return {
label: entity === null || entity === void 0 ? void 0 : entity.label,
href: entity === null || entity === void 0 ? void 0 : entity.href,
imgJsx: /*#__PURE__*/(0, _jsxRuntime.jsx)(CandidateImg, {
imgSrc: entity === null || entity === void 0 ? void 0 : entity.imgSrc
})
};
});
}
/**
* @param {Entity[]} entities
* @returns {CellEntity[]}
*/
}, {
key: "buildPartyCell",
value: function buildPartyCell(entities) {
return entities === null || entities === void 0 ? void 0 : entities.map(entity => {
return {
label: (entity === null || entity === void 0 ? void 0 : entity.label) || '無',
href: entity === null || entity === void 0 ? void 0 : entity.href,
imgJsx: entity !== null && entity !== void 0 && entity.imgSrc ? /*#__PURE__*/(0, _jsxRuntime.jsx)(ImgBlock, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
src: entity.imgSrc
})
}) : null
};
});
}
/**
* @param {string} id
* @returns {Row}
*/
// eslint-disable-next-line no-unused-vars
}, {
key: "getRowById",
value: function getRowById(id) {
console.warn('Method `getRowById` needs to be implemented.');
return {
id: '',
cells: [],
group: ''
};
}
/**
* @param {string} dn
* @returns {Row}
*/
// eslint-disable-next-line no-unused-vars
}, {
key: "findRowByDistrictName",
value: function findRowByDistrictName(dn) {
console.warn('Method `findRowByValue` needs to be implemented.');
return {
id: '',
cells: [],
group: ''
};
}
/**
* @param {string} dn
* @returns {string}
*/
}, {
key: "genFullDistrictName",
value: function genFullDistrictName(dn) {
return dn;
}
}]);
return DataManager;
}();
exports.DataManager = DataManager;
function CandidateImg({
imgSrc
}) {
const [errored, setErrored] = (0, _react.useState)(false);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(ImgBlock, {
children: imgSrc && !errored ? /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
src: imgSrc,
onError: () => setErrored(true)
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.AnonymousIcon, {})
});
}
let CouncilMemberDataManager = /*#__PURE__*/function (_DataManager) {
_inherits(CouncilMemberDataManager, _DataManager);
var _super = _createSuper(CouncilMemberDataManager);
function CouncilMemberDataManager() {
_classCallCheck(this, CouncilMemberDataManager);
return _super.apply(this, arguments);
}
_createClass(CouncilMemberDataManager, [{
key: "buildListHead",
value:
/**
* @override
* @returns {Head[]}
*/
function buildListHead() {
// built already, therefore return the built one
if (this.head.length > 0) {
return this.head;
}
this.head = ['地區', '號次', '姓名', '推薦政黨', '得票數', '得票率', '當選'];
return this.head;
}
/**
* @param {Candidate} c
* @returns {Cell[]}
*/
}, {
key: "buildRowFromCandidate",
value: function buildRowFromCandidate(c) {
var _c$tks, _c$votes;
const tksRate = (c === null || c === void 0 ? void 0 : c.tksRate) ?? (c === null || c === void 0 ? void 0 : c.voteRate);
return [// 號次
[{
label: `${(c === null || c === void 0 ? void 0 : c.candNo) ?? (c === null || c === void 0 ? void 0 : c.number) ?? '-'}`
}], // 姓名
this.buildNameCell([c === null || c === void 0 ? void 0 : c.name]), // 政黨
this.buildPartyCell([c === null || c === void 0 ? void 0 : c.party]), // 得票數
[{
label: (c === null || c === void 0 ? void 0 : (_c$tks = c.tks) === null || _c$tks === void 0 ? void 0 : _c$tks.toLocaleString()) ?? (c === null || c === void 0 ? void 0 : (_c$votes = c.votes) === null || _c$votes === void 0 ? void 0 : _c$votes.toLocaleString()) ?? '-'
}], // 得票率
[{
label: typeof tksRate === 'number' ? `${tksRate}%` : '-'
}], // 當選
[{
imgJsx: c !== null && c !== void 0 && c.candVictor || c !== null && c !== void 0 && c.elected ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.ElectedIcon, {}) : null
}]];
}
/**
* @override
*/
}, {
key: "genFullDistrictName",
value: function genFullDistrictName(dn) {
return `第${dn}選區`;
}
/**
* @override
* @returns {Row[]}
*/
}, {
key: "buildListRows",
value: function buildListRows() {
var _this$data, _this$data$districts;
// built already, therefore return the built one
if (this.rows.length > 0) {
return this.rows;
}
(_this$data = this.data) === null || _this$data === void 0 ? void 0 : (_this$data$districts = _this$data.districts) === null || _this$data$districts === void 0 ? void 0 : _this$data$districts.forEach(d => {
var _d$candidates;
d === null || d === void 0 ? void 0 : (_d$candidates = d.candidates) === null || _d$candidates === void 0 ? void 0 : _d$candidates.forEach((c, cIdx) => {
/** @type {Row} */
const row = {
id: '',
cells: [],
group: ''
}; // `districtName` 為 (1)下拉選單內容 (2)「地區」欄內容 (3)scrollTo 對應的 id 資訊
/** @type {string} */
let districtName = d.fullDistrictName || this.genFullDistrictName(d.districtName) || '';
row.id = `${districtName}-${cIdx}`; // data for `data-row-id`
row.group = districtName; //「地區」欄-內容小標(除了 cIdx[0] 外的都不顯示小標)
/** @type {string} */
let areaLabel = '';
if (cIdx === 0) {
areaLabel = districtName;
}
row.cells = this.buildRowFromCandidate(c);
row.cells.unshift([{
label: areaLabel
}]);
this.rows.push(row);
});
});
return this.rows;
}
/**
* @override
* @param {string} districtName
* @returns {Row}
*/
}, {
key: "findRowByDistrictName",
value: function findRowByDistrictName(districtName = '第01選區') {
return this.rows.find(r => {
return r.group === districtName;
});
}
}]);
return CouncilMemberDataManager;
}(DataManager);
exports.CouncilMemberDataManager = CouncilMemberDataManager;
let CountyMayorDataManager = /*#__PURE__*/function (_CouncilMemberDataMan) {
_inherits(CountyMayorDataManager, _CouncilMemberDataMan);
var _super2 = _createSuper(CountyMayorDataManager);
function CountyMayorDataManager() {
_classCallCheck(this, CountyMayorDataManager);
return _super2.apply(this, arguments);
}
_createClass(CountyMayorDataManager, [{
key: "genFullDistrictName",
value:
/**
* @override
*/
function genFullDistrictName(dn) {
return dn;
}
}]);
return CountyMayorDataManager;
}(CouncilMemberDataManager);
exports.CountyMayorDataManager = CountyMayorDataManager;
let LegislatorDataManager = /*#__PURE__*/function (_CouncilMemberDataMan2) {
_inherits(LegislatorDataManager, _CouncilMemberDataMan2);
var _super3 = _createSuper(LegislatorDataManager);
function LegislatorDataManager() {
_classCallCheck(this, LegislatorDataManager);
return _super3.apply(this, arguments);
}
return _createClass(LegislatorDataManager);
}(CouncilMemberDataManager);
exports.LegislatorDataManager = LegislatorDataManager;
let RecallDataManager = /*#__PURE__*/function (_LegislatorDataManage) {
_inherits(RecallDataManager, _LegislatorDataManage);
var _super4 = _createSuper(RecallDataManager);
function RecallDataManager(data) {
var _this;
_classCallCheck(this, RecallDataManager);
_this = _super4.call(this, data);
_this.buildListHead();
_this.buildListRows();
return _this;
}
/**
* @override
* @returns {Head[]}
*/
_createClass(RecallDataManager, [{
key: "buildListHead",
value: function buildListHead() {
if (this.head.length > 0) return this.head;
this.head = ['地區', '姓名', '政黨', '同意票數', '不同意票數', '選區人數同意率', '選區人數不同意率', '是否通過'];
return this.head;
}
/**
* @override
* @param {Candidate & {agreeTks: number, disagreeTks: number, agreeRate: number, disagreeRate: number}} candidate
* @returns {Cell[]}
*/
}, {
key: "buildRowFromCandidates",
value: function buildRowFromCandidates(candidate) {
var _candidate$agreeTks, _candidate$disagreeTk;
/**
*
* @param {string} adptVictor - is the candidate pass or not
* @returns {string}
*/
const isPassed = adptVictor => {
switch (adptVictor) {
case 'Y':
return '通過';
case 'N':
return '不通過';
default:
'';
}
}; // This method creates all cells except for the 'district' one.
return [// 姓名
this.buildNameCell([candidate === null || candidate === void 0 ? void 0 : candidate.name]), // 政黨
this.buildPartyCell([candidate === null || candidate === void 0 ? void 0 : candidate.party]), // 同意數
[{
label: (candidate === null || candidate === void 0 ? void 0 : (_candidate$agreeTks = candidate.agreeTks) === null || _candidate$agreeTks === void 0 ? void 0 : _candidate$agreeTks.toLocaleString()) ?? '-'
}], // 不同意數
[{
label: (candidate === null || candidate === void 0 ? void 0 : (_candidate$disagreeTk = candidate.disagreeTks) === null || _candidate$disagreeTk === void 0 ? void 0 : _candidate$disagreeTk.toLocaleString()) ?? '-'
}], // 同意率
[{
label: typeof (candidate === null || candidate === void 0 ? void 0 : candidate.ytpRate) === 'number' ? `${candidate === null || candidate === void 0 ? void 0 : candidate.ytpRate}%` : '-'
}], // 不同意率
[{
label: typeof (candidate === null || candidate === void 0 ? void 0 : candidate.ntpRate) === 'number' ? `${candidate === null || candidate === void 0 ? void 0 : candidate.ntpRate}%` : '-'
}], // 是否通過
[{
label: isPassed((candidate === null || candidate === void 0 ? void 0 : candidate.adptVictor) ?? '')
}]];
}
/**
* @override
* @returns {Row[]}
*/
}, {
key: "buildListRows",
value: function buildListRows() {
if (this.rows && this.rows.length > 0) {
return this.rows;
}
const newRows = [];
const districts = this.data.districts || [];
for (const district of districts) {
for (const [cIdx, candidate] of district.candidates.entries()) {
const row = {
id: `${district.districtName}-${candidate.name.label}`,
group: district.districtName,
cells: this.buildRowFromCandidates(candidate)
};
const areaLabel = cIdx === 0 ? district.districtName : '';
row.cells.unshift([{
label: areaLabel
}]);
newRows.push(row);
}
}
this.rows = newRows;
return this.rows;
}
}]);
return RecallDataManager;
}(LegislatorDataManager);
exports.RecallDataManager = RecallDataManager;
let LegislatorPartyDataManager = /*#__PURE__*/function (_DataManager2) {
_inherits(LegislatorPartyDataManager, _DataManager2);
var _super5 = _createSuper(LegislatorPartyDataManager);
/**
* @override
* @param {LegislatorPartyElection} data
*/
function LegislatorPartyDataManager(data) {
var _this2;
_classCallCheck(this, LegislatorPartyDataManager);
_this2 = _super5.call(this, data);
_this2.districts = [{
districtName: '全國'
}];
return _this2;
}
/**
* @return {LegislatorPartyElection & { districts: {districtName: string}[] }} data
*/
_createClass(LegislatorPartyDataManager, [{
key: "getData",
value: function getData() {
return { ...this.data,
districts: [{
districtName: '全國'
}]
};
}
/**
* @override
* @returns {Head[]}
*/
}, {
key: "buildListHead",
value: function buildListHead() {
// built already, therefore return the built one
if (this.head.length > 0) {
return this.head;
}
this.head = ['地區', '號次', '政黨', '得票數', '得票率', '當選席次'];
return this.head;
}
/**
* @param {LegislatorParty} p
* @returns {Cell[]}
*/
}, {
key: "buildRowFromParty",
value: function buildRowFromParty(p) {
var _p$tks, _p$seats;
return [// 號次
[{
label: `${(p === null || p === void 0 ? void 0 : p.candNo) ?? '-'}`
}], // 政黨
this.buildPartyCell([p === null || p === void 0 ? void 0 : p.party]), // 得票數
[{
label: (p === null || p === void 0 ? void 0 : (_p$tks = p.tks) === null || _p$tks === void 0 ? void 0 : _p$tks.toLocaleString()) ?? '-'
}], // 得票率
[{
label: typeof (p === null || p === void 0 ? void 0 : p.tksRate1) === 'number' ? `${p === null || p === void 0 ? void 0 : p.tksRate1}%` : '-'
}], // 當選席次
[{
label: (p === null || p === void 0 ? void 0 : (_p$seats = p.seats) === null || _p$seats === void 0 ? void 0 : _p$seats.toLocaleString()) ?? '-'
}]];
}
/**
* @override
* @returns {Row[]}
*/
}, {
key: "buildListRows",
value: function buildListRows() {
var _this$data2, _this$data2$parties;
// built already, therefore return the built one
if (this.rows.length > 0) {
return this.rows;
}
this.rows = (_this$data2 = this.data) === null || _this$data2 === void 0 ? void 0 : (_this$data2$parties = _this$data2.parties) === null || _this$data2$parties === void 0 ? void 0 : _this$data2$parties.map((p, idx) => {
/** @type {Row} */
const row = {
id: '',
cells: []
};
let districtName = '全國';
row.id = p.candNo;
row.group = districtName;
row.cells = this.buildRowFromParty(p);
if (idx !== 0) {
districtName = '';
}
row.cells.unshift([{
label: districtName
}]);
return row;
});
return this.rows;
}
/**
* @override
* @param {string} districtName
* @returns {Row}
*/
}, {
key: "findRowByDistrictName",
value: function findRowByDistrictName(districtName = '全國') {
return this.rows.find(r => {
return r.group === districtName;
});
}
}]);
return LegislatorPartyDataManager;
}(DataManager);
exports.LegislatorPartyDataManager = LegislatorPartyDataManager;
let LegislatorIndigenousDataManager = /*#__PURE__*/function (_DataManager3) {
_inherits(LegislatorIndigenousDataManager, _DataManager3);
var _super6 = _createSuper(LegislatorIndigenousDataManager);
/**
* @override
* @param {LegislatorIndigenousElection} data
*/
function LegislatorIndigenousDataManager(data) {
var _this3;
_classCallCheck(this, LegislatorIndigenousDataManager);
_this3 = _super6.call(this, data);
if (data.type === 'legislator-mountainIndigenous') {
_this3.districts = [{
districtName: '全國 (山地)'
}];
} else if (data.type === 'legislator-plainIndigenous') {
_this3.districts = [{
districtName: '全國 (平地)'
}];
} else {
_this3.districts = [{
districtName: '全國'
}];
}
return _this3;
}
/**
* @return {LegislatorIndigenousElection & { districts: {districtName: string}[] }} data
*/
_createClass(LegislatorIndigenousDataManager, [{
key: "getData",
value: function getData() {
let defaultDistrictName = '全國';
if (this.data.type === 'legislator-mountainIndigenous') {
defaultDistrictName = '全國 (山地)';
} else if (this.data.type === 'legislator-plainIndigenous') {
defaultDistrictName = '全國 (平地)';
}
return { ...this.data,
districts: [{
districtName: defaultDistrictName || '全國'
}]
};
}
/**
* @override
* @returns {Head[]}
*/
}, {
key: "buildListHead",
value: function buildListHead() {
// built already, therefore return the built one
if (this.head.length > 0) {
return this.head;
}
this.head = ['地區', '號次', '姓名', '推薦政黨', '得票數', '得票率', '當選'];
return this.head;
}
/**
* @param {LegislatorCandidate} c
* @returns {Cell[]}
*/
}, {
key: "buildRowFromCandidates",
value: function buildRowFromCandidates(c) {
var _c$tks2;
return [// 號次
[{
label: `${(c === null || c === void 0 ? void 0 : c.candNo) ?? '-'}`
}], // 姓名
this.buildNameCell([c === null || c === void 0 ? void 0 : c.name]), // 政黨
this.buildPartyCell([c === null || c === void 0 ? void 0 : c.party]), // 得票數
[{
label: (c === null || c === void 0 ? void 0 : (_c$tks2 = c.tks) === null || _c$tks2 === void 0 ? void 0 : _c$tks2.toLocaleString()) ?? '-'
}], // 得票率
[{
label: typeof (c === null || c === void 0 ? void 0 : c.tksRate) === 'number' ? `${c === null || c === void 0 ? void 0 : c.tksRate}%` : '-'
}], // 當選
[{
imgJsx: c !== null && c !== void 0 && c.candVictor ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.ElectedIcon, {}) : null
}]];
}
/**
* @override
* @returns {Row[]}
*/
}, {
key: "buildListRows",
value: function buildListRows() {
var _data$candidates;
// built already, therefore return the built one
if (this.rows.length > 0) {
return this.rows;
}
this.rows = [];
/** @type {LegislatorIndigenousElection} */
const data = this.data;
data === null || data === void 0 ? void 0 : (_data$candidates = data.candidates) === null || _data$candidates === void 0 ? void 0 : _data$candidates.forEach((c, cIdx) => {
/** @type {Row} */
const row = {
id: '',
cells: [],
group: ''
};
let districtName = '';
row.group = districtName;
row.id = c.candNo;
if (cIdx === 0) {
var _this$districts, _this$districts$;
districtName = (_this$districts = this.districts) === null || _this$districts === void 0 ? void 0 : (_this$districts$ = _this$districts[0]) === null || _this$districts$ === void 0 ? void 0 : _this$districts$.districtName;
}
row.cells = this.buildRowFromCandidates(c);
row.cells.unshift([{
label: districtName
}]);
this.rows.push(row);
});
return this.rows;
}
/**
* @override
* @param {string} districtName
* @returns {Row}
*/
}, {
key: "findRowByDistrictName",
value: function findRowByDistrictName(districtName = '全國') {
return this.rows.find(r => {
return r.group === districtName;
});
}
}]);
return LegislatorIndigenousDataManager;
}(DataManager);
exports.LegislatorIndigenousDataManager = LegislatorIndigenousDataManager;
let ReferendumDataManager = /*#__PURE__*/function (_DataManager4) {
_inherits(ReferendumDataManager, _DataManager4);
var _super7 = _createSuper(ReferendumDataManager);
/**
* @override
* @param {ReferendumElection} data
*/
function ReferendumDataManager(data) {
var _this4;
_classCallCheck(this, ReferendumDataManager);
_this4 = _super7.call(this, data);
_this4.districts = [{
districtName: '全國'
}];
return _this4;
}
/**
* @return {ReferendumElection & { districts: {districtName: string}[] }} data
*/
_createClass(ReferendumDataManager, [{
key: "getData",
value: function getData() {
return { ...this.data,
districts: [{
districtName: '全國'
}]
};
}
/**
* @override
* @returns {Head[]}
*/
}, {
key: "buildListHead",
value: function buildListHead() {
// built already, therefore return the built one
if (this.head.length > 0) {
return this.head;
}
this.head = ['案號', '案名', '領銜人', '同意數', '同意率', '不同意數', '不同意率', '通過註記'];
return this.head;
}
/**
* @param {Proposition} p
* @returns {Cell[]}
*/
}, {
key: "buildRowFromPropostion",
value: function buildRowFromPropostion(p) {
var _p$agreeTks, _p$agreeRate, _p$disagreeTks, _p$disagreeRate;
return [// 案號
[{
label: `${(p === null || p === void 0 ? void 0 : p.no) ?? '-'}`
}], // 案名
[{
label: `${(p === null || p === void 0 ? void 0 : p.content) ?? '-'}`,
multiLines: true
}], // 領銜人
[{
label: `${(p === null || p === void 0 ? void 0 : p.planner) ?? '-'}`
}], // 同意數
[{
label: (p === null || p === void 0 ? void 0 : (_p$agreeTks = p.agreeTks) === null || _p$agreeTks === void 0 ? void 0 : _p$agreeTks.toLocaleString()) ?? '-'
}], // 同意率
[{
label: (p === null || p === void 0 ? void 0 : (_p$agreeRate = p.agreeRate) === null || _p$agreeRate === void 0 ? void 0 : _p$agreeRate.toLocaleString()) ?? '-'
}], // 不同意數
[{
label: (p === null || p === void 0 ? void 0 : (_p$disagreeTks = p.disagreeTks) === null || _p$disagreeTks === void 0 ? void 0 : _p$disagreeTks.toLocaleString()) ?? '-'
}], // 不同意率
[{
label: (p === null || p === void 0 ? void 0 : (_p$disagreeRate = p.disagreeRate) === null || _p$disagreeRate === void 0 ? void 0 : _p$disagreeRate.toLocaleString()) ?? '-'
}], // 當選
[{
label: p !== null && p !== void 0 && p.pass ? '是' : '否'
}]];
}
/**
* @override
* @returns {Row[]}
*/
}, {
key: "buildListRows",
value: function buildListRows() {
var _this$data3, _this$data3$propositi;
// built already, therefore return the built one
if (this.rows.length > 0) {
return this.rows;
}
this.rows = (_this$data3 = this.data) === null || _this$data3 === void 0 ? void 0 : (_this$data3$propositi = _this$data3.propositions) === null || _this$data3$propositi === void 0 ? void 0 : _this$data3$propositi.map(p => {
/** @type {Row} */
const row = {
id: '',
cells: []
};
row.id = p.no;
row.group = '全國';
row.cells = this.buildRowFromPropostion(p);
return row;
});
return this.rows;
}
/**
* @override
* @param {string} districtName
* @returns {Row}
*/
}, {
key: "findRowByDistrictName",
value: function findRowByDistrictName(districtName = '全國') {
return this.rows.find(r => {
return r.group === districtName;
});
}
}]);
return ReferendumDataManager;
}(DataManager);
exports.ReferendumDataManager = ReferendumDataManager;
let PresidentDataManager = /*#__PURE__*/function (_DataManager5) {
_inherits(PresidentDataManager, _DataManager5);
var _super8 = _createSuper(PresidentDataManager);
/**
* @override
* @param {PresidentElection} data
*/
function PresidentDataManager(data) {
var _this5;
_classCallCheck(this, PresidentDataManager);
_this5 = _super8.call(this, data);
_this5.districts = [{
districtName: '全國'
}];
return _this5;
}
/**
* @return {PresidentElection & { districts: {districtName: string}[] }} data
*/
_createClass(PresidentDataManager, [{
key: "getData",
value: function getData() {
return { ...this.data,
districts: [{
districtName: '全國'
}]
};
}
/**
* @override
* @returns {Head[]}
*/
}, {
key: "buildListHead",
value: function buildListHead() {
// built already, therefore return the built one
if (this.head.length > 0) {
return this.head;
}
this.head = ['地區', '號次', '姓名', '推薦政黨', '得票數', '得票率', '當選'];
return this.head;
}
/**
* @param {PresidentCandidate} c
* @returns {Cell[]}
*/
}, {
key: "buildRowFromCandidates",
value: function buildRowFromCandidates(c) {
var _c$tks3;
return [// 號次
[{
label: `${(c === null || c === void 0 ? void 0 : c.candNo) ?? '-'}`
}], // 姓名
this.buildNameCell(c.names), // 政黨
this.buildPartyCell(c.parties).map(entity => Object.assign(entity, {
multiLines: true
})), // 得票數
[{
label: (c === null || c === void 0 ? void 0 : (_c$tks3 = c.tks) === null || _c$tks3 === void 0 ? void 0 : _c$tks3.toLocaleString()) ?? '-'
}], // 得票率
[{
label: typeof (c === null || c === void 0 ? void 0 : c.tksRate) === 'number' ? `${c === null || c === void 0 ? void 0 : c.tksRate}%` : '-'
}], // 當選
[{
imgJsx: c !== null && c !== void 0 && c.candVictor ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.ElectedIcon, {}) : null
}]];
}
/**
* @override
* @returns {Row[]}
*/
}, {
key: "buildListRows",
value: function buildListRows() {
var _data$candidates2;
// built already, therefore return the built one
if (this.rows.length > 0) {
return this.rows;
}
this.rows = [];
/** @type {PresidentElection} */
const data = this.data;
data === null || data === void 0 ? void 0 : (_data$candidates2 = data.candidates) === null || _data$candidates2 === void 0 ? void 0 : _data$candidates2.forEach((c, cIdx) => {
/** @type {Row} */
const row = {
id: '',
cells: [],
group: ''
};
let districtName = '';
row.group = districtName;
row.id = c.candNo;
if (cIdx === 0) {
var _this$districts2, _this$districts2$;
districtName = (_this$districts2 = this.districts) === null || _this$districts2 === void 0 ? void 0 : (_this$districts2$ = _this$districts2[0]) === null || _this$districts2$ === void 0 ? void 0 : _this$districts2$.districtName;
}
row.cells = this.buildRowFromCandidates(c);
row.cells.unshift([{
label: districtName
}]);
this.rows.push(row);
});
return this.rows;
}
/**
* @override
* @param {string} districtName
* @returns {Row}
*/
}, {
key: "findRowByDistrictName",
value: function findRowByDistrictName(districtName = '全國') {
return this.rows.find(r => {
return r.group === districtName;
});
}
}]);
return PresidentDataManager;
}(DataManager);
exports.PresidentDataManager = PresidentDataManager;
function dataManagerFactory() {
return {
/**
* @param {Election | ReferendumElection | LegislatorPartyElection | PresidentElection |LegislatorIndigenousElection } data
* @returns {DataManager}
*/
newDataManager: data => {
switch (data === null || data === void 0 ? void 0 : data.type) {
case 'mayor':
return new CountyMayorDataManager(data);
case 'councilMember':
return new CouncilMemberDataManager(data);
case 'legislator':
case 'legislator-district':
return new LegislatorDataManager(data);
case 'legislator-plainIndigenous':
case 'legislator-mountainIndigenous':
return new LegislatorIndigenousDataManager(data);
case 'legislator-party':
return new LegislatorPartyDataManager(data);
case 'referendum':
return new ReferendumDataManager(data);
case 'president':
return new PresidentDataManager(data);
case 'legislator-recall':
return new RecallDataManager(data);
default:
{
return new DataManager(data);
}
}
}
};
}