MetricsGraphics

一个为简洁原则的数据图形和布局而优化的库。(A library optimized for concise and principled data graphics and layouts.)

  • 所有者: metricsgraphics/metrics-graphics
  • 平台: Linux, Mac, Windows
  • 許可證:
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

MetricsGraphics

MetricsGraphics 是一个用于可视化和布局时间序列数据的库。它的体积约为 15kB(gzipped),它提供了一种简单的方式,以一种原则性和一致性的方式来制作常见的图形类型。该库目前支持线图、散点图和直方图,以及地毯图等功能。

例子

您所需要做的就是向文档添加一个条目节点。

<div id="chart"></div>

然后,使用 id 挂载图表:

import LineChart from 'metrics-graphics'
new LineChart({
  data, // some array of data objects
  width: 600,
  height: 200,
  target: '#chart',
  area: true,
  xAccessor: 'date',
  yAccessor: 'value'
})

就是这样!

这个例子的原始数据可以在 这里 找到。

文档

如果你想使用 MetricsGraphics,你可以在 这里 找到公共 API。

如果你想扩展 MetricsGraphics,你可以阅读 组件实用程序

开发设置

这个项目使用 Lerna。在全局范围内安装它有很大帮助(npm i -g lerna)。

# 克隆和设置
git clone https://github.com/metricsgraphics/metrics-graphics
cd metrics-graphics
lerna bootstrap

同时运行库的开发设置和实例的开发设置:

# inside packages/lib
npm run dev
# inside packages/examples
npm run dev


主要指標

概覽
名稱與所有者metricsgraphics/metrics-graphics
主編程語言TypeScript
編程語言JavaScript (語言數: 3)
平台Linux, Mac, Windows
許可證
所有者活动
創建於2014-05-01 18:25:52
推送於2022-05-31 15:05:59
最后一次提交2022-05-19 15:56:38
發布數41
最新版本名稱v3.0.0-beta1 (發布於 )
第一版名稱V0.1.0 (發布於 )
用户参与
星數7.4k
關注者數196
派生數471
提交數1.8k
已啟用問題?
問題數718
打開的問題數131
拉請求數185
打開的拉請求數0
關閉的拉請求數57
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

License: MPL 2.0 Build Status CDNJS

this project is unmaintained. please see this blog post: https://wlach.github.io/blog/2019/09/metrics-graphics-stepping-back-for-a-while/

MetricsGraphics.js is a library optimized for visualizing and laying out time-series data. At under 80KB (minified), it provides a simple way to produce common types of graphics in a principled and consistent way. The library currently supports line charts, scatterplots, histograms, bar charts and data tables, as well as features like rug plots and basic linear regression.

A sample set of examples may be found on the examples page. The example below demonstrates how easy it is to produce a graphic. Our graphics function provides a robust layer of indirection, allowing one to more efficiently build, say, a dashboard of interactive graphics, each of which may be pulling data from a different data source. For the complete list of options, and for download instructions, take a look at the sections below.

MG.data_graphic({
    title: 'Downloads',
    description: 'This graphics shows Firefox GA downloads for the past six months.',
    data: downloads_data, // an array of objects, such as [{value:100,date:...},...]
    width: 600,
    height: 250,
    target: '#downloads', // the html element that the graphic is inserted in
    x_accessor: 'date',  // the key that accesses the x value
    y_accessor: 'value' // the key that accesses the y value
})

The API is simple. All that's needed to create a graphic is to specify a few default parameters and then, if desired, override one or more of the optional parameters on offer. We don't maintain state. In order to update a graphic, one would call MG.data_graphic on the same target element.

The library is data-source agnostic. While it provides a number of convenience functions and options that allow for graphics to better handle things like missing observations, it doesn't care where the data comes from.

Though originally envisioned for Mozilla Metrics dashboard projects, we are making this repository public for others to use, knowing full well that we are far from having this project in good-enough shape. Take a look at the issues to see the milestones and other upcoming work on this repository. We are currently using semantic versioning.

http://metricsgraphicsjs.org

Important changes in v2.10

The library now depends on D3 4.x. The impact on MG users is minimal, though if you do use D3 for other work, here is the list of changes from 3.x to 4.x. Please refer to the release notes for further details.

Important changes in v2.0

  1. The library is now namespaced. data_graphic is now MG.data_graphic, convert_dates is now MG.convert.date, clone is now MG.clone, button_layout is now MG.button_layout and data_table is now MG.data_table. We added a new convenience function called MG.convert.number.
  2. The rollover_callback option has been renamed mouseover and expanded in order to make it more consistent with other libraries. We now have three callback functions available: mouseover, mouseout and mousemove.
  3. CSS rules have been prefixed and in some cases updated for consistency. active_datapoint for instance is now mg-active-datapoint.

Quick-start guide

  1. Download the latest release.
  2. Follow the examples here and here to see how graphics are laid out and built. The examples use JSON data from examples/data, though you may easily pull data from elsewhere.

Dependencies

The library depends on D3. If you wish to enable tooltips or use buttons, please include jQuery as well. Versions of MG older than v2.10 depend on D3 3, whereas MG v2.10 onwards depend on D3 4.

Contributing

If you would like to help extend MetricsGraphics.js or fix bugs, please fork the library and install Node.js. Then, from the project's root directory install gulp:

npm install gulp

Then, install the library's dependencies:

npm install

To build the library from source, type:

gulp build:js

To run tests, type:

gulp test

We have a basic development environment which uses the project source to
serve up an interactive example. To run it, type:

gulp serve

A development server will be available at http://localhost:4300. Just reload
it as you make modifications to the files in src/ -- any changes made to
the example source and data should be preserved.

The website metricsgraphicsjs.org is automatically
uploaded/updated by travis ci when a new tag is created (corresponding to a
new release). It is served from github pages using a netlify
configuration maintained and controlled by William Lachance.

You might also be interested in writing addons for the library, in which case, have a read through this page.

Resources

Download package

The download package includes everything that you see on metricsgraphicsjs.org. In order to use the library in your own project, the only files that you'll need are the ones under dist. Remember to load D3 and jQuery. If you don't care about tooltips or the button layout, you won't need the latter. If your project uses Bootstrap, make sure you load MetricsGraphics.js after it.

Frequently asked questions

What does MetricsGraphics.js do that library x doesn't do?

If library x works for you, you should keep using it. We're not aiming to be competitive with libraries that already exist. We're aiming to make a library that meets our needs. We also happen to think that the world needs a principled data presentation library, and that many of our needs are the same as other folks'.

I only see colours for the first 10 lines in my chart, what gives?

The colors for the first ten lines, areas and legends are defined in the stylesheet for the light and dark themes. For an eleventh line, you would add the following CSS rules:

.mg-line11-color {
    stroke: lightpink;
}

.mg-area11-color {
    fill: lightpink;
}

.mg-hover-line11-color {
    fill: lightpink;
}

.mg-line11-legend-color {
    color: lightpink;
}

If you're plotting more than five lines in the same chart and using color to encode some dimension of the data, then you probably need to rethink the chart.

I get an error when I load MG alongside library x

If your project uses Bootstrap, make sure you load MetricsGraphics.js after it. If your project uses jQuery UI, load it after MetricsGraphics.js.

Feel free to add your addons and websites to this list.

License

The MetricsGraphics.js code is shared under the terms of the Mozilla Public License v2.0. See the LICENSE file at the root of the repository. The current logo is courtesy of Font Awesome.