Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
c3-closed
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Evgeny
c3-closed
Commits
8f1d1c1c
Commit
8f1d1c1c
authored
Jan 08, 2014
by
Masayuki Tanaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable custom x
parent
beb7aeef
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
5 deletions
+56
-5
c3.js
c3.js
+33
-5
c3.min.js
c3.min.js
+0
-0
custom_x_scale.html
htdocs/samples/custom_x_scale.html
+23
-0
No files found.
c3.js
View file @
8f1d1c1c
...
...
@@ -45,7 +45,7 @@
// data - data configuration
checkConfig
(
'data'
,
'data is required in config'
);
var
__data_x
=
getConfig
([
'data'
,
'x'
],
'x'
),
var
__data_x
=
getConfig
([
'data'
,
'x'
],
undefined
),
__data_x_format
=
getConfig
([
'data'
,
'x_format'
],
'%Y-%m-%d'
),
__data_id_converter
=
getConfig
([
'data'
,
'id_converter'
],
function
(
id
)
{
return
id
;
}),
__data_names
=
getConfig
([
'data'
,
'names'
],
{}),
...
...
@@ -148,7 +148,8 @@
clipPath
=
"url(#"
+
clipId
+
")"
;
var
isTimeSeries
=
(
__axis_x_type
===
'timeseries'
),
isCategorized
=
(
__axis_x_type
===
'categorized'
);
isCategorized
=
(
__axis_x_type
===
'categorized'
),
isCustomX
=
!
isTimeSeries
&&
__data_x
;
var
dragStart
=
null
,
dragging
=
false
,
cancelClick
=
false
;
...
...
@@ -447,13 +448,23 @@
var
ids
=
d3
.
keys
(
data
[
0
]).
filter
(
function
(
key
)
{
return
key
!==
__data_x
;
});
var
targets
,
i
=
0
,
parsedDate
;
// check __data_x is defined if timeseries
if
(
isTimeSeries
&&
!
__data_x
)
{
alert
(
'data.x must be specified when axis.x.type == "timeseries"'
);
return
[];
}
data
.
forEach
(
function
(
d
)
{
if
(
isTimeSeries
)
{
if
(
!
(
__data_x
in
d
))
{
throw
Error
(
"'"
+
__data_x
+
"' must be included in data"
);
}
parsedDate
=
parseDate
(
d
[
__data_x
]);
if
(
parsedDate
===
null
)
{
throw
Error
(
"Failed to parse timeseries date in data"
);
}
d
.
x
=
parsedDate
;
}
else
{
}
else
if
(
isCustomX
)
{
d
.
x
=
d
[
__data_x
];
}
else
{
d
.
x
=
i
++
;
}
if
(
firstDate
===
null
)
{
firstDate
=
new
Date
(
d
.
x
);
}
...
...
@@ -487,6 +498,12 @@
})
};
}
function
getPrevX
(
i
)
{
return
i
>
0
?
c3
.
data
.
targets
[
0
].
values
[
i
-
1
].
x
:
undefined
;
}
function
getNextX
(
i
)
{
return
i
<
maxDataCount
()
-
1
?
c3
.
data
.
targets
[
0
].
values
[
i
+
1
].
x
:
undefined
;
}
function
maxDataCount
()
{
return
d3
.
max
(
c3
.
data
.
targets
,
function
(
t
)
{
return
t
.
values
.
length
;
});
}
...
...
@@ -1477,8 +1494,19 @@
.
attr
(
"cy"
,
__axis_rotated
?
circleX
:
circleY
);
// rect for mouseover
rectW
=
(((
__axis_rotated
?
height
:
width
)
*
getXDomainRatio
())
/
(
maxDataCount
()
-
1
));
rectX
=
function
(
d
)
{
return
x
(
d
.
x
)
-
(
rectW
/
2
);
};
if
(
isCustomX
)
{
rectW
=
function
(
d
,
i
)
{
var
prevX
=
getPrevX
(
i
),
nextX
=
getNextX
(
i
);
return
(
x
(
nextX
?
nextX
:
d
.
x
+
50
)
-
x
(
prevX
?
prevX
:
d
.
x
-
50
))
/
2
;
};
rectX
=
function
(
d
,
i
)
{
var
prevX
=
getPrevX
(
i
);
return
(
x
(
d
.
x
)
+
x
(
prevX
?
prevX
:
d
.
x
-
50
))
/
2
;
};
}
else
{
rectW
=
(((
__axis_rotated
?
height
:
width
)
*
getXDomainRatio
())
/
(
maxDataCount
()
-
1
));
rectX
=
function
(
d
,
i
)
{
return
x
(
d
.
x
)
-
(
rectW
/
2
);
};
}
main
.
selectAll
(
'.event-rect'
)
.
attr
(
"x"
,
__axis_rotated
?
0
:
rectX
)
.
attr
(
"y"
,
__axis_rotated
?
rectX
:
0
)
...
...
c3.min.js
View file @
8f1d1c1c
This diff is collapsed.
Click to expand it.
htdocs/samples/custom_x_scale.html
0 → 100644
View file @
8f1d1c1c
<html>
<head>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"/css/c3.css"
>
</head>
<body>
<div
id=
"chart"
></div>
<script
src=
"http://d3js.org/d3.v3.min.js"
charset=
"utf-8"
></script>
<script
src=
"/js/c3.min.js"
></script>
<script>
var
chart
=
c3
.
generate
({
bindto
:
'#chart'
,
data
:
{
x
:
'x'
,
columns
:
[
[
'x'
,
100
,
120
,
130
,
200
,
240
,
500
],
[
'sample'
,
30
,
200
,
100
,
400
,
150
,
250
]
]
}
});
</script>
</body>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment